summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS4
-rw-r--r--README.org6
-rw-r--r--bog.el13
3 files changed, 19 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index 6883a90..a42f5d5 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,10 @@
- All Bog commands now work outside of Org buffers. To access them,
bind =bog-command= a global key.
+- When Bog mode is turned on in non-Org buffers, text matching
+ bog-citekey-format is now highlighted, without relying on
+ Org-specific font-lock mechanisms.
+
- New command =bog-citekey-tree-to-indirect-buffer= opens the subtree
for a citekey in an indirect buffer. The citekey is either taken from
at point or selected from all heading citekeys.
diff --git a/README.org b/README.org
index 021f011..af0b4d3 100644
--- a/README.org
+++ b/README.org
@@ -143,8 +143,10 @@ The variables below are important for specifying how Bog behaves.
A keymap is defined for Bog under the prefix =C-c "​=. If you prefer
something else (like =C-c b=), set =bog-keymap-prefix=.
-Many of the Bog functions are useful outside of an Org buffer, so you
-can also bind =bog-command-map= to a global key.
+Many of the Bog functions are useful outside of an Org buffer. You
+can turn Bog minor mode on (=bog-mode=) in non-Org buffers to get
+access to the keymap and citekey highlighting. To make Bog commands
+available from any buffer, bind =bog-command-map= to a global key.
* Other approaches
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)))))