summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS6
-rw-r--r--bog.el25
2 files changed, 25 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index 7f77346..dfe8d3b 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,12 @@
custom Bog commands for the Org agenda have been removed because this
functionality is now available through =bog-commander=.
+** Other changes
+
+- =bog-goto-citekey-heading-in-buffer= and
+ =bog-goto-citekey-heading-in-notes= will now widen the buffer is the
+ heading is outside of the narrowed region.
+
* v0.6.0
** New features
diff --git a/bog.el b/bog.el
index 7ca3ec5..53d86a0 100644
--- a/bog.el
+++ b/bog.el
@@ -605,15 +605,21 @@ The citekey will be taken from the text under point if it matches
With prefix argument NO-CONTEXT, a prompt will open to select
from all citekeys for headings in the current buffer. This same
-prompt will be opened if locating a citekey from context fails."
+prompt will be opened if locating a citekey from context fails.
+
+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-buffer-headings no-context))
(pos (org-find-exact-headline-in-buffer citekey nil t)))
(if pos
(progn
- (org-mark-ring-push)
- (goto-char pos)
- (org-show-context))
+ (when (or (< pos (point-min))
+ (> pos (point-max)))
+ (widen))
+ (org-mark-ring-push)
+ (goto-char pos)
+ (org-show-context))
(message "Heading for %s not found in buffer" citekey))))
(defun bog-goto-citekey-heading-in-notes (&optional no-context)
@@ -626,7 +632,10 @@ The citekey will be taken from the text under point if it matches
With prefix argument NO-CONTEXT, a prompt will open to select
from all citekeys for headings in notes. This same prompt will be
-opened if locating a citekey from context fails."
+opened if locating a citekey from context fails.
+
+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
@@ -634,7 +643,11 @@ opened if locating a citekey from context fails."
(if marker
(progn
(switch-to-buffer (marker-buffer marker))
- (goto-char (marker-position marker))
+ (let ((pos (marker-position marker)))
+ (when (or (< pos (point-min))
+ (> pos (point-max)))
+ (widen))
+ (goto-char pos))
(org-show-context))
(message "Heading for %s not found in notes" citekey))))