From 5a5d372a06c7bbd2572944a8291822b395d24b7a Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Mon, 16 Mar 2015 22:23:25 -0400 Subject: Make context-functions check if in Org mode This will allow commands that use the context functions to work outside of Org. --- bog.el | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/bog.el b/bog.el index a3823a5..17dc3c7 100644 --- a/bog.el +++ b/bog.el @@ -316,14 +316,15 @@ word constituents." (defun bog-citekey-from-tree () "Retrieve citekey from first parent heading associated with citekey." - (org-with-wide-buffer - (let (maybe-citekey) - (while (and (not (setq maybe-citekey (bog-citekey-from-heading))) - ;; This isn't actually safe in Org mode <= 8.2.10. - ;; Fixed in Org mode commit - ;; 9ba9f916e87297d863c197cb87199adbb39da894. - (ignore-errors (org-up-heading-safe)))) - maybe-citekey))) + (when (derived-mode-p 'org-mode) + (org-with-wide-buffer + (let (maybe-citekey) + (while (and (not (setq maybe-citekey (bog-citekey-from-heading))) + ;; This isn't actually safe in Org mode <= 8.2.10. + ;; Fixed in Org mode commit + ;; 9ba9f916e87297d863c197cb87199adbb39da894. + (ignore-errors (org-up-heading-safe)))) + maybe-citekey)))) (defun bog-citekey-from-heading () "Retrieve citekey from current heading title or property." @@ -332,15 +333,17 @@ word constituents." (defun bog-citekey-from-heading-title () "Retrieve citekey from heading title." - (unless (org-before-first-heading-p) - (let ((heading (org-no-properties (org-get-heading t t)))) - (and (bog-citekey-p heading) - heading)))) + (when (derived-mode-p 'org-mode) + (unless (org-before-first-heading-p) + (let ((heading (org-no-properties (org-get-heading t t)))) + (and (bog-citekey-p heading) + heading))))) (defun bog-citekey-from-property () "Retrieve citekey from `bog-citekey-property'." - (let ((ck (org-entry-get (point) bog-citekey-property))) - (and ck (bog-citekey-p ck) ck))) + (when (derived-mode-p 'org-mode) + (let ((ck (org-entry-get (point) bog-citekey-property))) + (and ck (bog-citekey-p ck) ck)))) (defun bog-citekey-p (text) "Return non-nil if TEXT matches `bog-citekey-format'." -- cgit v1.2.3