diff options
author | Kyle Meyer <kyle@kyleam.com> | 2014-11-23 00:45:47 -0500 |
---|---|---|
committer | Kyle Meyer <kyle@kyleam.com> | 2014-11-23 00:45:47 -0500 |
commit | dff85f2f57f68a63b922aa101bfc130fdf80b13a (patch) | |
tree | 67e4e927b0bb2177b9dde331e4783ac70cf1f90c | |
parent | 3bb227f34ceac610b594583ac38b453dca065790 (diff) | |
download | bog-dff85f2f57f68a63b922aa101bfc130fdf80b13a.tar.gz |
Fix inconsistent citekey highlighting
With the previous approach, some citekeys weren't highlighted until text
near them was changed. I'm still not certain why this is, but using
`org-font-lock-hook' seems to fix it.
-rw-r--r-- | bog-todo.org | 2 | ||||
-rw-r--r-- | bog.el | 24 |
2 files changed, 10 insertions, 16 deletions
diff --git a/bog-todo.org b/bog-todo.org index aa476b6..22873d3 100644 --- a/bog-todo.org +++ b/bog-todo.org @@ -4,7 +4,7 @@ * General -** BUG Inconsistent face highlighting +** DONE Inconsistent face highlighting Some citekeys are not highlighed until the surrounding text is altered. @@ -774,19 +774,11 @@ current buffer." '((t (:inherit org-link :underline nil))) "Face used to highlight text that matches `bog-citekey-format'.") -(defun bog-non-heading-citekey-p (limit) - (and (re-search-forward bog-citekey-format limit t) - (not (org-at-heading-p)))) - -(defun bog-add-fontlock () - (font-lock-add-keywords nil - '((bog-non-heading-citekey-p . 'bog-citekey-face))) - (font-lock-fontify-buffer)) - -(defun bog-remove-fontlock () - (font-lock-remove-keywords nil - '((bog-non-heading-citekey-p . 'bog-citekey-face))) - (font-lock-fontify-buffer)) +(defun bog-fontify-non-heading-citekeys (limit) + (while (re-search-forward bog-citekey-format limit t) + (unless (save-match-data (org-at-heading-p)) + (add-text-properties (match-beginning 0) (match-end 0) + '(face bog-citekey-face))))) ;;; Commander @@ -903,9 +895,11 @@ ARG is omitted or nil. :require 'bog (cond (bog-mode - (bog-add-fontlock)) + (add-hook 'org-font-lock-hook 'bog-fontify-non-heading-citekeys) + (font-lock-fontify-buffer)) (t - (bog-remove-fontlock)))) + (remove-hook 'org-font-lock-hook 'bog-fontify-non-heading-citekeys) + (font-lock-fontify-buffer)))) (provide 'bog) |