my-emacs-d/init.el

483 lines
16 KiB
EmacsLisp
Raw Normal View History

;;; init --- Summary
;;; Commentary:
;;; Code:
(setq custom-file (concat user-emacs-directory "customizations.el"))
(load custom-file)
;; Initialize the package system and use-package
(setq load-prefer-newer t)
(require 'package)
(add-to-list 'package-archives
'("gnu" . "http://elpa.gnu.org/packages/"))
2016-11-07 13:46:53 +00:00
(add-to-list 'package-archives
'("melpa-stable" . "https://stable.melpa.org/packages/") t)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/") t)
2017-01-05 20:41:48 +00:00
(add-to-list 'package-archives
'("org" . "http://orgmode.org/elpa/") t)
2016-08-18 20:01:20 +00:00
(package-initialize)
2018-07-29 16:38:44 +00:00
;; I started moving my configuration to this Org file. Its easier to document this way.
(org-babel-load-file (expand-file-name "configuration.org" user-emacs-directory))
2016-09-15 14:08:54 +00:00
2016-11-18 08:45:50 +00:00
;; Load my own functions
(load "gnu-c-header")
(load "round-number-to-decimals")
(load "window-manip")
;; From gmane.emacs.orgmode
;; (http://article.gmane.org/gmane.emacs.orgmode/75222)
(defun f-ediff-org-showhide (buf command &rest cmdargs)
"If buffer BUF exists and in `org-mode', execute COMMAND with CMDARGS."
(when buf
(when (eq (buffer-local-value 'major-mode (get-buffer buf)) 'org-mode)
(save-excursion
(set-buffer buf)
(apply command cmdargs)))))
(defun f-ediff-org-unfold-tree-element ()
"Unfold tree at diff location."
(f-ediff-org-showhide ediff-buffer-A 'org-reveal)
(f-ediff-org-showhide ediff-buffer-B 'org-reveal)
(f-ediff-org-showhide ediff-buffer-C 'org-reveal))
(defun f-ediff-org-fold-tree ()
"Fold tree back to top level."
(f-ediff-org-showhide ediff-buffer-A 'hide-sublevels 1)
(f-ediff-org-showhide ediff-buffer-B 'hide-sublevels 1)
(f-ediff-org-showhide ediff-buffer-C 'hide-sublevels 1))
;; Waka-waka
(use-package wakatime-mode
:init
(setq-default wakatime-cli-path (executable-find "wakatime"))
:config
(global-wakatime-mode t))
(use-package gnugo)
(use-package gobgen)
(use-package xlicense)
2016-10-17 15:43:18 +00:00
(use-package plantuml-mode
:init
(setq plantuml-jar-path
(expand-file-name
;; Make sure we have a download location even if XDG is not
;; working
(cond
((xdg-user-dir "DOWNLOAD")
(concat (xdg-user-dir "DOWNLOAD") "/plantuml.jar"))
(t
"~/Downloads/plantuml.jar"))))
2016-10-17 15:43:18 +00:00
(defvaralias 'org-plantuml-jar-path 'plantuml-jar-path)
:config
(org-babel-do-load-languages
'org-babel-load-languages
'((plantuml . t))))
2016-10-17 14:24:31 +00:00
2016-10-20 12:09:15 +00:00
(use-package hungarian-holidays
:config
(hungarian-holidays-add))
(use-package flyspell
:config
(add-hook 'prog-mode-hook
2016-10-21 07:32:50 +00:00
'flyspell-prog-mode)
(add-hook 'text-mode-hook
2016-10-21 07:32:50 +00:00
'flyspell-mode))
2016-10-21 08:18:21 +00:00
(use-package hungry-delete
:config
(global-hungry-delete-mode))
(use-package alert
:config
(setq alert-default-style
(if (termux-p)
(progn
;; TODO Remove this as soon as my PR gets merged
;; https://github.com/jwiegley/alert/pull/41
(unless (fboundp 'alert-termux-notify)
(defcustom alert-termux-command (executable-find "termux-notification")
"Path to the termux-notification command.
This is found in the termux-api package, and it requires the Termux
API addon app to be installed."
:type 'file
:group 'alert)
(defun alert-termux-notify (info)
"Send INFO using termux-notification.
Handles :TITLE and :MESSAGE keywords from the
INFO plist."
(if alert-termux-command
(let ((args (nconc
(when (plist-get info :title)
(list "-t" (alert-encode-string (plist-get info :title))))
(list "-c" (alert-encode-string (plist-get info :message))))))
(apply #'call-process alert-termux-command nil
(list (get-buffer-create " *termux-notification output*") t)
nil args))
(alert-message-notify info)))
(alert-define-style 'termux :title "Notify using termux"
:notifier #'alert-termux-notify))
'termux)
'libnotify)))
2016-10-24 07:49:07 +00:00
(use-package newsticker
2016-10-24 12:36:50 +00:00
:demand
2016-10-24 07:49:07 +00:00
:config
(setq newsticker-url-list '(("(or emacs irrelevant)"
"http://oremacs.com/atom.xml"
nil nil nil)
("think"
"http://batsov.com/atom.xml"
nil nil nil)
("Endless Parentheses"
"http://endlessparentheses.com/atom.xml"
2016-10-24 12:36:50 +00:00
nil nil nil)
2016-10-24 10:19:37 +00:00
("Irreal"
"http://irreal.org/blog/?feed=rss2"
nil nil nil)
;; The followint may supersede previous entries
("Planet Emacs"
"http://planet.emacsen.org/atom.xml"
2016-10-24 10:19:37 +00:00
nil nil nil)))
2016-10-24 07:49:07 +00:00
:bind
(:map gpolonkai/pers-map
("n" . newsticker-show-news)))
(use-package cheatsheet)
2016-10-28 05:12:16 +00:00
(use-package ace-popup-menu
:config
(ace-popup-menu-mode 1))
2016-11-01 12:52:52 +00:00
(use-package achievements
:config
(achievements-mode 1))
2016-11-07 15:17:30 +00:00
(use-package form-feed
:config
(add-hook 'emacs-lisp-mode-hook 'form-feed-mode))
2016-11-09 07:23:51 +00:00
(use-package auto-virtualenv
:config
(add-hook 'python-mode-hook 'auto-virtualenv-set-virtualenv)
(add-hook 'projectile-after-switch-project-hook
'auto-virtualenv-set-virtualenv))
2016-11-09 07:23:51 +00:00
(use-package gitlab)
(use-package hl-todo)
2016-11-11 22:26:40 +00:00
(use-package anaconda-mode
:config
(add-hook 'python-mode-hook 'anaconda-mode)
(add-hook 'python-mode-hook 'anaconda-eldoc-mode))
(use-package enlive)
2018-07-19 10:50:05 +00:00
(use-package emmet-mode
:config
(setq emmet-self-closing-tag-style "")
(add-hook 'web-mode 'emmet-mode)
(add-hook 'css-mode 'emmet-mode))
(use-package phi-search)
(use-package phi-search-mc
:config
(phi-search-mc/setup-keys))
2017-04-07 16:23:53 +00:00
(use-package secretaria
:after
alert
2017-04-07 16:23:53 +00:00
:config
;; use this for getting a reminder every 30 minutes of those tasks
;; scheduled for today and which have no time of day defined.
(add-hook 'after-init-hook
#'secretaria-today-unknown-time-appt-always-remind-me))
(when (termux-p)
(use-package browse-url
:ensure nil
:config
(advice-add 'browse-url-default-browser :override
(lambda (url &rest args)
(start-process-shell-command
"open-url"
nil
(concat "am start -a android.intent.action.VIEW --user 0 -d "
url))))))
2017-08-21 22:13:15 +00:00
(use-package feature-mode)
2017-08-07 08:44:10 +00:00
(use-package org-ref
:after
org
:config
(setq org-ref-bibliography-notes (concat user-documents-directory
(convert-standard-filename
"/orgmode/bibliography-notes"))
org-ref-default-bibliography '((concat user-documents-directory
(convert-standard-filename
"/orgmode/references.bib")))
org-ref-pdf-directory (concat user-documents-directory
(convert-standard-filename
"/orgmode/bibtex-pdfs"))))
2017-09-22 11:48:32 +00:00
(use-package ag
:after projectile
:bind
(:map projectile-mode-map
("C-c p C-a" . ag-project)))
2017-10-02 11:33:25 +00:00
(use-package fancy-narrow
:config
(fancy-narrow-mode))
2017-11-08 07:24:22 +00:00
(use-package undo-tree)
2018-07-25 05:16:09 +00:00
(use-package all-the-icons)
(use-package neotree
:after
all-the-icons
:config
(setq neo-theme (if (display-graphic-p) 'icons 'arrow))
:bind
(("<f5>" . neotree-toggle)))
2017-08-07 08:44:10 +00:00
;; open pdf with system pdf viewer (works on mac)
(setq bibtex-completion-pdf-open-function
(lambda (fpath)
(start-process "open" "*open*" "open" fpath)))
;; alternative
;; (setq bibtex-completion-pdf-open-function 'org-open-file))
(add-hook 'python-mode-hook
(lambda ()
(add-to-list 'prettify-symbols-alist
'("not" . 172))
(add-to-list 'prettify-symbols-alist
2017-08-07 06:30:00 +00:00
'("in" . 8712))
(add-to-list 'prettify-symbols-alist
'("def" . 402))))
2016-09-29 08:50:50 +00:00
;; `c-mode' settings
(add-hook 'c-mode-common-hook
(lambda ()
(local-set-key (kbd "C-c o") 'ff-find-other-file)
(c-set-style "PERSONAL")
(setq tab-width 4
indent-tabs-mode nil)
(c-toggle-auto-newline 1)))
2016-09-29 08:50:50 +00:00
(add-hook 'c-initialization-hook
(lambda ()
(define-key c-mode-base-map (kbd "C-m") 'c-context-line-break)))
(defvaralias 'c-basic-offset 'tab-width)
(defvaralias 'cperl-indent-level 'tab-width)
(defconst my-c-style
'((c-tab-always-indent . t)
(c-comment-only-line-offset . 4)
(c-hanging-braces-alist . ((substatement-open after)
(brace-list-open)))
(c-hanging-colons-alist . ((member-init-intro before)
(inher-intro)
(case-label after)
(label after)
(access-label after)))
(c-cleanup-list . (scope-operator
empty-defun-braces
defun-close-semi))
(c-offsets-alist . ((arglist-close . +)
2018-06-12 13:05:19 +00:00
(arglist-intro . +)
(substatement-open . 0)
(case-label . 4)
(block-open . 0)
2014-11-16 15:42:08 +00:00
(knr-argdecl-intro . -)
2018-06-12 13:05:19 +00:00
(comment-intro . 0)
(member-init-intro . ++)))
(c-echo-syntactic-information-p . t))
"My C Programming Style.")
(c-add-style "PERSONAL" my-c-style)
2016-02-16 08:12:19 +00:00
2016-09-29 08:50:50 +00:00
;; Custom key bindings
(bind-keys
:map global-map
("M-(" . æ-enclose-region)
("<C-return>" . open-line-below)
("<C-S-return>" . open-line-above)
2016-11-07 12:22:46 +00:00
("M-t" . nil) ;; Remove the old keybinding
("M-t c" . transpose-chars)
("M-t w" . transpose-words)
("M-t l" . transpose-lines)
("M-t e" . transpose-sexps)
("M-t s" . transpose-sentences)
("M-t p" . transpose-paragraphs)
2016-11-15 07:55:42 +00:00
("M-t W" . transpose-windows)
("C-a" . gpolonkai/move-to-beginning-of-line)
("C-e" . gpolonkai/move-to-end-of-line)
("M-q" . sachachua/fill-or-unfill-paragraph)
("C-c r" . round-number-at-point-to-decimals)
("C-s" . isearch-forward-regexp)
("C-r" . isearch-backward-regexp)
("C-M-s" . isearch-forward)
("C-M-r" . isearch-backward)
("C-~" . toggle-char-case)
:map ctl-x-map
("C-y" . gpolonkai/duplicate-line)
("_" . maximize-window)
("C-r" . rename-current-buffer-file)
("C-d" . delete-current-buffer-file)
("|" . toggle-window-split)
("k" . gpolonkai/kill-this-buffer)
("M-c" . gpolonkai/kill-this-buffer-delete-this-window)
("M-k" . gpolonkai/undo-buffer-kill)
2017-08-07 06:44:14 +00:00
("C-b" . bury-buffer)
2018-06-10 06:22:31 +00:00
("/" . repeat)
:map isearch-mode-map
("<C-return>" . isearch-exit-other-end)
("<S-return>" . isearch-exit-mark-match)
:map gpolonkai/pers-map
("m" . hidden-mode-line-mode)
("C-i e" . "gergely@polonkai.eu")
("C-i w" . "http://gergely.polonkai.eu/")
("C-p" . package-list-packages)
("o i" . gpolonkai/visit-init-file)
("o o" . gpolonkai/visit-org-index)
("u" . browse-url-at-point)
("C" . clean-buffer-list))
;; TODO: This doesnt work with use-package and bind-key for some reason.
;; But why?
(define-key 'help-command (kbd "C-l") 'find-library)
(define-key 'help-command (kbd "C-f") 'find-function)
(define-key 'help-command (kbd "C-k") 'find-function-on-key)
(define-key 'help-command (kbd "C-v") 'find-variable)
2016-10-20 12:17:30 +00:00
;; Kudos goes to
;; http://endlessparentheses.com/leave-the-cursor-at-start-of-match-after-isearch.html
(defun isearch-exit-other-end ()
"Exit isearch, at the opposite end of the string."
(interactive)
(isearch-exit)
(goto-char isearch-other-end))
2016-09-15 15:49:29 +00:00
;; Kudos goes to http://emacs.stackexchange.com/a/31321/507
(defun isearch-exit-mark-match ()
"Exit isearch and mark the current match."
(interactive)
(isearch-exit)
(push-mark isearch-other-end)
(activate-mark))
2016-09-29 08:50:50 +00:00
;; Enable some functions
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)
2016-11-17 07:25:17 +00:00
(put 'erase-buffer 'disabled nil)
2017-01-11 08:11:29 +00:00
(put 'narrow-to-region 'disabled nil)
(put 'set-goal-column 'disabled nil)
2016-09-29 08:50:50 +00:00
;; text-mode settings
(add-hook 'text-mode-hook (lambda () (visual-line-mode t)))
2016-09-29 08:50:50 +00:00
;; Add some symbols to be prettified
(setq prettify-symbols-alist
2017-08-07 06:30:00 +00:00
'(("lambda" . 955) ; λ
("function" . 402) ; ƒ
("->" . 8594) ; →
("=>" . 8658) ; ⇒
("map" . 8614) ; ↦
("not" . 172)) ; ¬
;; …and some pairs to complete
;; TODO: maybe add-to-list is a better way to do it
insert-pair-alist '(
(40 41) ; ()
(91 93) ; []
(123 125) ; {}
(60 62) ; <>
(34 34) ; ""
(39 39) ; ''
(96 39) ; `'
(8220 8221) ; “”
(8222 8221) ; „”
(8216 8217) ;
(8249 8250) ;
(8250 8249) ;
(171 187) ; «»
(187 171)) ; »«
;; Set the frame title to the current file name
frame-title-format '((:eval (concat system-name
": "
(if (buffer-file-name)
(abbreviate-file-name
(buffer-file-name))
"%b")))))
(defun gpolonkai/helm-ff-slash-dir-complete ()
"Make forward slash (/) do completion in helm."
(interactive)
(if (and (or
(equal "magit-status" (assoc-default 'name (helm-get-current-source)))
(equal "Find Files" (assoc-default 'name (helm-get-current-source))))
(stringp (helm-get-selection))
(file-directory-p (helm-get-selection)))
(helm-execute-persistent-action)
(insert "/")))
;; TODO: 'cursor-color is sometimes nil, but why?
(setq default-cursor-color (or (frame-parameter nil 'cursor-color) "#ffd85c"))
(setq yasnippet-can-fire-cursor-color "purple")
;; It will test whether it can expand, if yes, cursor color -> purple.
(defun yasnippet-can-fire-p (&optional field)
"Check if the word before point can be expanded with yasnippet.
TODO: What is FIELD for?"
(interactive)
(setq yas--condition-cache-timestamp (current-time))
(let (templates-and-pos)
(unless (and yas-expand-only-for-last-commands
(not (member last-command yas-expand-only-for-last-commands)))
(setq templates-and-pos (if field
(save-restriction
(narrow-to-region (yas--field-start field)
(yas--field-end field))
(yas--templates-for-key-at-point))
(yas--templates-for-key-at-point))))
(and templates-and-pos (first templates-and-pos))))
;; Taken from http://pages.sachachua.com/.emacs.d/Sacha.html
(defun sachachua/change-cursor-color-when-can-expand (&optional field)
"Change cursor color if the text before point can be expanded with yasnippet.
TODO: What is FIELD for?"
(interactive)
(when (eq last-command 'self-insert-command)
(set-cursor-color (if (sachachua/can-expand)
yasnippet-can-fire-cursor-color
default-cursor-color))))
(defun sachachua/can-expand ()
2018-07-02 07:46:16 +00:00
"Return t if right after an expandable thing."
(or (abbrev--before-point) (yasnippet-can-fire-p)))
2017-08-07 06:44:49 +00:00
;; SysAdmin Day to the calendar
(add-to-list 'holiday-other-holidays '(holiday-float 7 5 -1 "SysAdmin Day") t)
(add-to-list 'holiday-other-holidays '(holiday-fixed 10 21 "Reptile Awareness Day") t)
;;; init.el ends here