summaryrefslogtreecommitdiff
path: root/bog.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2014-11-23 00:45:47 -0500
committerKyle Meyer <kyle@kyleam.com>2014-11-23 00:45:47 -0500
commitdff85f2f57f68a63b922aa101bfc130fdf80b13a (patch)
tree67e4e927b0bb2177b9dde331e4783ac70cf1f90c /bog.el
parent3bb227f34ceac610b594583ac38b453dca065790 (diff)
downloadbog-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.
Diffstat (limited to 'bog.el')
-rw-r--r--bog.el24
1 files changed, 9 insertions, 15 deletions
diff --git a/bog.el b/bog.el
index c3d9384..62722d8 100644
--- a/bog.el
+++ b/bog.el
@@ -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)