2017-12-08 22:59:42 -05:00
|
|
|
;;; lang/org/config.el -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
(defvar +org-dir (expand-file-name "~/work/org/")
|
|
|
|
"The directory where org files are kept.")
|
2017-07-05 02:33:41 +02:00
|
|
|
|
|
|
|
;; Ensure ELPA org is prioritized above built-in org.
|
2017-12-10 14:49:52 -05:00
|
|
|
(when-let* ((path (locate-library "org" nil doom--package-load-path)))
|
2017-09-22 22:14:00 +02:00
|
|
|
(setq load-path (delete path load-path))
|
|
|
|
(push (file-name-directory path) load-path))
|
2017-07-05 02:33:41 +02:00
|
|
|
|
2017-12-08 22:59:42 -05:00
|
|
|
;; Sub-modules
|
|
|
|
(if (featurep! +attach) (load! +attach))
|
|
|
|
(if (featurep! +babel) (load! +babel))
|
|
|
|
(if (featurep! +capture) (load! +capture))
|
|
|
|
(if (featurep! +export) (load! +export))
|
|
|
|
(if (featurep! +present) (load! +present))
|
|
|
|
;; TODO (if (featurep! +publish) (load! +publish))
|
2017-07-05 02:33:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Plugins
|
|
|
|
;;
|
|
|
|
|
|
|
|
(def-package! toc-org
|
2017-12-09 14:42:42 -05:00
|
|
|
:commands toc-org-enable)
|
2017-07-05 02:33:41 +02:00
|
|
|
|
|
|
|
(def-package! org-crypt ; built-in
|
2017-12-09 14:42:42 -05:00
|
|
|
:commands org-crypt-use-before-save-magic
|
2017-07-05 02:33:41 +02:00
|
|
|
:config
|
|
|
|
(setq org-tags-exclude-from-inheritance '("crypt")
|
2017-12-27 20:48:06 -05:00
|
|
|
org-crypt-key user-mail-address))
|
2017-07-05 02:33:41 +02:00
|
|
|
|
|
|
|
(def-package! org-bullets
|
2017-12-09 14:42:42 -05:00
|
|
|
:commands org-bullets-mode)
|
2017-07-05 02:33:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
2017-12-09 14:42:42 -05:00
|
|
|
;; Bootstrap
|
2017-07-05 02:33:41 +02:00
|
|
|
;;
|
|
|
|
|
2017-12-09 14:42:42 -05:00
|
|
|
(after! org
|
|
|
|
;; Occasionally, Emacs encounters an error loading the built-in org, aborting
|
|
|
|
;; the load. This results in a broken, partially loaded state. This require
|
|
|
|
;; tries to set it straight.
|
2017-12-08 22:59:42 -05:00
|
|
|
(require 'org)
|
|
|
|
|
2017-12-09 14:42:42 -05:00
|
|
|
(defvaralias 'org-directory '+org-dir)
|
|
|
|
|
|
|
|
(org-crypt-use-before-save-magic)
|
2017-12-08 22:59:42 -05:00
|
|
|
(+org-init-ui)
|
|
|
|
(+org-init-keybinds)
|
|
|
|
(+org-hacks))
|
|
|
|
|
2017-12-09 14:42:42 -05:00
|
|
|
(add-hook! org-mode
|
|
|
|
#'(doom|disable-line-numbers ; no line numbers
|
|
|
|
org-bullets-mode ; "prettier" bullets
|
|
|
|
org-indent-mode ; margin-based indentation
|
|
|
|
toc-org-enable ; auto-table of contents
|
|
|
|
visual-line-mode ; line wrapping
|
2017-09-05 16:42:00 +02:00
|
|
|
|
2017-12-09 14:42:42 -05:00
|
|
|
+org|enable-auto-reformat-tables
|
|
|
|
+org|enable-auto-update-cookies
|
|
|
|
+org|smartparens-compatibility-config
|
|
|
|
+org|unfold-to-2nd-level-or-point
|
2017-12-16 12:45:15 -05:00
|
|
|
+org|show-paren-mode-compatibility
|
2017-12-09 14:42:42 -05:00
|
|
|
))
|
2017-09-05 16:42:00 +02:00
|
|
|
|
2017-07-05 02:33:41 +02:00
|
|
|
|
2017-12-09 14:42:42 -05:00
|
|
|
;;
|
|
|
|
;; Config hooks
|
|
|
|
;;
|
2017-07-05 02:33:41 +02:00
|
|
|
|
2017-12-09 14:42:42 -05:00
|
|
|
(defun +org|unfold-to-2nd-level-or-point ()
|
|
|
|
"My version of the 'overview' #+STARTUP option: expand first-level headings.
|
|
|
|
Expands the first level, but no further. If point was left somewhere deeper,
|
|
|
|
unfold to point on startup."
|
2017-07-05 02:33:41 +02:00
|
|
|
(unless org-agenda-inhibit-startup
|
|
|
|
(when (eq org-startup-folded t)
|
|
|
|
(outline-hide-sublevels 2))
|
|
|
|
(when (outline-invisible-p)
|
|
|
|
(ignore-errors
|
|
|
|
(save-excursion
|
|
|
|
(outline-previous-visible-heading 1)
|
2017-12-09 14:42:42 -05:00
|
|
|
(org-show-subtree))))))
|
2017-12-09 00:17:01 -05:00
|
|
|
|
2017-12-09 14:42:42 -05:00
|
|
|
(defun +org|smartparens-compatibility-config ()
|
|
|
|
"Instruct `smartparens' not to impose itself in org-mode."
|
2017-12-09 00:17:01 -05:00
|
|
|
(defun +org-sp-point-in-checkbox-p (_id action _context)
|
|
|
|
(when (eq action 'insert)
|
|
|
|
(sp--looking-at-p "\\s-*]")))
|
|
|
|
|
|
|
|
;; make delimiter auto-closing a little more conservative
|
|
|
|
(sp-with-modes 'org-mode
|
|
|
|
(sp-local-pair "*" nil :unless '(sp-point-after-word-p sp-point-before-word-p sp-point-at-bol-p))
|
|
|
|
(sp-local-pair "_" nil :unless '(sp-point-after-word-p sp-point-before-word-p))
|
|
|
|
(sp-local-pair "/" nil :unless '(sp-point-after-word-p sp-point-before-word-p +org-sp-point-in-checkbox-p))
|
|
|
|
(sp-local-pair "~" nil :unless '(sp-point-after-word-p sp-point-before-word-p))
|
|
|
|
(sp-local-pair "=" nil :unless '(sp-point-after-word-p sp-point-before-word-p))))
|
2017-07-05 02:33:41 +02:00
|
|
|
|
2017-12-09 14:42:42 -05:00
|
|
|
(defun +org|enable-auto-reformat-tables ()
|
|
|
|
"Realign tables exiting insert mode (`evil-mode')."
|
|
|
|
(when (featurep 'evil)
|
|
|
|
(add-hook 'evil-insert-state-exit-hook #'+org|realign-table-maybe nil t)))
|
|
|
|
|
|
|
|
(defun +org|enable-auto-update-cookies ()
|
|
|
|
"Update statistics cookies when saving or exiting insert mode (`evil-mode')."
|
|
|
|
(when (featurep 'evil)
|
|
|
|
(add-hook 'evil-insert-state-exit-hook #'+org|update-cookies nil t))
|
|
|
|
(add-hook 'before-save-hook #'+org|update-cookies nil t))
|
|
|
|
|
2017-12-16 12:45:15 -05:00
|
|
|
(defun +org|show-paren-mode-compatibility ()
|
|
|
|
"`show-paren-mode' causes flickering with indentation margins made by
|
|
|
|
`org-indent-mode', so we simply turn off show-paren-mode altogether."
|
|
|
|
(set (make-local-variable 'show-paren-mode) nil))
|
|
|
|
|
2017-12-09 14:42:42 -05:00
|
|
|
|
2017-07-05 02:33:41 +02:00
|
|
|
;;
|
|
|
|
(defun +org-init-ui ()
|
|
|
|
"Configures the UI for `org-mode'."
|
|
|
|
(setq-default
|
|
|
|
org-adapt-indentation nil
|
|
|
|
org-agenda-dim-blocked-tasks nil
|
|
|
|
org-agenda-files (directory-files +org-dir t "\\.org$" t)
|
|
|
|
org-agenda-inhibit-startup t
|
|
|
|
org-agenda-skip-unavailable-files nil
|
|
|
|
org-cycle-include-plain-lists t
|
|
|
|
org-cycle-separator-lines 1
|
|
|
|
org-entities-user '(("flat" "\\flat" nil "" "" "266D" "♭") ("sharp" "\\sharp" nil "" "" "266F" "♯"))
|
2017-12-08 22:59:42 -05:00
|
|
|
;; org-ellipsis " ... "
|
2017-07-05 02:33:41 +02:00
|
|
|
org-fontify-done-headline t
|
|
|
|
org-fontify-quote-and-verse-blocks t
|
|
|
|
org-fontify-whole-heading-line t
|
|
|
|
org-footnote-auto-label 'plain
|
|
|
|
org-hidden-keywords nil
|
|
|
|
org-hide-emphasis-markers nil
|
|
|
|
org-hide-leading-stars t
|
|
|
|
org-hide-leading-stars-before-indent-mode t
|
|
|
|
org-image-actual-width nil
|
|
|
|
org-indent-indentation-per-level 2
|
|
|
|
org-indent-mode-turns-on-hiding-stars t
|
|
|
|
org-pretty-entities nil
|
|
|
|
org-pretty-entities-include-sub-superscripts t
|
2017-10-05 17:01:10 +02:00
|
|
|
org-priority-faces
|
|
|
|
`((?a . ,(face-foreground 'error))
|
|
|
|
(?b . ,(face-foreground 'warning))
|
|
|
|
(?c . ,(face-foreground 'success)))
|
2017-07-05 02:33:41 +02:00
|
|
|
org-startup-folded t
|
|
|
|
org-startup-indented t
|
|
|
|
org-startup-with-inline-images nil
|
|
|
|
org-tags-column 0
|
2017-11-09 00:35:53 +01:00
|
|
|
org-todo-keywords
|
|
|
|
'((sequence "[ ](t)" "[-](p)" "[?](m)" "|" "[X](d)")
|
|
|
|
(sequence "TODO(T)" "|" "DONE(D)")
|
|
|
|
(sequence "NEXT(n)" "ACTIVE(a)" "WAITING(w)" "LATER(l)" "|" "CANCELLED(c)"))
|
2017-07-05 02:33:41 +02:00
|
|
|
org-use-sub-superscripts '{}
|
|
|
|
outline-blank-line t
|
|
|
|
|
|
|
|
;; LaTeX previews are too small and usually render to light backgrounds, so
|
|
|
|
;; this enlargens them and ensures their background (and foreground) match the
|
|
|
|
;; current theme.
|
2017-12-08 22:59:42 -05:00
|
|
|
org-preview-latex-image-directory (concat doom-cache-dir "org-latex/")
|
2017-07-05 02:33:41 +02:00
|
|
|
org-format-latex-options (plist-put org-format-latex-options :scale 1.5)
|
|
|
|
org-format-latex-options
|
|
|
|
(plist-put org-format-latex-options
|
|
|
|
:background (face-attribute (or (cadr (assq 'default face-remapping-alist))
|
|
|
|
'default)
|
|
|
|
:background nil t)))
|
|
|
|
|
2017-11-06 00:07:37 +01:00
|
|
|
;; Custom links
|
|
|
|
(org-link-set-parameters
|
|
|
|
"org"
|
|
|
|
:complete (lambda () (+org-link-read-file "org" +org-dir))
|
|
|
|
:follow (lambda (link) (find-file (expand-file-name link +org-dir)))
|
|
|
|
:face (lambda (link)
|
|
|
|
(if (file-exists-p (expand-file-name link +org-dir))
|
|
|
|
'org-link
|
|
|
|
'error))))
|
2017-07-05 02:33:41 +02:00
|
|
|
|
|
|
|
(defun +org-init-keybinds ()
|
|
|
|
"Sets up org-mode and evil keybindings. Tries to fix the idiosyncrasies
|
|
|
|
between the two."
|
2017-12-08 22:59:42 -05:00
|
|
|
(map! :map org-mode-map
|
|
|
|
"RET" #'org-return-indent
|
|
|
|
"C-c C-S-l" #'+org/remove-link
|
|
|
|
:n "C-c C-i" #'org-toggle-inline-images
|
|
|
|
|
|
|
|
:n "RET" #'+org/dwim-at-point
|
|
|
|
|
|
|
|
;; Navigate table cells (from insert-mode)
|
|
|
|
:i "C-l" #'+org/table-next-field
|
|
|
|
:i "C-h" #'+org/table-previous-field
|
|
|
|
:i "C-k" #'+org/table-previous-row
|
|
|
|
:i "C-j" #'+org/table-next-row
|
|
|
|
;; Expand tables (or shiftmeta move)
|
|
|
|
:ni "C-S-l" #'+org/table-append-field-or-shift-right
|
|
|
|
:ni "C-S-h" #'+org/table-prepend-field-or-shift-left
|
|
|
|
:ni "C-S-k" #'org-metaup
|
|
|
|
:ni "C-S-j" #'org-metadown
|
|
|
|
|
|
|
|
:n [tab] #'+org/toggle-fold
|
|
|
|
:i [tab] #'+org/indent-or-next-field-or-yas-expand
|
|
|
|
:i [backtab] #'+org/dedent-or-prev-field
|
|
|
|
|
|
|
|
:ni [M-return] (λ! (+org/insert-item 'below))
|
|
|
|
:ni [S-M-return] (λ! (+org/insert-item 'above))
|
|
|
|
|
|
|
|
:m "]]" (λ! (org-forward-heading-same-level nil) (org-beginning-of-line))
|
|
|
|
:m "[[" (λ! (org-backward-heading-same-level nil) (org-beginning-of-line))
|
|
|
|
:m "]l" #'org-next-link
|
|
|
|
:m "[l" #'org-previous-link
|
|
|
|
:m "$" #'org-end-of-line
|
|
|
|
:m "^" #'org-beginning-of-line
|
|
|
|
:n "gQ" #'org-fill-paragraph
|
|
|
|
:n "<" #'org-metaleft
|
|
|
|
:n ">" #'org-metaright
|
|
|
|
:v "<" (λ! (org-metaleft) (evil-visual-restore))
|
|
|
|
:v ">" (λ! (org-metaright) (evil-visual-restore))
|
|
|
|
|
|
|
|
;; Fix code-folding keybindings
|
|
|
|
:n "za" #'+org/toggle-fold
|
|
|
|
:n "zA" #'org-shifttab
|
|
|
|
:n "zc" #'outline-hide-subtree
|
|
|
|
:n "zC" (λ! (outline-hide-sublevels 1))
|
|
|
|
:n "zd" (lambda (&optional arg) (interactive "p") (outline-hide-sublevels (or arg 3)))
|
|
|
|
:n "zm" (λ! (outline-hide-sublevels 1))
|
|
|
|
:n "zo" #'outline-show-subtree
|
|
|
|
:n "zO" #'outline-show-all
|
|
|
|
:n "zr" #'outline-show-all
|
2017-07-05 02:33:41 +02:00
|
|
|
|
|
|
|
(:after org-agenda
|
|
|
|
(:map org-agenda-mode-map
|
|
|
|
:e "<escape>" #'org-agenda-Quit
|
|
|
|
:e "m" #'org-agenda-month-view
|
|
|
|
:e "C-j" #'org-agenda-next-item
|
|
|
|
:e "C-k" #'org-agenda-previous-item
|
|
|
|
:e "C-n" #'org-agenda-next-item
|
|
|
|
:e "C-p" #'org-agenda-previous-item))))
|
|
|
|
|
|
|
|
;;
|
|
|
|
(defun +org-hacks ()
|
|
|
|
"Getting org to behave."
|
|
|
|
;; Don't open separate windows
|
2017-11-10 00:19:04 +01:00
|
|
|
(push '(file . find-file) org-link-frame-setup)
|
2017-07-05 02:33:41 +02:00
|
|
|
|
|
|
|
;; Let OS decide what to do with files when opened
|
|
|
|
(setq org-file-apps
|
|
|
|
`(("\\.org$" . emacs)
|
|
|
|
(t . ,(cond (IS-MAC "open -R \"%s\"")
|
|
|
|
(IS-LINUX "xdg-open \"%s\"")))))
|
|
|
|
|
|
|
|
(defun +org|remove-occur-highlights ()
|
2017-09-05 16:42:00 +02:00
|
|
|
"Remove org occur highlights on ESC in normal mode."
|
2017-09-30 16:34:24 +02:00
|
|
|
(when (and (derived-mode-p 'org-mode)
|
|
|
|
org-occur-highlights)
|
|
|
|
(org-remove-occur-highlights)))
|
2017-07-05 02:33:41 +02:00
|
|
|
(add-hook '+evil-esc-hook #'+org|remove-occur-highlights)
|
|
|
|
|
|
|
|
(after! recentf
|
|
|
|
;; Don't clobber recentf with agenda files
|
|
|
|
(defun +org-is-agenda-file (filename)
|
|
|
|
(cl-find (file-truename filename) org-agenda-files
|
|
|
|
:key #'file-truename
|
|
|
|
:test #'equal))
|
|
|
|
(add-to-list 'recentf-exclude #'+org-is-agenda-file)))
|