From 3576c0fd9f716a99db3e244d4f2df34655186829 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sun, 23 Nov 2014 19:19:16 -0500 Subject: Prefer current buffer when finding citekey heading Several functions use `org-find-exact-heading-in-directory' to find the location of a citekey heading. However, when called with a citekey at point, it is likely that the citekey is in the current file (assuming files are arranged by general topics), so first check the current buffer and, only if it isn't found there, search all Org files in `bog-notes-directory'. --- bog.el | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/bog.el b/bog.el index 48e3b16..5c10709 100644 --- a/bog.el +++ b/bog.el @@ -657,8 +657,7 @@ If the heading is found outside any current narrowing of the buffer, the narrowing is removed." (interactive "P") (let* ((citekey (bog-citekey-from-point-or-all-headings no-context)) - (marker - (org-find-exact-heading-in-directory citekey bog-notes-directory))) + (marker (bog--find-exact-heading-in-notes citekey))) (if marker (progn (switch-to-buffer (marker-buffer marker)) @@ -669,6 +668,14 @@ buffer, the narrowing is removed." (org-show-context)) (message "Heading for %s not found in notes" citekey)))) +(defun bog--find-exact-heading-in-notes (heading) + "Return the marker of HEADING in Bog notes. +If the current buffer is a Bog notes file, try to find the +heading there first." + (or (when (member (buffer-file-name) (bog-notes-files)) + (org-find-exact-headline-in-buffer heading)) + (org-find-exact-heading-in-directory heading bog-notes-directory))) + (defun bog-citekey-tree-to-indirect-buffer (&optional no-context) "Open subtree for citekey in an indirect buffer. @@ -683,8 +690,7 @@ If the citekey file prompt is slow to appear, consider enabling `bog-use-citekey-cache'." (interactive "P") (let* ((citekey (bog-citekey-from-point-or-all-headings no-context)) - (marker - (org-find-exact-heading-in-directory citekey bog-notes-directory))) + (marker (bog--find-exact-heading-in-notes citekey))) (if marker (with-current-buffer (marker-buffer marker) (save-excursion @@ -778,8 +784,7 @@ from all citekeys for headings in notes. This same prompt will be opened if locating a citekey from context fails." (interactive "P") (let* ((citekey (bog-citekey-from-point-or-all-headings no-context)) - (marker - (org-find-exact-heading-in-directory citekey bog-notes-directory))) + (marker (bog--find-exact-heading-in-notes citekey))) (if marker (with-current-buffer (marker-buffer marker) (org-with-wide-buffer -- cgit v1.2.3