Function: org-footnote-next-reference-or-definition
org-footnote-next-reference-or-definition is a byte-compiled function
defined in org-footnote.el.gz.
Signature
(org-footnote-next-reference-or-definition LIMIT)
Documentation
Move point to next footnote reference or definition.
LIMIT is the buffer position bounding the search.
Return value is a list like those provided by
org-footnote-at-reference-p or org-footnote-at-definition-p.
If no footnote is found, return nil.
This function is meant to be used for fontification only.
Source Code
;; Defined in /usr/src/emacs/lisp/org/org-footnote.el.gz
(defun org-footnote-next-reference-or-definition (limit)
"Move point to next footnote reference or definition.
LIMIT is the buffer position bounding the search.
Return value is a list like those provided by
`org-footnote-at-reference-p' or `org-footnote-at-definition-p'.
If no footnote is found, return nil.
This function is meant to be used for fontification only."
(let ((origin (point)))
(catch 'exit
(while t
(unless (re-search-forward org-footnote-re limit t)
(goto-char origin)
(throw 'exit nil))
;; Beware: with non-inline footnotes point will be just after
;; the closing square bracket.
(backward-char)
(cond
((and (/= (match-beginning 0) (line-beginning-position))
(let* ((beg (match-beginning 0))
(label (match-string-no-properties 1))
;; Inline footnotes don't end at (match-end 0)
;; as `org-footnote-re' stops just after the
;; second colon. Find the real ending with
;; `scan-sexps', so Org doesn't get fooled by
;; unrelated closing square brackets.
(end (ignore-errors (scan-sexps beg 1))))
(and end
;; Verify match isn't a part of a link.
(not (save-excursion
(goto-char beg)
(let ((linkp
(save-match-data
(org-in-regexp org-link-bracket-re))))
(and linkp (< (point) (cdr linkp))))))
;; Verify point doesn't belong to a LaTeX macro.
(not (org-inside-latex-macro-p))
(throw 'exit
(list label beg end
;; Definition: ensure this is an
;; inline footnote first.
(and (match-end 2)
(org-trim
(buffer-substring-no-properties
(match-end 0) (1- end))))))))))
;; Definition: also grab the last square bracket, matched in
;; `org-footnote-re' for non-inline footnotes.
((and (save-excursion
(forward-line 0)
(save-match-data (org-footnote-in-valid-context-p)))
(save-excursion
(end-of-line)
;; Footnotes definitions are separated by new
;; headlines, another footnote definition or 2 blank
;; lines.
(let ((end (match-end 0))
(lim (save-excursion
(re-search-backward
(concat org-outline-regexp-bol
"\\|^\\([ \t]*\n\\)\\{2,\\}")
nil t))))
(and (re-search-backward org-footnote-definition-re lim t)
(throw 'exit
(list nil
(match-beginning 0)
(if (eq (char-before end) ?\]) end
(1+ end)))))))))
(t nil))))))