Prechádzať zdrojové kódy

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.
Nicolas Goaziou 10 rokov pred
rodič
commit
c8e3873a5e
1 zmenil súbory, kde vykonal 14 pridanie a 2 odobranie
  1. 14 2
      lisp/org-footnote.el

+ 14 - 2
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)))))