lang/org: better font-lock reconfig

+ TODO/DONE tags now respect underlying faces
+ ...but still fontify a complete heading properly
+ Statistics cookies (e.g. [3/14]) now respect their underlying faces
+ ...but respect org-headlined-one more
+ Refactor other font-lock rules
This commit is contained in:
Henrik Lissner 2017-05-19 13:21:39 +02:00
parent 13b2cc9446
commit 4bb4b5ebb9

View file

@ -190,14 +190,36 @@
ext-regexp "\\)\\(\\]\\]\\|>\\|'\\)?") . 2) ext-regexp "\\)\\(\\]\\]\\|>\\|'\\)?") . 2)
(,(concat "<\\(http://.+\\." ext-regexp "\\)>") . 1)))) (,(concat "<\\(http://.+\\." ext-regexp "\\)>") . 1))))
;;; Custom fontification ;;; Custom fontification
(add-hook! 'org-font-lock-set-keywords-hook (defun +org--tag-face (n)
(setq org-font-lock-extra-keywords (let ((kwd (match-string n)))
(delete '("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]" (or (and (equal kwd "#") 'org-tag)
(and (equal kwd "@") 'org-special-keyword))))
(defun +org|adjust-faces ()
"Correct (and improve) org-mode's font-lock keywords.
1. Re-set `org-todo' & `org-headline-done' faces, to make them respect
underlying faces.
2. Fontify item bullets
3. Fontify item checkboxes (and when they're marked done)"
(let ((org-todo (format org-heading-keyword-regexp-format
org-todo-regexp))
(org-done (format org-heading-keyword-regexp-format
(concat "\\(?:" (mapconcat #'regexp-quote org-done-keywords "\\|") "\\)"))))
(setq
org-font-lock-extra-keywords
(append (org-delete-all
`(("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
(0 (org-get-checkbox-statistics-face) t)) (0 (org-get-checkbox-statistics-face) t))
org-font-lock-extra-keywords)) (,org-todo (2 (org-get-todo-face 2) t))
(nconc org-font-lock-extra-keywords (,org-done (2 'org-headline-done t)))
'(;; Make checkbox statistic cookies respect underlying faces org-font-lock-extra-keywords)
`((,org-todo (2 (org-get-todo-face 2) prepend))
(,org-done (2 'org-headline-done prepend))
;; Make checkbox statistic cookies respect underlying faces
("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]" ("\\[\\([0-9]*%\\)\\]\\|\\[\\([0-9]*\\)/\\([0-9]*\\)\\]"
(0 (org-get-checkbox-statistics-face) prepend)) (0 (org-get-checkbox-statistics-face) prepend))
;; I like how org-mode fontifies checked TODOs and want this to extend to ;; I like how org-mode fontifies checked TODOs and want this to extend to
@ -210,12 +232,10 @@
("^ *\\(-----+\\)$" 1 'org-meta-line) ("^ *\\(-----+\\)$" 1 'org-meta-line)
;; custom #hashtags & @at-tags for another level of organization ;; custom #hashtags & @at-tags for another level of organization
;; TODO refactor this into a single rule ;; TODO refactor this into a single rule
("\\s-\\(#[^ \n]+\\)" 1 'org-tag) ("\\s-\\(\\([#@]\\)[^ \n]+\\)" 1 (+org--tag-face 2)))))))
("\\s-\\(@[^ \n]+\\)" 1 'org-special-keyword)))) (add-hook 'org-font-lock-set-keywords-hook #'+org|adjust-faces)
;; Enable gpg support ;; enable gpg support
(require 'epa-file)
(epa-file-enable)
(require 'org-crypt) (require 'org-crypt)
(org-crypt-use-before-save-magic) (org-crypt-use-before-save-magic)
(setq org-tags-exclude-from-inheritance '("crypt") (setq org-tags-exclude-from-inheritance '("crypt")