From dff85f2f57f68a63b922aa101bfc130fdf80b13a Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sun, 23 Nov 2014 00:45:47 -0500 Subject: 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. --- bog-todo.org | 2 +- 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. 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) -- cgit v1.2.3