From 2cefc2c03ab152e0c8aef6152811a149d2ede5ca Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Fri, 22 Jan 2016 02:11:13 -0500 Subject: Don't assume font-lock-ensure is defined Fixes #5. Also, * Use font-lock-flush instead of font-lock-ensure, which wasn't removing Bog-related highlighting when turning off bog-mode. * Check that font-lock-mode is enabled before calling font-lock function. --- bog.el | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/bog.el b/bog.el index 8b465e9..2049fc2 100644 --- a/bog.el +++ b/bog.el @@ -1295,6 +1295,11 @@ Topic headings are determined by `bog-topic-heading-level'." `((,bog-citekey-format . 'bog-citekey-face)) "Citekey font-lock for non-Org buffers.") +(defvar bog-font-lock-function + (if (fboundp 'font-lock-flush) + #'font-lock-flush + #'font-lock-fontify-buffer)) + ;;; Minor mode @@ -1344,19 +1349,20 @@ if ARG is omitted or nil. :group 'bog :lighter " Bog" :require 'bog - (cond - (bog-mode - (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-ensure)) - (t - (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-ensure) - (when (bound-and-true-p bog-view-mode) - (bog-view-mode -1))))) + (progn + (cond + (bog-mode + (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))) + (t + (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)) + (when (bound-and-true-p bog-view-mode) + (bog-view-mode -1)))) + (when font-lock-mode + (funcall bog-font-lock-function)))) ;;; View minor mode -- cgit v1.2.3