emacs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. ;; Platform-specific stuff!!!!
  2. (setq document-view "setsid -w xdg-open %s"
  3. pdf-viewer "Evince" ; for C-c C-v LaTeX forward search
  4. keepass-folder "~/Syncthing/keepass/"
  5. bibliography-folder "~/Documents/bibliography/"
  6. biblio-key (kbd "<f12>") ; use <apps> for the menu button in
  7. ; other OS's, or for example <f12> for
  8. ; Termux and see its wiki for showing
  9. ; this button on its interface. Also
  10. ; <X86Launch1> works in Mate desktop,
  11. ; but not terminals.
  12. windmove-key 'shift ; for 'shift, see
  13. ; https://emacs.stackexchange.com/a/54002
  14. ;; browse-url-browser-function 'browse-url-xdg-open ; in termux
  15. org-replace-disputed-keys t ; for windmove when using 'shift
  16. want-to-use-xclip nil ; termux clipboard, install termux-api too
  17. )
  18. ;; Computed stuff:
  19. (setq own-calendar-file (concat keepass-folder "calendar.org")
  20. own-bookmark-file (concat keepass-folder "bookmarks.org")
  21. bibliography-file (concat bibliography-folder "references.bib")
  22. bibliography-pdf-folder (concat bibliography-folder "bibtex-pdfs/")
  23. bibliography-notes (concat bibliography-folder "notes.org"))
  24. ;; Defer loading packages unless daemon
  25. (setq use-package-always-demand (daemonp))
  26. ;; Always revert files, i.e. reload them to buffers if emacs notices
  27. ;; them changing by e.g. an external program.
  28. (global-auto-revert-mode 1)
  29. ;; Load the MELPA package library
  30. (require 'package)
  31. (add-to-list 'package-archives '("melpa"
  32. . "https://melpa.org/packages/") t)
  33. (package-initialize)
  34. ;; Download and load use-package
  35. (unless (package-installed-p 'use-package)
  36. (package-install 'use-package))
  37. ;;;;;;;;;;;;;;;;;;;;;;;
  38. ;;;; Email related ;;;;
  39. ;;;;;;;;;;;;;;;;;;;;;;;
  40. (setq mail-user-agent 'gnus-user-agent
  41. epg-pinentry-mode 'loopback) ; Avoids GPG password input entry
  42. ; issue in emacs termux. Might need
  43. ; to edit .gnupeg/gpg-agent.conf
  44. ; and add "allow-emacs-pinentry"
  45. ;; BBDB settings
  46. (use-package bbdb
  47. :ensure t
  48. :custom
  49. (bbdb-file (concat keepass-folder "bbdb"))
  50. (bbdb-mua-pop-up t) ; Display BBDB in popup window
  51. (bbdb-mua-pop-up-window-size 3)
  52. (bbdb-mua-update-interactive-p
  53. '(query . create)) ; Look for existing contact, interactively
  54. ; prompt to create
  55. :config
  56. (bbdb-initialize 'gnus 'message)
  57. (bbdb-mua-auto-update-init 'gnus 'message))
  58. ;;;;;;;;;;;;;;;;;;;;;;;
  59. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  60. ;;;; Appearance related ;;;;
  61. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  62. ;; Nyan-mode.
  63. (use-package nyan-mode
  64. :ensure t
  65. :config
  66. (nyan-mode 1)
  67. (nyan-start-animation)
  68. ;; Install sox in termux to play music and uncomment below.
  69. ;; (defun nyan-start-music ()
  70. ;; (interactive)
  71. ;; (unless nyan-music-process
  72. ;; (setq nyan-music-process (start-process-shell-command "nyan-music" "nyan-music" (concat "play " +nyan-music+ " repeat 9001")))))
  73. )
  74. ;; Theme
  75. (use-package nord-theme ; Good candidates: nord-theme, dracula-theme
  76. :ensure t
  77. :config
  78. (enable-theme 'nord))
  79. ;; Color issues
  80. (setq shr-use-colors nil) ; Don't use text color when rendering html
  81. ; using shr (links ok)
  82. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  83. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  84. ;;;; Emacs buffer etc. behaviour ;;;;
  85. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  86. ;; Expand region
  87. (use-package expand-region
  88. :ensure t
  89. :config
  90. (global-set-key (kbd "<f11>") 'er/expand-region)
  91. (delete-selection-mode t) ; typed text replaces the selection
  92. )
  93. ;; Smartparens
  94. (use-package smartparens
  95. :ensure t
  96. :hook
  97. ((lisp-mode emacs-lisp-mode gfm-mode markdown-mode LaTeX-mode)
  98. . show-paren-mode)
  99. ((lisp-mode emacs-lisp-mode gfm-mode markdown-mode LaTeX-mode)
  100. . smartparens-mode)
  101. :config
  102. (sp-local-pair '(lisp-mode emacs-lisp-mode) "'" nil :actions nil)
  103. (sp-local-pair '(lisp-mode emacs-lisp-mode) "`" nil :actions nil)
  104. )
  105. (winner-mode t) ; C-c ←/→ for going between used window configurations
  106. (setq-default word-wrap t)
  107. (defun unfill-paragraph () ; for copy-pasting to external program
  108. "Takes a multi-line paragraph and makes it into a single line of text."
  109. (interactive)
  110. (let ((fill-column (point-max)))
  111. (fill-paragraph nil)))
  112. (define-key global-map "\M-Q" 'unfill-paragraph) ; alt+shift+q
  113. ;; Sort words
  114. ;; https://www.emacswiki.org/emacs/SortWords
  115. (defun sort-words (reverse beg end)
  116. "Sort words in region alphabetically, in REVERSE if negative.
  117. Prefixed with negative \\[universal-argument], sorts in reverse.
  118. The variable `sort-fold-case' determines whether alphabetic case
  119. affects the sort order.
  120. See `sort-regexp-fields'."
  121. (interactive "*P\nr")
  122. (sort-regexp-fields reverse "\\w+" "\\&" beg end))
  123. (windmove-default-keybindings windmove-key)
  124. (setq mouse-yank-at-point t) ; Use current cursor position for middle
  125. ; mouse pasting instead of jumping to new
  126. ; location then paste
  127. ;; F9 opens file where we save www-bookmarks
  128. (global-set-key (kbd "<f9>") (lambda() (interactive)(find-file own-bookmark-file)))
  129. ;; Xclip
  130. (when want-to-use-xclip
  131. (use-package xclip
  132. :ensure t
  133. :config
  134. (xclip-mode 1)
  135. ))
  136. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  137. ;;;;;;;;;;;;;;;;;;;;;;;;
  138. ;;;; Coding related ;;;;
  139. ;;;;;;;;;;;;;;;;;;;;;;;;
  140. (global-set-key "\C-x\C-m" 'compile) ; C-x C-m compile
  141. (setq compilation-read-command nil ; compile with "make -k"
  142. compilation-scroll-output t) ; autoscroll compilation buffer
  143. (use-package magit
  144. :ensure t
  145. :bind
  146. ("C-x g" . magit-status))
  147. (use-package company ; Company (complete anything) mode
  148. :ensure t
  149. :hook
  150. ((latex-mode LaTeX-mode emacs-lisp-mode) . company-mode)
  151. ((latex-mode LaTeX-mode) . (lambda ()
  152. (set (make-local-variable 'company-backends)
  153. '((company-dabbrev)))))
  154. :custom
  155. (company-tooltip-align-annotations 1)
  156. (company-minimum-prefix-length 1)
  157. (company-idle-delay 0.0)
  158. (company-selection-wrap-around t)
  159. (company-dabbrev-ignore-case nil)
  160. (company-dabbrev-downcase nil)
  161. :config
  162. (company-tng-mode)
  163. (define-key company-active-map [up] nil)
  164. (define-key company-active-map [down] nil))
  165. (use-package slime ; SLIME (Common LISP)
  166. :ensure t
  167. :custom
  168. (inferior-lisp-program "clisp")
  169. :config
  170. (slime-setup '(slime-fancy)))
  171. (use-package slime-company
  172. :ensure t
  173. :after (slime company)
  174. :custom
  175. (slime-company-completion 'fuzzy)
  176. :config
  177. (slime-setup '(slime-company)))
  178. (use-package geiser-chez ; For Chez Scheme, start M-x run-geiser
  179. :ensure t)
  180. (use-package markdown-mode
  181. :ensure t
  182. :mode ("README\\.md\\'" . gfm-mode)
  183. :custom
  184. (markdown-command "pandoc"))
  185. ;; Indentation & behaviour
  186. (setq-default indent-tabs-mode nil
  187. standard-indent 2)
  188. ;;;;;;;;;;;;;;;;;;;;;;;;
  189. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  190. ;;;; LaTeX / math related ;;;;
  191. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  192. (add-to-list 'auto-mode-alist '("\\.m\\'" . octave-mode))
  193. (setq bibtex-align-at-equal-sign t) ; align = in bibtex using C-c C-q
  194. (use-package tex
  195. :ensure auctex
  196. :custom
  197. (TeX-source-correlate-mode t) ; for forward search
  198. :config
  199. (add-to-list 'TeX-view-program-selection
  200. `(output-pdf ,pdf-viewer)) ; ` is like quote but allows
  201. ; evaluation inside using ,
  202. :hook
  203. ; Make \ part of words in LaTeX-mode
  204. ((latex-mode LaTeX-mode) . (lambda () (modify-syntax-entry
  205. (string-to-char TeX-esc)
  206. "w"
  207. LaTeX-mode-syntax-table))))
  208. (use-package reftex
  209. :ensure t
  210. :hook
  211. ((latex-mode LaTeX-mode) . turn-on-reftex))
  212. (use-package bibtex
  213. :custom
  214. ;; Ignore only lower case title words instead of all non-uppercased
  215. ;; ones when generating keys for bibtex
  216. (bibtex-autokey-titleword-ignore
  217. '("A" "An" "On" "The" "Eine?" "Der" "Die" "Das" "[[:lower:]].*" ".*[^[:upper:][:lower:]0-9].*")))
  218. ;; Helm-bibtex
  219. (use-package helm-bibtex
  220. :ensure t
  221. :demand t ; otherwise biblio-key will be bound to void
  222. :init ; can't have a form like biblio-key under :bind
  223. (bind-key biblio-key 'helm-command-prefix)
  224. :config
  225. (define-key helm-command-map biblio-key 'helm-resume)
  226. :bind
  227. (:map helm-command-map
  228. ("b" . helm-bibtex)
  229. ("B" . helm-bibtex-with-local-bibliography)
  230. ("n" . helm-bibtex-with-notes))
  231. ;; (define-key helm-command-map (kbd "<f12>") 'helm-resume)
  232. :custom
  233. (bibtex-completion-bibliography
  234. (list ; needs (list ...) for new org-ref to work
  235. bibliography-file))
  236. (bibtex-completion-library-path
  237. (list ; needs (list ...) for new org-ref to work
  238. bibliography-pdf-folder))
  239. (bibtex-completion-pdf-extension '(".pdf" ".djvu"))
  240. (bibtex-completion-pdf-open-function 'org-open-file)
  241. (bibtex-completion-notes-path bibliography-notes)
  242. (bibtex-completion-additional-search-fields '(keywords tags))
  243. (bibtex-completion-pdf-field "File")
  244. (bibtex-completion-pdf-symbol "⌘")
  245. (bibtex-completion-notes-symbol "✎")
  246. )
  247. (use-package org-ref ; Includes doi-utils
  248. :ensure t
  249. :custom
  250. ;; Words which shouldn't be capitalized in titles
  251. (org-ref-lower-case-words '("a" "an" "at" "on" "and" "for" "the" "of" "in"))
  252. ;; Allow the following fields Into Title Case of the Following Items
  253. (org-ref-title-case-types '(("article" "title")
  254. ("book" "booktitle")
  255. ("misc" "title")))
  256. ;; Don't convert ä,ö,å, etc when org-ref-clean-bibtex-entry
  257. (org-ref-clean-bibtex-entry-hook
  258. '(org-ref-bibtex-format-url-if-doi orcb-key-comma orcb-& orcb-% org-ref-title-case orcb-clean-year orcb-key orcb-clean-doi orcb-clean-pages orcb-check-journal org-ref-sort-bibtex-entry orcb-fix-spacing orcb-download-pdf)))
  259. (use-package scihub
  260. :ensure t
  261. :custom
  262. (scihub-download-directory (car bibtex-completion-library-path))
  263. (scihub-open-after-download nil)
  264. (scihub-fetch-domain 'scihub-fetch-domains-lovescihub))
  265. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  266. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  267. ;;;; Org-mode related ;;;;
  268. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  269. (use-package org
  270. :ensure t
  271. :bind
  272. ("C-c l" . org-store-link)
  273. ("C-c a" . org-agenda)
  274. ("C-c c" . org-capture)
  275. :custom
  276. (org-agenda-files (list own-calendar-file))
  277. (org-agenda-start-on-weekday 1) ; nil means current day
  278. (org-agenda-span 7)
  279. (org-refile-targets '((org-agenda-files :maxlevel . 9)))
  280. (org-reverse-note-order t) ; refiles to top instead of bottom
  281. (org-archive-reversed-order t) ; same for archiving with C-c C-x A
  282. (org-refile-use-outline-path t)
  283. (org-todo-keywords
  284. '((sequence "TODO(t)" "WAIT(w!/!)" "MEET(m)" "IDEA(i)"
  285. "|" "DONE(d)" "CANCELLED(c@)")))
  286. (org-log-done 'time)
  287. ;; See see http://cachestocaches.com/2016/9/my-workflow-org-agenda/
  288. (org-capture-templates
  289. '(("t" "todo" entry (file+headline own-calendar-file "Unclassified")
  290. "* TODO %? %A")
  291. ("m" "Meeting" entry (file+headline own-calendar-file "Unclassified")
  292. "* MEET %? %A")
  293. ("b" "Bookmark" entry (file+headline own-bookmark-file "Bookmarks")
  294. "* %x %?%^g\n:PROPERTIES:\n:CREATED: %U\n:END:\n\n" :empty-lines-before 1)
  295. ("n" "Pdf note from email" plain (file bibliography-file)
  296. "@misc{????,\nauthor = {%^{author}},\nday = %^{day},\nmonth = %^{month},\nyear = %^{year},\ntags = {%^{comma-separated tags}},\ntitle = {%\\4/%\\3/%\\2 Notes - %^{topic (remember to save the PDF from email!!)}},\nurl = %l\n}\n\n" :empty-lines 1 :before-finalize org-ref-clean-bibtex-entry :immediate-finish 1)))
  297. ;; Org & agendar look
  298. (org-todo-keyword-faces '(("MEET" .
  299. (:foreground "#486f66"
  300. :background "#f4bbce"
  301. :weight ultra-bold))))
  302. (org-agenda-prefix-format
  303. '((agenda . " %i %?-12t% s") ; default: " %i %-12:c%?-12t% s"
  304. (todo . " %i %-12:c")
  305. (tags . " %i %-12:c")
  306. (search . " %i %-12:c")))
  307. (org-agenda-remove-tags t)
  308. :config
  309. ;; Open pdf & djvu outside emacs
  310. (defun alist-set (KEY PROP ALIST)
  311. (set ALIST (assoc-delete-all KEY (symbol-value ALIST)))
  312. (add-to-list ALIST (cons KEY PROP)))
  313. (alist-set "\\.pdf\\'" document-view 'org-file-apps)
  314. (alist-set "\\.djvu\\'" document-view 'org-file-apps)
  315. ;; C-c C- s RET inserts block. See ":exports both" for results.
  316. (org-babel-do-load-languages
  317. 'org-babel-load-languages
  318. '((calc . t)
  319. (octave . t)
  320. (R . t)
  321. (python . t) ; see https://emacs.stackexchange.com/a/64539
  322. (shell . t)))
  323. (setq org-babel-python-command
  324. "python3") ; add ":python python" to block for python2
  325. )
  326. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  327. (custom-set-variables
  328. ;; custom-set-variables was added by Custom.
  329. ;; If you edit it by hand, you could mess it up, so be careful.
  330. ;; Your init file should contain only one such instance.
  331. ;; If there is more than one, they won't work right.
  332. '(bbdb-mua-interactive-action '(query . create) nil nil "Customized with use-package bbdb")
  333. '(custom-safe-themes
  334. '("4c7228157ba3a48c288ad8ef83c490b94cb29ef01236205e360c2c4db200bb18" default)))
  335. (custom-set-faces
  336. ;; custom-set-faces was added by Custom.
  337. ;; If you edit it by hand, you could mess it up, so be careful.
  338. ;; Your init file should contain only one such instance.
  339. ;; If there is more than one, they won't work right.
  340. )