From c8e3873a5efc68f62304e376aef031137542f0be Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 2 May 2015 15:56:42 +0200 Subject: [PATCH] org-footnote: Offer to widen buffer when trying to move to a definiton * lisp/org-footnote.el (org-footnote-action): Offer to widen buffer if definition is outside of narrow part of buffer. --- lisp/org-footnote.el | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index 2125cb538..f4c3f7eed 100644 --- a/lisp/org-footnote.el +++ b/lisp/org-footnote.el @@ -641,8 +641,20 @@ offer additional commands in a menu." ;; definition. ((not label) (goto-char (org-element-property :contents-begin context))) - ;; A definition exists: move to it. - ((ignore-errors (org-footnote-goto-definition label))) + ;; A definition exists: move to it, if possible, or offer to + ;; widen buffer to reach it. + ((let ((definition (org-footnote-get-definition label))) + (when definition + (let ((begin (nth 1 definition))) + (catch 'do-nothing + (cond ((and (>= begin (point-min)) (<= begin (point-max)))) + ((yes-or-no-p "Definition outside scope. Widen? ") + (widen)) + (t (throw 'do-nothing nil))) + (goto-char begin) + (search-forward label) + (forward-char) + t))))) ;; No definition exists: offer to create it. ((yes-or-no-p (format "No definition for %s. Create one? " label)) (org-footnote-create-definition label))))) -- 2.11.4.GIT