From de0fcdffa48da8baf57a612f2ce032d8737e6525 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Tue, 5 Jul 2011 13:28:03 +0200 Subject: [PATCH] org-footnote: distinguish footnotes from links * lisp/org-footnote.el (org-footnote-at-reference-p): verify that what looks like a footnote doesn't belong to a link. (org-footnote-next-reference-or-definition): check more strictly footnote definitions. --- lisp/org-footnote.el | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index 7e4cb0693..41ac50e7c 100644 --- a/lisp/org-footnote.el +++ b/lisp/org-footnote.el @@ -176,14 +176,20 @@ positions, and the definition, if local." ;; get fooled by unrelated closing square brackets. (end (ignore-errors (scan-sexps beg 1)))) ;; Point is really at a reference if it's located before true - ;; ending of the footnote and isn't within a LaTeX macro. About - ;; that case, some special attention should be paid. Indeed, - ;; when two footnotes are side by side, once the first one is - ;; changed into LaTeX, the second one might then be considered - ;; as an optional argument of the command. To prevent that, we - ;; have a look at the `org-protected' property of that LaTeX - ;; command. + ;; ending of the footnote and isn't within a link or a LaTeX + ;; macro. About that case, some special attention should be + ;; paid. Indeed, when two footnotes are side by side, once the + ;; first one is changed into LaTeX, the second one might then be + ;; considered as an optional argument of the command. To + ;; prevent that, we have a look at the `org-protected' property + ;; of that LaTeX command. (when (and end (< (point) end) + (not (save-excursion + (goto-char beg) + (let ((linkp + (save-match-data + (org-in-regexp org-bracket-link-regexp)))) + (and linkp (< (point) (cdr linkp)))))) (or (not (org-inside-latex-macro-p)) (and (get-text-property (1- beg) 'org-protected) (not (get-text-property beg 'org-protected))))) @@ -257,7 +263,7 @@ If no footnote is found, return nil." (throw 'exit ref)) ;; Definition: also grab the last square bracket, only ;; matched in `org-footnote-re' for [1]-like footnotes. - ((= (point-at-bol) (match-beginning 0)) + ((save-match-data (org-footnote-at-definition-p)) (let ((end (match-end 0))) (throw 'exit (list nil (match-beginning 0)