From 6218b61a377e193dde9c01db59bb010e0a8b4aed Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Mon, 16 Mar 2015 22:41:04 -0400 Subject: Support highlighting citekeys in non-Org buffers --- bog.el | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'bog.el') diff --git a/bog.el b/bog.el index 55d63fe..bcbbb3a 100644 --- a/bog.el +++ b/bog.el @@ -1208,12 +1208,17 @@ Topic headings are determined by `bog-topic-heading-level'." "Face used to highlight text that matches `bog-citekey-format'.") (defun bog-fontify-non-heading-citekeys (limit) + "Highlight non-heading citekey in an Org buffer." (let (case-fold-search) (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)))))) +(defvar bog-citekey-font-lock-keywords + `((,bog-citekey-format . 'bog-citekey-face)) + "Citekey font-lock for non-Org buffers.") + ;;; Minor mode @@ -1265,10 +1270,14 @@ if ARG is omitted or nil. :require 'bog (cond (bog-mode - (add-hook 'org-font-lock-hook 'bog-fontify-non-heading-citekeys) + (if (derived-mode-p 'org-mode) + (add-hook 'org-font-lock-hook 'bog-fontify-non-heading-citekeys) + (font-lock-add-keywords nil bog-citekey-font-lock-keywords)) (font-lock-fontify-buffer)) (t - (remove-hook 'org-font-lock-hook 'bog-fontify-non-heading-citekeys) + (if (derived-mode-p 'org-mode) + (remove-hook 'org-font-lock-hook 'bog-fontify-non-heading-citekeys) + (font-lock-remove-keywords nil bog-citekey-font-lock-keywords)) (font-lock-fontify-buffer) (when (bound-and-true-p bog-view-mode) (bog-view-mode -1))))) -- cgit v1.2.3