summaryrefslogtreecommitdiff
path: root/bog.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2014-11-23 19:19:16 -0500
committerKyle Meyer <kyle@kyleam.com>2014-11-23 19:19:16 -0500
commit3576c0fd9f716a99db3e244d4f2df34655186829 (patch)
tree924c409890d3e4ddfbaa46a51d7c53acc7e37ea4 /bog.el
parent3f5ae391ddcd3f371f027a97e6cbac1644883ff2 (diff)
downloadbog-3576c0fd9f716a99db3e244d4f2df34655186829.tar.gz
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'.
Diffstat (limited to 'bog.el')
-rw-r--r--bog.el17
1 files 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