emacs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  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. ;; Make garbage collection less frequent
  44. ;; then put to normal at the end of init
  45. (setq gc-cons-threshold (* 50 1000 1000))
  46. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  47. ;; General text file handling ;;
  48. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  49. ;; Coding system
  50. (set-language-environment "UTF-8")
  51. (setq locale-coding-system 'utf-8)
  52. (prefer-coding-system 'utf-8)
  53. (set-default-coding-systems 'utf-8)
  54. (set-terminal-coding-system 'utf-8)
  55. (set-keyboard-coding-system 'utf-8)
  56. (set-selection-coding-system 'utf-8)
  57. (setq-default buffer-file-coding-system 'utf-8)
  58. (add-to-list 'safe-local-variable-values '(buffer-file-coding-system . utf-8))
  59. ;; Backups into ~/.emacs-saves
  60. (unless (file-exists-p "~/.saves-emacs")
  61. (make-directory "~/.saves-emacs"))
  62. (setq backup-directory-alist '(("." . "~/.saves-emacs"))
  63. backup-by-copying t
  64. delete-old-versions t
  65. kept-new-versions 6
  66. kept-old-versions 2
  67. version-control t)
  68. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  69. ;;;;;;;;;;;;;;;;;;;;;;;
  70. ;;;; Email related ;;;;
  71. ;;;;;;;;;;;;;;;;;;;;;;;
  72. (setq mail-user-agent 'gnus-user-agent
  73. epg-pinentry-mode 'loopback) ; Avoids GPG password input entry
  74. ; issue in emacs termux. Might need
  75. ; to edit .gnupeg/gpg-agent.conf
  76. ; and add "allow-emacs-pinentry"
  77. ;; BBDB settings
  78. (use-package bbdb
  79. :ensure t
  80. :custom
  81. (bbdb-file (concat keepass-folder "bbdb"))
  82. (bbdb-mua-pop-up t) ; Display BBDB in popup window
  83. (bbdb-mua-pop-up-window-size 3)
  84. (bbdb-mua-update-interactive-p
  85. '(query . create)) ; Look for existing contact, interactively
  86. ; prompt to create
  87. :config
  88. (bbdb-initialize 'gnus 'message)
  89. (bbdb-mua-auto-update-init 'gnus 'message))
  90. ;;;;;;;;;;;;;;;;;;;;;;;
  91. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  92. ;;;; Appearance related ;;;;
  93. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  94. ;; Nyan-mode.
  95. (use-package nyan-mode
  96. :ensure t
  97. :config
  98. (nyan-mode 1)
  99. (nyan-start-animation)
  100. ;; Install sox in termux to play music and uncomment below.
  101. ;; (defun nyan-start-music ()
  102. ;; (interactive)
  103. ;; (unless nyan-music-process
  104. ;; (setq nyan-music-process (start-process-shell-command "nyan-music" "nyan-music" (concat "play " +nyan-music+ " repeat 9001")))))
  105. )
  106. ;; Bar instead of cursor & highlight it on buffer change
  107. (setq-default cursor-type 'bar)
  108. (use-package beacon
  109. :ensure t
  110. :defer t
  111. :init (beacon-mode 1)
  112. :config
  113. (setq beacon-blink-when-window-scrolls nil))
  114. ;; Mixed pitch font in latex and org
  115. (use-package mixed-pitch
  116. :ensure t
  117. :defer t
  118. :hook ((org-mode . mixed-pitch-mode)
  119. (LaTeX-mode . mixed-pitch-mode)))
  120. ;; Theme
  121. (use-package nord-theme ; Good candidates: nord-theme, dracula-theme
  122. :ensure t)
  123. (use-package theme-changer
  124. :ensure t
  125. :after nord-theme
  126. :config
  127. (setq calendar-location-name "Espoo")
  128. (setq calendar-latitude 60.18)
  129. (setq calendar-longitude 24.82)
  130. (change-theme nil 'nord))
  131. ;; Color issues
  132. (setq shr-use-colors nil) ; Don't use text color when rendering html
  133. ; using shr (links ok)
  134. ;; Olivetti mode for org-mode etc long texts.
  135. ;; Add
  136. ;; ((nil . ((fill-column . 80)
  137. ;; (mode . olivetti))))
  138. ;; inside a folder's .dir-locals.el to use olivetti for all files there
  139. (use-package olivetti
  140. :ensure t
  141. :defer t
  142. :config
  143. (setq gnus-treat-fill-long-lines nil)
  144. :hook
  145. ((latex-mode LaTeX-mode) . olivetti-mode)
  146. ((latex-mode LaTeX-mode)
  147. .
  148. (lambda () (auto-fill-mode -1))))
  149. (use-package adaptive-wrap
  150. :ensure t
  151. :defer t
  152. :hook
  153. (visual-line-mode . adaptive-wrap-prefix-mode))
  154. (global-visual-line-mode t) ;; Break lines instead of truncating them
  155. (use-package writeroom-mode ; for clutter-free writing
  156. :ensure t
  157. :defer t)
  158. (use-package writegood-mode ; for M-x writegood-mode to avoid passive tense etc
  159. :ensure t
  160. :defer t)
  161. (use-package jinx ; for spellchecking, requires the enchant-2 library (+voikko for Finnish)
  162. ;; install in Windows using: https://github.com/minad/jinx/issues/10
  163. :ensure t
  164. :hook (emacs-startup . global-jinx-mode)
  165. :bind (("M-$" . jinx-correct)
  166. ("C-M-$" . jinx-languages))
  167. :config
  168. (setq jinx-languages "en_GB fi")) ; fi requires voikko
  169. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  170. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  171. ;;;; Emacs (mini-)buffer etc. behaviour ;;;;
  172. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  173. ;; type ~ in minibuffer to go to home directory directly
  174. (defun emilia/take-me-home ()
  175. (interactive)
  176. (if (looking-back "/" nil)
  177. (progn (call-interactively 'delete-minibuffer-contents) (insert "~/"))
  178. (call-interactively 'self-insert-command)))
  179. ;; Completion in M-x, filenames, etc
  180. (use-package vertico
  181. :ensure t
  182. :bind (:map vertico-map (("~" . emilia/take-me-home)
  183. ("TAB" . minibuffer-complete)))
  184. :config
  185. (vertico-mode 1)
  186. (vertico-multiform-mode 1)
  187. (setq read-extended-command-predicate 'command-completion-default-include-p
  188. vertico-multiform-commands '(t (:not posframe))
  189. vertico-count 10 ; Show more candidates
  190. read-file-name-completion-ignore-case t ; Ignore case of file names
  191. read-buffer-completion-ignore-case t ; Ignore case in buffer completion
  192. completion-ignore-case t)) ; Ignore case in completion
  193. (use-package marginalia ; annotations in the minibuffer
  194. :ensure t
  195. :init
  196. (marginalia-mode 1))
  197. (use-package vertico-posframe
  198. :ensure t
  199. :init
  200. (setq vertico-posframe-parameters
  201. '((left-fringe . 12) ;; Fringes
  202. (right-fringe . 12)
  203. (undecorated . nil))) ;; Rounded frame
  204. :config
  205. (vertico-posframe-mode 1)
  206. (setq vertico-posframe-width 88 ;; Narrow frame
  207. vertico-posframe-height vertico-count) ;; Default height
  208. ;; Make embark-act windows also in posframe instead of behind (since I'm using vertico-posframe)
  209. ;; https://emacs-china.org/t/vertico-posframe-embark-buffer/28610/6
  210. (progn
  211. (defun posframe-display-buffer (buffer)
  212. (let ((default-fgc (face-attribute 'default :foreground))
  213. (default-bgc (face-attribute 'default :background))
  214. (hl (face-attribute 'highlight :background)))
  215. (when buffer (posframe-show
  216. buffer
  217. :position (point)
  218. :poshandler 'posframe-poshandler-frame-center
  219. :font-height 1.0
  220. :font-width 1.0
  221. :width 120
  222. :height 20
  223. :border-width 5
  224. :left-fringe 20
  225. :right-fringe 20
  226. :border-color hl
  227. :background-color default-bgc))))
  228. (defvar embark-get-buffer-pos-display-orig-result nil
  229. "Variable to store the original result in embark-get-buffer-pos-display.")
  230. (defun embark-get-buffer-pos-display (orig-fun)
  231. (interactive)
  232. (setq embark-get-buffer-pos-display-orig-result (funcall orig-fun))
  233. (lambda (&optional keymap targets prefix)
  234. (let ((result (funcall embark-get-buffer-pos-display-orig-result keymap targets prefix)))
  235. (when (and result (windowp result))
  236. (posframe-display-buffer (window-buffer result))
  237. (delete-window result)))))
  238. (advice-add #'embark-verbose-indicator :around #'embark-get-buffer-pos-display)))
  239. (use-package orderless
  240. :ensure t
  241. :demand t ; force loading
  242. :config
  243. (setq completion-styles '(orderless basic partial-completion)
  244. completion-category-overrides '((file (styles basic partial-completion)))
  245. orderless-component-separator "[ |]"))
  246. ;; Expand region
  247. (use-package expand-region
  248. :ensure t
  249. :config
  250. (global-set-key (kbd "<f11>") 'er/expand-region)
  251. (delete-selection-mode t) ; typed text replaces the selection
  252. )
  253. ;; Smartparens
  254. (use-package smartparens
  255. :ensure t
  256. :hook
  257. ((lisp-mode emacs-lisp-mode gfm-mode markdown-mode LaTeX-mode)
  258. . show-paren-mode)
  259. ((lisp-mode emacs-lisp-mode gfm-mode markdown-mode LaTeX-mode)
  260. . smartparens-mode)
  261. :config
  262. (sp-local-pair '(lisp-mode emacs-lisp-mode) "'" nil :actions nil)
  263. (sp-local-pair '(lisp-mode emacs-lisp-mode) "`" nil :actions nil)
  264. ;; Add \big( \big), etc. without having to use \bigl( \bigr).
  265. (sp-with-modes '(tex-mode plain-tex-mode latex-mode LaTeX-mode)
  266. (sp-local-pair "\\big(" "\\big)" :post-handlers '(sp-latex-insert-spaces-inside-pair))
  267. (sp-local-pair "\\bigg(" "\\bigg)" :post-handlers '(sp-latex-insert-spaces-inside-pair))
  268. (sp-local-pair "\\Big(" "\\Big)" :post-handlers '(sp-latex-insert-spaces-inside-pair))
  269. (sp-local-pair "\\Bigg(" "\\Bigg)" :post-handlers '(sp-latex-insert-spaces-inside-pair))
  270. (sp-local-pair "\\big[" "\\big]" :post-handlers '(sp-latex-insert-spaces-inside-pair))
  271. (sp-local-pair "\\bigg[" "\\bigg]" :post-handlers '(sp-latex-insert-spaces-inside-pair))
  272. (sp-local-pair "\\Big[" "\\Big]" :post-handlers '(sp-latex-insert-spaces-inside-pair))
  273. (sp-local-pair "\\Bigg[" "\\Bigg]" :post-handlers '(sp-latex-insert-spaces-inside-pair))
  274. (sp-local-pair "\\big\\{" "\\big\\}" :post-handlers '(sp-latex-insert-spaces-inside-pair))
  275. (sp-local-pair "\\bigg\\{" "\\bigg\\}" :post-handlers '(sp-latex-insert-spaces-inside-pair))
  276. (sp-local-pair "\\Big\\{" "\\Big\\}" :post-handlers '(sp-latex-insert-spaces-inside-pair))
  277. (sp-local-pair "\\Bigg\\{" "\\Bigg\\}" :post-handlers '(sp-latex-insert-spaces-inside-pair)))
  278. (eval-after-load 'latex '(require 'smartparens-latex))
  279. )
  280. (winner-mode t) ; C-c ←/→ for going between used window configurations
  281. (setq-default word-wrap nil)
  282. (defun unfill-paragraph () ; for copy-pasting to external program
  283. "Takes a multi-line paragraph and makes it into a single line of text."
  284. (interactive)
  285. (let ((fill-column (point-max)))
  286. (fill-paragraph nil)))
  287. (define-key global-map "\M-Q" 'unfill-paragraph) ; alt+shift+q
  288. ;; Sort words
  289. ;; https://www.emacswiki.org/emacs/SortWords
  290. (defun sort-words (reverse beg end)
  291. "Sort words in region alphabetically, in REVERSE if negative.
  292. Prefixed with negative \\[universal-argument], sorts in reverse.
  293. The variable `sort-fold-case' determines whether alphabetic case
  294. affects the sort order.
  295. See `sort-regexp-fields'."
  296. (interactive "*P\nr")
  297. (sort-regexp-fields reverse "\\w+" "\\&" beg end))
  298. (windmove-default-keybindings windmove-key)
  299. (setq mouse-yank-at-point t) ; Use current cursor position for middle
  300. ; mouse pasting instead of jumping to new
  301. ; location then paste
  302. ;; F9 opens file where we save www-bookmarks
  303. (global-set-key (kbd "<f9>") (lambda() (interactive)(find-file own-bookmark-file)))
  304. ;; Xclip
  305. (when want-to-use-xclip
  306. (use-package xclip
  307. :ensure t
  308. :config
  309. (xclip-mode 1)
  310. ))
  311. ;; Scroll speed
  312. (setq scroll-conservatively 101
  313. mouse-wheel-follow-mouse 't
  314. mouse-wheel-progressive-speed nil
  315. ;; Scroll 1 line at a time, instead of default 5
  316. ;; Hold shift to scroll faster and meta to scroll very fast
  317. mouse-wheel-scroll-amount '(1 ((shift) . 3) ((meta) . 6)))
  318. ;; (Native) smooooooth scrolling
  319. (setq pixel-scroll-precision-mode t)
  320. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  321. ;;;;;;;;;;;;;;;;;;;;;;;;
  322. ;;;; Coding related ;;;;
  323. ;;;;;;;;;;;;;;;;;;;;;;;;
  324. (global-set-key "\C-x\C-m" 'compile) ; C-x C-m compile
  325. (setq compilation-read-command nil ; compile with "make -k"
  326. compilation-scroll-output t) ; autoscroll compilation buffer
  327. (use-package magit
  328. :ensure t
  329. :bind
  330. ("C-x g" . magit-status)
  331. :custom
  332. (magit-diff-refine-hunk 'all))
  333. (use-package abridge-diff
  334. :ensure t
  335. :after magit
  336. :init (abridge-diff-mode 1))
  337. ;; Completion
  338. (use-package company
  339. :ensure t
  340. :hook
  341. ((emacs-lisp-mode latex-mode LaTeX-mode) . company-mode)
  342. :custom
  343. (company-tooltip-align-annotations 1)
  344. (company-minimum-prefix-length 1)
  345. (company-idle-delay 0.0)
  346. (company-selection-wrap-around t)
  347. (company-dabbrev-ignore-case nil)
  348. (company-dabbrev-downcase nil)
  349. :config
  350. (company-tng-mode)
  351. (define-key company-active-map [up] nil)
  352. (define-key company-active-map [down] nil)
  353. (define-key company-active-map [tab] nil)
  354. (define-key company-active-map (kbd "TAB") nil)
  355. (define-key company-active-map (kbd "<C-tab>") 'company-complete-common-or-cycle)
  356. (define-key company-active-map (kbd "C-<iso-lefttab>") 'company-cycle-backward)
  357. (define-key company-tng-map [tab] nil)
  358. (define-key company-tng-map (kbd "TAB") nil)
  359. (define-key company-tng-map [backtab] nil)
  360. (define-key company-tng-map (kbd "S-TAB") nil)
  361. (define-key company-tng-map (kbd "<C-tab>") 'company-select-next)
  362. (define-key company-tng-map [C-backtab] 'company-select-previous)
  363. (define-key company-tng-map (kbd "C-<iso-lefttab>") 'company-select-previous))
  364. (use-package company-reftex
  365. :ensure t
  366. :after (reftex company)
  367. :hook
  368. ((latex-mode LaTeX-mode) . (lambda ()
  369. (set (make-local-variable 'company-backends)
  370. '((company-reftex-labels company-reftex-citations company-dabbrev)))))
  371. :custom
  372. (company-reftex-labels-regexp
  373. (rx "\\"
  374. ;; List taken from `reftex-ref-style-alist'
  375. (or "autoref"
  376. "autopageref"
  377. "Cpageref"
  378. "cpageref"
  379. "Cref"
  380. "cref"
  381. "eqref"
  382. "Fref"
  383. "fref"
  384. "pageref"
  385. "Ref"
  386. "ref"
  387. "vpageref"
  388. "Vref"
  389. "vref"
  390. ;; own stuff:
  391. "ilo")
  392. "{"
  393. (group (* (not (any "}"))))
  394. (regexp "\\="))
  395. "Regular expression to use when lookng for the label prefix.
  396. Group number 1 should be the prefix itself."
  397. :type 'string
  398. :group 'company-reftex)
  399. )
  400. (use-package slime ; SLIME (Common LISP)
  401. :ensure t
  402. :defer
  403. :custom
  404. (inferior-lisp-program "clisp")
  405. :config
  406. (slime-setup '(slime-fancy)))
  407. (use-package slime-company
  408. :ensure t
  409. :defer
  410. :after (slime company)
  411. :custom
  412. (slime-company-completion 'fuzzy)
  413. :config
  414. (slime-setup '(slime-company)))
  415. (use-package geiser-chez ; For Chez Scheme, start M-x run-geiser
  416. :ensure t
  417. :defer)
  418. (use-package markdown-mode
  419. :ensure t
  420. :defer
  421. :mode ("README\\.md\\'" . gfm-mode)
  422. :custom
  423. (markdown-command "pandoc"))
  424. ;; Indentation & behaviour
  425. (defun infer-indentation-style ()
  426. "Default to no tabs, but use tabs if already in project"
  427. (let ((space-count (how-many "^ " (point-min) (point-max)))
  428. (tab-count (how-many "^\t" (point-min) (point-max))))
  429. (if (> space-count tab-count) (setq-default indent-tabs-mode nil))
  430. (if (> tab-count space-count) (setq-default indent-tabs-mode t))))
  431. (setq-default indent-tabs-mode nil
  432. standard-indent 2)
  433. (infer-indentation-style)
  434. ;; C-a and C-e moves to beginning and syntactic element respecting indentation
  435. (use-package mwim
  436. :ensure t
  437. :bind (("C-a" . mwim-beginning-of-code-or-line)
  438. ("C-e" . mwim-end-of-code-or-line)))
  439. ;;;;;;;;;;;;;;;;;;;;;;;;
  440. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  441. ;;;; LaTeX / math /calc related ;;;;
  442. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  443. (add-to-list 'auto-mode-alist '("\\.m\\'" . octave-mode))
  444. (setq bibtex-align-at-equal-sign t) ; align = in bibtex using C-c C-q
  445. (if (display-graphic-p)
  446. (progn
  447. (use-package pdf-tools
  448. :ensure t
  449. :defer
  450. :config
  451. (pdf-tools-install :no-query))
  452. (use-package org-noter
  453. :ensure t
  454. :defer
  455. :after (pdf-tools)
  456. :custom
  457. (org-noter-notes-search-path (list bibliography-notes)))))
  458. (use-package tex
  459. :ensure auctex
  460. :after cdlatex
  461. :custom
  462. (TeX-source-correlate-mode t) ; for forward search
  463. :config
  464. ;; Make sure that when tabbing in org-cdlatex-mode it will not
  465. ;; complain of missing "LaTeX-indent-line".
  466. (defun own-LaTeX-indent-line ()
  467. (when (or (eq major-mode 'LaTeX-mode)
  468. (eq major-mode 'latex-mode))
  469. (LaTeX-indent-line)))
  470. (add-hook 'cdlatex-tab-hook 'own-LaTeX-indent-line)
  471. (add-to-list 'TeX-view-program-selection
  472. `(output-pdf ,pdf-viewer)) ; ` is like quote but allows
  473. ; evaluation inside using ,
  474. :hook
  475. ; Make \ part of words in LaTeX-mode
  476. ((latex-mode LaTeX-mode) . (lambda () (modify-syntax-entry
  477. (string-to-char TeX-esc)
  478. "w"
  479. LaTeX-mode-syntax-table))))
  480. (use-package cdlatex
  481. :ensure t
  482. :custom
  483. (cdlatex-takeover-parenthesis . nil)
  484. :hook
  485. ((latex-mode LaTeX-mode) . cdlatex-mode)
  486. (org-mode . turn-on-org-cdlatex)
  487. :config
  488. (setq cdlatex-env-alist
  489. '(("definition" "\\begin{definition} AUTOLABEL\n?\n\\end{definition}\n" nil)
  490. ("theorem" "\\begin{theorem} AUTOLABEL\n?\n\\end{theorem}\n" nil)
  491. ("lemma" "\\begin{lemma} AUTOLABEL\n?\n\\end{lemma}\n" nil)))
  492. (setq cdlatex-command-alist
  493. '(("def" "Insert definition env" "" cdlatex-environment ("definition") t nil)
  494. ("thm" "Insert theorem env" "" cdlatex-environment ("theorem") t nil)
  495. ("lem" "Insert lemma env" "" cdlatex-environment ("lemma") t nil)
  496. ("wt" "Insert \\widetilde{}" "\\widetilde{?}" cdlatex-position-cursor nil nil t))))
  497. (use-package reftex
  498. :ensure t
  499. :hook
  500. ((latex-mode LaTeX-mode) . turn-on-reftex))
  501. (use-package bibtex
  502. :custom
  503. ;; Ignore only lower case title words instead of all non-uppercased
  504. ;; ones when generating keys for bibtex
  505. (bibtex-autokey-titleword-ignore
  506. '("A" "An" "On" "The" "Eine?" "Der" "Die" "Das" "[[:lower:]].*" ".*[^[:upper:][:lower:]0-9].*")))
  507. ;; Handle references, citar-xxx for actions, use with embark
  508. (use-package citar
  509. :ensure t
  510. :demand t
  511. :bind (:map citar-map
  512. ("m" . citar-attach-files))
  513. :custom
  514. (citar-bibliography (list bibliography-file))
  515. (citar-library-paths (list bibliography-pdf-folder))
  516. (citar-notes-paths (list bibliography-notes))
  517. (citar-file-open-functions
  518. '((t . org-open-file)))
  519. :config ; can't have a form like biblio-key under :bind
  520. (bind-key biblio-key citar-map))
  521. (use-package embark
  522. :ensure t
  523. :bind (("C-." . embark-act)
  524. ("C-h B" . embark-bindings)))
  525. (use-package citar-embark
  526. :ensure t
  527. :after citar embark
  528. :no-require
  529. :config (citar-embark-mode 1))
  530. (use-package org-ref ; Includes doi-utils
  531. :ensure t
  532. :defer
  533. :custom
  534. ;; Words which shouldn't be capitalized in titles
  535. (org-ref-lower-case-words '("a" "an" "at" "on" "and" "for" "the" "of" "in"))
  536. ;; Allow the following fields Into Title Case of the Following Items
  537. (org-ref-title-case-types '(("article" "title")
  538. ("book" "booktitle")
  539. ("misc" "title")))
  540. ;; Don't convert ä,ö,å, etc when org-ref-clean-bibtex-entry
  541. (org-ref-clean-bibtex-entry-hook
  542. '(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)))
  543. (use-package emacsql :ensure t)
  544. (use-package org-roam
  545. :ensure t
  546. :defer
  547. :after emacsql
  548. :init
  549. (setq org-roam-database-connector 'sqlite-builtin)
  550. :custom
  551. (org-roam-directory bibliography-notes)
  552. (org-roam-capture-templates
  553. `(("d" "default" plain "%?"
  554. :target (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}")
  555. :unnarrowed t)
  556. ("b" "bibliography notes" plain ; Org-noter integration
  557. (file ,(concat bibliography-notes "notes-template.org"))
  558. :target (file+head "${citekey}.org" "#+title: ${title}\n")
  559. :unnarrowed t)))
  560. :config
  561. (org-roam-db-autosync-mode 1))
  562. (use-package org-roam-bibtex
  563. :ensure t
  564. :defer
  565. :custom
  566. (orb-preformat-keywords '("citekey" "title" "url" "author-or-editor" "keywords" "file")) ; customisation for notes, org-noter integration
  567. (orb-process-file-keyword t)
  568. (orb-attached-file-extensions '("pdf"))
  569. ;;(bibtex-completion-edit-notes-function 'bibtex-completion-edit-notes-default) ; default to org-ref for notes
  570. (bibtex-completion-edit-notes-function 'orb-bibtex-completion-edit-note) ; use org-roam-capture-templates for notes
  571. :config
  572. (require 'org-ref))
  573. (use-package org-roam-ui
  574. :ensure t
  575. :after org-roam
  576. :custom
  577. (org-roam-ui-sync-theme t)
  578. (org-roam-ui-follow t)
  579. (org-roam-ui-update-on-save t)
  580. (org-roam-ui-open-on-start t))
  581. (use-package casual
  582. :ensure t
  583. :after calc
  584. :bind (:map calc-mode-map ("C-o" . 'casual-calc-tmenu))
  585. )
  586. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  587. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  588. ;;;; Org-mode related ;;;;
  589. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  590. (use-package org
  591. :ensure t
  592. :bind
  593. ("C-c l" . org-store-link)
  594. ("C-c a" . org-agenda)
  595. ("C-c c" . org-capture)
  596. :custom
  597. (org-agenda-files (list own-calendar-file
  598. gtd-inbox
  599. gtd-gtd
  600. gtd-tickler
  601. gtd-someday))
  602. (org-agenda-start-on-weekday 1) ; nil means current day
  603. (org-agenda-span 7)
  604. (org-refile-targets '((org-agenda-files :maxlevel . 9)
  605. (gtd-inbox :maxlevel . 3)
  606. (gtd-someday :maxlevel . 2)
  607. (gtd-tickler :maxlevel . 2)
  608. (gtd-archive :level . 1)))
  609. (org-archive-reversed-order t) ; same for archiving with C-c C-x A
  610. (org-refile-use-outline-path t)
  611. (org-todo-keywords
  612. '((sequence "TODO(t)" "MEET(m)"
  613. "|" "DONE(d)" "WAIT(w@)" "CANCELLED(c@)")))
  614. (org-todo-repeat-to-state t)
  615. (org-log-done 'time)
  616. ;; See see http://cachestocaches.com/2016/9/my-workflow-org-agenda/
  617. (org-capture-templates
  618. `(("t" "Todo [gtd inbox]" entry (file+headline ,gtd-inbox "Tasks")
  619. "* TODO %i%? %A")
  620. ("T" "Tickler" entry (file+headline ,gtd-tickler "Tickler")
  621. "* %i%? \n%T")
  622. ("m" "Meeting" entry (file+headline ,gtd-inbox "Tasks")
  623. "* MEET %i%? %A")
  624. ("b" "Bookmark" entry (file+headline ,own-bookmark-file "Bookmarks")
  625. "* %x %?%^g\n:PROPERTIES:\n:CREATED: %U\n:END:\n\n" :empty-lines-before 1)
  626. ("n" "Pdf note from email" plain (file ,bibliography-file)
  627. "@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)))
  628. ;; Org & agendar look
  629. (org-todo-keyword-faces '(("MEET" .
  630. (:foreground "#486f66"
  631. :background "#f4bbce"
  632. :weight ultra-bold))))
  633. (org-agenda-prefix-format
  634. '((agenda . " %i %?-12t% s") ; default: " %i %-12:c%?-12t% s"
  635. (todo . " %i %-12:c")
  636. (tags . " %i %-12:c")
  637. (search . " %i %-12:c")))
  638. (org-format-latex-options '(:foreground default
  639. :background default
  640. :scale 1.0
  641. :html-foreground "Black"
  642. :html-background "Transparent"
  643. :html-scale 1.0
  644. :matchers ("begin" "$1" "$" "$$" "\\(" "\\[")))
  645. (org-outline-path-complete-in-steps nil) ; for completions to work in Helm
  646. :config
  647. ;; Open pdf & djvu outside emacs
  648. (defun alist-set (KEY PROP ALIST)
  649. (set ALIST (assoc-delete-all KEY (symbol-value ALIST)))
  650. (add-to-list ALIST (cons KEY PROP)))
  651. (alist-set "\\.pdf\\'" document-view 'org-file-apps)
  652. (alist-set "\\.djvu\\'" document-view 'org-file-apps)
  653. ;; C-c C-s RET inserts block. See ":exports both" for results.
  654. ;; TODO: Section 5 in https://blog.d46.us/advanced-emacs-startup/
  655. (org-babel-do-load-languages
  656. 'org-babel-load-languages
  657. '((calc . t)
  658. (octave . t)
  659. (R . t)
  660. (python . t) ; see https://emacs.stackexchange.com/a/64539
  661. (shell . t)))
  662. (setq org-babel-python-command
  663. "python3") ; add ":python python" to block for python2
  664. ;; Automagically save org-buffers after org-refile moves stuff
  665. (defun my-org-refile (&optional goto default-buffer rfloc msg)
  666. (interactive "P")
  667. "Does an ~org-refile~ and then a ~org-save-all-org-buffers~."
  668. (org-refile goto default-buffer rfloc msg) (org-save-all-org-buffers))
  669. (define-key org-mode-map (kbd "C-c C-w") 'my-org-refile)
  670. ;; F8 opens GTD file
  671. (global-set-key (kbd "<f8>") (lambda() (interactive)(find-file gtd-gtd)))
  672. )
  673. (use-package suomalainen-kalenteri
  674. :ensure t
  675. :after org
  676. :config
  677. (set-face-attribute 'org-agenda-calendar-sexp nil
  678. :inherit 'org-level-2)
  679. )
  680. (use-package org-appear
  681. :ensure t
  682. :commands (org-appear-mode)
  683. :hook (org-mode . org-appear-mode)
  684. :config
  685. (setq org-hide-emphasis-markers t) ; Must be activated for org-appear to work
  686. (setq org-appear-autoemphasis t ; Show bold, italics, verbatim, etc.
  687. org-appear-autosubmarkers t)) ; Show sub- and superscripts
  688. (use-package org-fragtog ; toggle LaTeX previews automatically, like org-appear
  689. :ensure t
  690. :after org
  691. :hook (org-mode . org-fragtog-mode))
  692. ;;;;;;;;;;;;;;;;;;;;;;;;;;
  693. ;; Make garbage collection more frequent now after initialization
  694. (setq gc-cons-threshold (* 2 1000 1000))