emacs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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. gtd-folder (concat keepass-folder "gtd/")
  22. gtd-inbox (concat gtd-folder "inbox.org")
  23. gtd-gtd (concat gtd-folder "gtd.org")
  24. gtd-someday (concat gtd-folder "someday.org")
  25. gtd-archive (concat gtd-folder "archive.org")
  26. gtd-tickler (concat gtd-folder "tickler.org")
  27. bibliography-file (concat bibliography-folder "references.bib")
  28. bibliography-pdf-folder (concat bibliography-folder "bibtex-pdfs/")
  29. bibliography-notes (concat bibliography-folder "bibtex-notes/"))
  30. (modify-coding-system-alist 'file "" 'utf-8)
  31. (setq-default buffer-file-coding-system 'utf-8)
  32. ;; Defer loading packages unless daemon
  33. (setq use-package-always-demand (daemonp))
  34. ;; Always revert files, i.e. reload them to buffers if emacs notices
  35. ;; them changing by e.g. an external program.
  36. (global-auto-revert-mode 1)
  37. ;; Load the MELPA package library
  38. (require 'package)
  39. (add-to-list 'package-archives '("melpa"
  40. . "https://melpa.org/packages/") t)
  41. (package-initialize)
  42. ;; Download and load use-package
  43. (unless (package-installed-p 'use-package)
  44. (package-install 'use-package))
  45. ;;;;;;;;;;;;;;;;;;;;;;;
  46. ;;;; Email related ;;;;
  47. ;;;;;;;;;;;;;;;;;;;;;;;
  48. (setq mail-user-agent 'gnus-user-agent
  49. epg-pinentry-mode 'loopback) ; Avoids GPG password input entry
  50. ; issue in emacs termux. Might need
  51. ; to edit .gnupeg/gpg-agent.conf
  52. ; and add "allow-emacs-pinentry"
  53. ;; BBDB settings
  54. (use-package bbdb
  55. :ensure t
  56. :custom
  57. (bbdb-file (concat keepass-folder "bbdb"))
  58. (bbdb-mua-pop-up t) ; Display BBDB in popup window
  59. (bbdb-mua-pop-up-window-size 3)
  60. (bbdb-mua-update-interactive-p
  61. '(query . create)) ; Look for existing contact, interactively
  62. ; prompt to create
  63. :config
  64. (bbdb-initialize 'gnus 'message)
  65. (bbdb-mua-auto-update-init 'gnus 'message))
  66. ;;;;;;;;;;;;;;;;;;;;;;;
  67. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  68. ;;;; Appearance related ;;;;
  69. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  70. ;; Nyan-mode.
  71. (use-package nyan-mode
  72. :ensure t
  73. :config
  74. (nyan-mode 1)
  75. (nyan-start-animation)
  76. ;; Install sox in termux to play music and uncomment below.
  77. ;; (defun nyan-start-music ()
  78. ;; (interactive)
  79. ;; (unless nyan-music-process
  80. ;; (setq nyan-music-process (start-process-shell-command "nyan-music" "nyan-music" (concat "play " +nyan-music+ " repeat 9001")))))
  81. )
  82. ;; Theme
  83. (use-package nord-theme ; Good candidates: nord-theme, dracula-theme
  84. :ensure t
  85. :config
  86. (enable-theme 'nord))
  87. ;; Color issues
  88. (setq shr-use-colors nil) ; Don't use text color when rendering html
  89. ; using shr (links ok)
  90. ;; Olivetti mode for org-mode etc long texts.
  91. ;; Add
  92. ;; ((nil . ((fill-column . 80)
  93. ;; (mode . olivetti))))
  94. ;; inside a folder's .dir-locals.el to use olivetti for all files there
  95. (use-package olivetti :ensure t)
  96. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  97. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  98. ;;;; Emacs buffer etc. behaviour ;;;;
  99. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  100. ;; Expand region
  101. (use-package expand-region
  102. :ensure t
  103. :config
  104. (global-set-key (kbd "<f11>") 'er/expand-region)
  105. (delete-selection-mode t) ; typed text replaces the selection
  106. )
  107. ;; Smartparens
  108. (use-package smartparens
  109. :ensure t
  110. :hook
  111. ((lisp-mode emacs-lisp-mode gfm-mode markdown-mode LaTeX-mode)
  112. . show-paren-mode)
  113. ((lisp-mode emacs-lisp-mode gfm-mode markdown-mode LaTeX-mode)
  114. . smartparens-mode)
  115. :config
  116. (sp-local-pair '(lisp-mode emacs-lisp-mode) "'" nil :actions nil)
  117. (sp-local-pair '(lisp-mode emacs-lisp-mode) "`" nil :actions nil)
  118. )
  119. ;; Helm (completion framework)
  120. (use-package helm
  121. :ensure t
  122. :bind (("M-x" . helm-M-x))
  123. :config
  124. (helm-mode 1))
  125. (winner-mode t) ; C-c ←/→ for going between used window configurations
  126. (setq-default word-wrap t)
  127. (defun unfill-paragraph () ; for copy-pasting to external program
  128. "Takes a multi-line paragraph and makes it into a single line of text."
  129. (interactive)
  130. (let ((fill-column (point-max)))
  131. (fill-paragraph nil)))
  132. (define-key global-map "\M-Q" 'unfill-paragraph) ; alt+shift+q
  133. ;; Sort words
  134. ;; https://www.emacswiki.org/emacs/SortWords
  135. (defun sort-words (reverse beg end)
  136. "Sort words in region alphabetically, in REVERSE if negative.
  137. Prefixed with negative \\[universal-argument], sorts in reverse.
  138. The variable `sort-fold-case' determines whether alphabetic case
  139. affects the sort order.
  140. See `sort-regexp-fields'."
  141. (interactive "*P\nr")
  142. (sort-regexp-fields reverse "\\w+" "\\&" beg end))
  143. (windmove-default-keybindings windmove-key)
  144. (setq mouse-yank-at-point t) ; Use current cursor position for middle
  145. ; mouse pasting instead of jumping to new
  146. ; location then paste
  147. ;; F9 opens file where we save www-bookmarks
  148. (global-set-key (kbd "<f9>") (lambda() (interactive)(find-file own-bookmark-file)))
  149. ;; Xclip
  150. (when want-to-use-xclip
  151. (use-package xclip
  152. :ensure t
  153. :config
  154. (xclip-mode 1)
  155. ))
  156. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  157. ;;;;;;;;;;;;;;;;;;;;;;;;
  158. ;;;; Coding related ;;;;
  159. ;;;;;;;;;;;;;;;;;;;;;;;;
  160. (global-set-key "\C-x\C-m" 'compile) ; C-x C-m compile
  161. (setq compilation-read-command nil ; compile with "make -k"
  162. compilation-scroll-output t) ; autoscroll compilation buffer
  163. (use-package magit
  164. :ensure t
  165. :bind
  166. ("C-x g" . magit-status))
  167. (use-package company ; Company (complete anything) mode
  168. :ensure t
  169. :hook
  170. ((latex-mode LaTeX-mode emacs-lisp-mode) . company-mode)
  171. ((latex-mode LaTeX-mode) . (lambda ()
  172. (set (make-local-variable 'company-backends)
  173. '((company-dabbrev)))))
  174. :custom
  175. (company-tooltip-align-annotations 1)
  176. (company-minimum-prefix-length 1)
  177. (company-idle-delay 0.0)
  178. (company-selection-wrap-around t)
  179. (company-dabbrev-ignore-case nil)
  180. (company-dabbrev-downcase nil)
  181. :config
  182. (company-tng-mode)
  183. (define-key company-active-map [up] nil)
  184. (define-key company-active-map [down] nil))
  185. (use-package slime ; SLIME (Common LISP)
  186. :ensure t
  187. :custom
  188. (inferior-lisp-program "clisp")
  189. :config
  190. (slime-setup '(slime-fancy)))
  191. (use-package slime-company
  192. :ensure t
  193. :after (slime company)
  194. :custom
  195. (slime-company-completion 'fuzzy)
  196. :config
  197. (slime-setup '(slime-company)))
  198. (use-package geiser-chez ; For Chez Scheme, start M-x run-geiser
  199. :ensure t)
  200. (use-package markdown-mode
  201. :ensure t
  202. :mode ("README\\.md\\'" . gfm-mode)
  203. :custom
  204. (markdown-command "pandoc"))
  205. ;; Indentation & behaviour
  206. (setq-default indent-tabs-mode nil
  207. standard-indent 2)
  208. ;;;;;;;;;;;;;;;;;;;;;;;;
  209. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  210. ;;;; LaTeX / math related ;;;;
  211. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  212. (add-to-list 'auto-mode-alist '("\\.m\\'" . octave-mode))
  213. (setq bibtex-align-at-equal-sign t) ; align = in bibtex using C-c C-q
  214. (if (display-graphic-p)
  215. (use-package pdf-tools
  216. :ensure t
  217. :config
  218. (pdf-tools-install :no-query))
  219. (use-package org-noter
  220. :ensure t
  221. :custom
  222. (org-noter-notes-search-path (list bibliography-notes))))
  223. (use-package tex
  224. :ensure auctex
  225. :custom
  226. (TeX-source-correlate-mode t) ; for forward search
  227. :config
  228. (add-to-list 'TeX-view-program-selection
  229. `(output-pdf ,pdf-viewer)) ; ` is like quote but allows
  230. ; evaluation inside using ,
  231. :hook
  232. ; Make \ part of words in LaTeX-mode
  233. ((latex-mode LaTeX-mode) . (lambda () (modify-syntax-entry
  234. (string-to-char TeX-esc)
  235. "w"
  236. LaTeX-mode-syntax-table))))
  237. (use-package reftex
  238. :ensure t
  239. :hook
  240. ((latex-mode LaTeX-mode) . turn-on-reftex))
  241. (use-package bibtex
  242. :custom
  243. ;; Ignore only lower case title words instead of all non-uppercased
  244. ;; ones when generating keys for bibtex
  245. (bibtex-autokey-titleword-ignore
  246. '("A" "An" "On" "The" "Eine?" "Der" "Die" "Das" "[[:lower:]].*" ".*[^[:upper:][:lower:]0-9].*")))
  247. ;; Helm-bibtex
  248. (use-package helm-bibtex
  249. :ensure t
  250. :demand t ; otherwise biblio-key will be bound to void
  251. :init ; can't have a form like biblio-key under :bind
  252. (bind-key biblio-key 'helm-command-prefix)
  253. :config
  254. (define-key helm-command-map biblio-key 'helm-resume)
  255. :bind
  256. (:map helm-command-map
  257. ("b" . helm-bibtex)
  258. ("B" . helm-bibtex-with-local-bibliography)
  259. ("n" . helm-bibtex-with-notes))
  260. ;; (define-key helm-command-map (kbd "<f12>") 'helm-resume)
  261. :custom
  262. (bibtex-completion-bibliography
  263. (list ; needs (list ...) for new org-ref to work
  264. bibliography-file))
  265. (bibtex-completion-library-path
  266. (list ; needs (list ...) for new org-ref to work
  267. bibliography-pdf-folder))
  268. (bibtex-completion-pdf-extension '(".pdf" ".djvu"))
  269. (bibtex-completion-pdf-open-function 'org-open-file)
  270. (bibtex-completion-notes-path bibliography-notes)
  271. (bibtex-completion-additional-search-fields '(keywords tags))
  272. (bibtex-completion-pdf-field "File")
  273. (bibtex-completion-pdf-symbol "⌘")
  274. (bibtex-completion-notes-symbol "✎")
  275. )
  276. (use-package org-ref ; Includes doi-utils
  277. :ensure t
  278. :custom
  279. ;; Words which shouldn't be capitalized in titles
  280. (org-ref-lower-case-words '("a" "an" "at" "on" "and" "for" "the" "of" "in"))
  281. ;; Allow the following fields Into Title Case of the Following Items
  282. (org-ref-title-case-types '(("article" "title")
  283. ("book" "booktitle")
  284. ("misc" "title")))
  285. ;; Don't convert ä,ö,å, etc when org-ref-clean-bibtex-entry
  286. (org-ref-clean-bibtex-entry-hook
  287. '(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)))
  288. (use-package emacsql-sqlite-builtin :ensure t)
  289. (use-package org-roam
  290. :ensure t
  291. :after emacsql-sqlite-builtin
  292. :init
  293. (setq org-roam-database-connector 'sqlite-builtin)
  294. :custom
  295. (org-roam-directory bibliography-notes)
  296. (org-roam-capture-templates
  297. `(("d" "default" plain "%?"
  298. :target (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}")
  299. :unnarrowed t)
  300. ("b" "bibliography notes" plain ; Org-noter integration
  301. (file ,(concat bibliography-notes "notes-template.org"))
  302. :target (file+head "${citekey}.org" "#+title: ${title}\n")
  303. :unnarrowed t)))
  304. :config
  305. (org-roam-db-autosync-mode 1))
  306. (use-package org-roam-bibtex
  307. :ensure t
  308. :custom
  309. (orb-preformat-keywords '("citekey" "title" "url" "author-or-editor" "keywords" "file")) ; customisation for notes, org-noter integration
  310. (orb-process-file-keyword t)
  311. (orb-attached-file-extensions '("pdf"))
  312. ;;(bibtex-completion-edit-notes-function 'bibtex-completion-edit-notes-default) ; default to org-ref for notes
  313. (bibtex-completion-edit-notes-function 'orb-bibtex-completion-edit-note) ; use org-roam-capture-templates for notes
  314. :config
  315. (require 'org-ref))
  316. (use-package org-roam-ui
  317. :ensure t
  318. :after org-roam
  319. :custom
  320. (org-roam-ui-sync-theme t)
  321. (org-roam-ui-follow t)
  322. (org-roam-ui-update-on-save t)
  323. (org-roam-ui-open-on-start t))
  324. (use-package scihub
  325. :ensure t
  326. :custom
  327. (scihub-download-directory (car bibtex-completion-library-path))
  328. (scihub-open-after-download nil)
  329. (scihub-fetch-domain 'scihub-fetch-domains-lovescihub))
  330. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  331. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  332. ;;;; Org-mode related ;;;;
  333. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  334. (use-package org
  335. :ensure t
  336. :bind
  337. ("C-c l" . org-store-link)
  338. ("C-c a" . org-agenda)
  339. ("C-c c" . org-capture)
  340. :custom
  341. (org-agenda-files (list own-calendar-file
  342. gtd-inbox
  343. gtd-gtd
  344. gtd-tickler
  345. gtd-someday))
  346. (org-agenda-start-on-weekday 1) ; nil means current day
  347. (org-agenda-span 7)
  348. (org-refile-targets '((org-agenda-files :maxlevel . 9)
  349. (gtd-inbox :maxlevel . 3)
  350. (gtd-someday :maxlevel . 2)
  351. (gtd-tickler :maxlevel . 2)
  352. (gtd-archive :level . 1)))
  353. (org-archive-reversed-order t) ; same for archiving with C-c C-x A
  354. (org-refile-use-outline-path t)
  355. (org-todo-keywords
  356. '((sequence "TODO(t)" "WAIT(w)" "MEET(m)"
  357. "|" "DONE(d)" "CANCELLED(c@)")))
  358. (org-todo-repeat-to-state t)
  359. (org-log-done 'time)
  360. ;; See see http://cachestocaches.com/2016/9/my-workflow-org-agenda/
  361. (org-capture-templates
  362. `(("t" "Todo [gtd inbox]" entry (file+headline ,gtd-inbox "Tasks")
  363. "* TODO %i%? %A")
  364. ("T" "Tickler" entry (file+headline ,gtd-tickler "Tickler")
  365. "* %i%? \n%T")
  366. ("m" "Meeting" entry (file+headline ,gtd-inbox "Tasks")
  367. "* MEET %i%? %A")
  368. ("b" "Bookmark" entry (file+headline ,own-bookmark-file "Bookmarks")
  369. "* %x %?%^g\n:PROPERTIES:\n:CREATED: %U\n:END:\n\n" :empty-lines-before 1)
  370. ("n" "Pdf note from email" plain (file ,bibliography-file)
  371. "@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)))
  372. ;; Org & agendar look
  373. (org-todo-keyword-faces '(("MEET" .
  374. (:foreground "#486f66"
  375. :background "#f4bbce"
  376. :weight ultra-bold))))
  377. (org-agenda-prefix-format
  378. '((agenda . " %i %?-12t% s") ; default: " %i %-12:c%?-12t% s"
  379. (todo . " %i %-12:c")
  380. (tags . " %i %-12:c")
  381. (search . " %i %-12:c")))
  382. (org-format-latex-options '(:foreground default
  383. :background default
  384. :scale 1.0
  385. :html-foreground "Black"
  386. :html-background "Transparent"
  387. :html-scale 1.0
  388. :matchers ("begin" "$1" "$" "$$" "\\(" "\\[")))
  389. (org-outline-path-complete-in-steps nil) ; for completions to work in Helm
  390. :config
  391. ;; Open pdf & djvu outside emacs
  392. (defun alist-set (KEY PROP ALIST)
  393. (set ALIST (assoc-delete-all KEY (symbol-value ALIST)))
  394. (add-to-list ALIST (cons KEY PROP)))
  395. (alist-set "\\.pdf\\'" document-view 'org-file-apps)
  396. (alist-set "\\.djvu\\'" document-view 'org-file-apps)
  397. ;; C-c C- s RET inserts block. See ":exports both" for results.
  398. (org-babel-do-load-languages
  399. 'org-babel-load-languages
  400. '((calc . t)
  401. (octave . t)
  402. (R . t)
  403. (python . t) ; see https://emacs.stackexchange.com/a/64539
  404. (shell . t)))
  405. (setq org-babel-python-command
  406. "python3") ; add ":python python" to block for python2
  407. ;; Automagically save org-buffers after org-refile moves stuff
  408. (defun my-org-refile (&optional goto default-buffer rfloc msg)
  409. (interactive "P")
  410. "Does an ~org-refile~ and then a ~org-save-all-org-buffers~."
  411. (org-refile goto default-buffer rfloc msg) (org-save-all-org-buffers))
  412. (define-key org-mode-map (kbd "C-c C-w") 'my-org-refile)
  413. )
  414. (use-package helm-org
  415. :ensure t
  416. :after (org helm)
  417. :config
  418. (add-to-list 'helm-completing-read-handlers-alist '(org-capture . helm-org-completing-read-tags))
  419. (add-to-list 'helm-completing-read-handlers-alist '(org-set-tags . helm-org-completing-read-tags)))
  420. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  421. (custom-set-variables
  422. ;; custom-set-variables was added by Custom.
  423. ;; If you edit it by hand, you could mess it up, so be careful.
  424. ;; Your init file should contain only one such instance.
  425. ;; If there is more than one, they won't work right.
  426. '(bbdb-mua-interactive-action '(query . create) nil nil "Customized with use-package bbdb")
  427. '(custom-safe-themes
  428. '("4c7228157ba3a48c288ad8ef83c490b94cb29ef01236205e360c2c4db200bb18" default)))
  429. (custom-set-faces
  430. ;; custom-set-faces was added by Custom.
  431. ;; If you edit it by hand, you could mess it up, so be careful.
  432. ;; Your init file should contain only one such instance.
  433. ;; If there is more than one, they won't work right.
  434. )