summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2015-05-02 15:34:31 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2015-05-02 16:45:54 +0200
commit5b49f18941129063f8743e15f991a53fa5fad444 (patch)
treeda4d54f6b4ead1984d9c9ff7b34014fe8a522ff2
parent9e52d2ed012cf25a66a9a3d1100510974219f967 (diff)
downloadorg-mode-5b49f18941129063f8743e15f991a53fa5fad444.tar.gz
org-footnote: Fix `org-footnote-get-definition'
* lisp/org-footnote.el (org-footnote-get-definition): Footnotes definitions are global, so ignore narrowing right from the start. Also skip false positives.
-rw-r--r--lisp/org-footnote.el33
1 files changed, 19 insertions, 14 deletions
diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el
index 679b47f..2125cb5 100644
--- a/lisp/org-footnote.el
+++ b/lisp/org-footnote.el
@@ -341,20 +341,25 @@ If no footnote is found, return nil."
(defun org-footnote-get-definition (label)
"Return label, boundaries and definition of the footnote LABEL."
(let* ((label (regexp-quote (org-footnote-normalize-label label)))
- (re (format "^\\[%s\\]\\|.\\[%s:" label label))
- pos)
- (save-excursion
- (save-restriction
- (when (or (re-search-forward re nil t)
- (and (goto-char (point-min))
- (re-search-forward re nil t))
- (and (progn (widen) t)
- (goto-char (point-min))
- (re-search-forward re nil t)))
- (let ((refp (org-footnote-at-reference-p)))
- (cond
- ((and (nth 3 refp) refp))
- ((org-footnote-at-definition-p)))))))))
+ (re (format "^\\[%s\\]\\|.\\[%s:" label label)))
+ (org-with-wide-buffer
+ (goto-char (point-min))
+ (catch 'found
+ (while (re-search-forward re nil t)
+ (let* ((datum (progn (backward-char) (org-element-context)))
+ (type (org-element-type datum)))
+ (when (memq type '(footnote-definition footnote-reference))
+ (throw 'found
+ (list label
+ (org-element-property :begin datum)
+ (org-element-property :end datum)
+ (replace-regexp-in-string
+ "[ \t\n]*\\'"
+ ""
+ (buffer-substring-no-properties
+ (org-element-property :contents-begin datum)
+ (org-element-property :contents-end datum))))))))
+ nil))))
(defun org-footnote-goto-definition (label)
"Move point to the definition of the footnote LABEL.