org-footnote: strenghten footnotes regexp

* lisp/org-footnote.el (org-footnote-re): avoid matching inactive
  time-stamps or check-box cookies.
(org-footnote-next-reference-or-definition): adapt to the new regexp.
This commit is contained in:
Nicolas Goaziou 2011-06-29 01:14:13 +02:00
parent 56b558d15a
commit 66537c520c
1 changed files with 15 additions and 6 deletions

View File

@ -53,15 +53,18 @@
(defvar message-signature-separator) ;; defined in message.el (defvar message-signature-separator) ;; defined in message.el
(defconst org-footnote-re (defconst org-footnote-re
;; Footnotes ain't closed in this regexp, as their definition might ;; Only [1]-like footnotes are closed in this regexp, as footnotes
;; contain square brackets \(i.e. links\). ;; from other types might contain square brackets (i.e. links) in
;; their definition.
;; ;;
;; `org-re' is used for regexp compatibility with XEmacs. ;; `org-re' is used for regexp compatibility with XEmacs.
(org-re (concat "\\[\\(?:" (org-re (concat "\\[\\(?:"
;; Match inline footnotes. ;; Match inline footnotes.
"fn:\\([-_[:word:]]+\\)?:\\|" "fn:\\([-_[:word:]]+\\)?:\\|"
;; Match other footnotes. ;; Match other footnotes.
"\\([0-9]+\\)\\|\\(fn:[-_[:word:]]+\\)\\)")) "\\(?:\\([0-9]+\\)\\]\\)\\|"
"\\(fn:[-_[:word:]]+\\)"
"\\)"))
"Regular expression for matching footnotes.") "Regular expression for matching footnotes.")
(defconst org-footnote-definition-re (defconst org-footnote-definition-re
@ -244,13 +247,19 @@ If no footnote is found, return nil."
(while t (while t
(unless (re-search-forward org-footnote-re limit t) (unless (re-search-forward org-footnote-re limit t)
(throw 'exit nil)) (throw 'exit nil))
;; Beware: with [1]-like footnotes point will be just after
;; the closing square bracket.
(backward-char)
(cond (cond
((setq ref (org-footnote-at-reference-p)) ((setq ref (org-footnote-at-reference-p))
(throw 'exit ref)) (throw 'exit ref))
;; Definition: also grab the last square bracket, not matched ;; Definition: also grab the last square bracket, only
;; in `org-footnote-re' ;; matched in `org-footnote-re' for [1]-like footnotes.
((= (point-at-bol) (match-beginning 0)) ((= (point-at-bol) (match-beginning 0))
(throw 'exit (list nil (match-beginning 0) (1+ (match-end 0)))))))))) (let ((end (match-end 0)))
(throw 'exit
(list nil (match-beginning 0)
(if (eq (char-before end) 93) end (1+ end)))))))))))
(defun org-footnote-get-definition (label) (defun org-footnote-get-definition (label)
"Return label, boundaries and definition of the footnote LABEL." "Return label, boundaries and definition of the footnote LABEL."