emacs 17 KB

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