From 1c2a78d0d3b63d09087d6a3e4b8788b2aee2d188 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Tue, 6 May 2014 23:53:56 -0400 Subject: Widen if needed in goto-heading functions Widen the buffer if the heading is outside the currently narrowed region. --- NEWS | 6 ++++++ bog.el | 25 +++++++++++++++++++------ 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)))) -- cgit v1.2.3