Adjust fontification of footnotes

* lisp/org-footnote.el (org-footnote-next-reference-or-definition):
  new function.
* lisp/org.el (org-activate-footnote-links): activate the whole
  footnote, but only fontify its label.
This commit is contained in:
Nicolas Goaziou 2011-05-02 11:34:06 +02:00
parent 460d093da8
commit 1eac25a438
2 changed files with 35 additions and 16 deletions

View File

@ -221,17 +221,36 @@ the buffer position bounding the search.
Return value is a list like those provided by `org-footnote-at-reference-p'.
If no footnote is found, return nil."
(save-excursion
(let* ((label-fmt (if label
(format "\\[%s[]:]" label)
(org-re "\\[[-_[:word:]]+[]:]"))))
(let* ((label-fmt (if label (format "\\[%s[]:]" label) org-footnote-re)))
(catch 'exit
(while t
(unless (funcall (if backward #'re-search-backward #'re-search-forward)
label-fmt limit t)
(throw 'exit nil))
(unless backward (backward-char))
(when (setq ref (org-footnote-at-reference-p))
(throw 'exit ref)))))))
(let ((ref (org-footnote-at-reference-p)))
(when ref (throw 'exit ref))))))))
(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."
(let* (ref)
(catch 'exit
(while t
(unless (re-search-forward org-footnote-re limit t)
(throw 'exit nil))
(cond
((setq ref (org-footnote-at-reference-p))
(throw 'exit ref))
;; Definition: also grab the last square bracket, not matched
;; in `org-footnote-re'
((= (point-at-bol) (match-beginning 0))
(throw 'exit (list nil (match-beginning 0) (1+ (match-end 0))))))))))
(defun org-footnote-get-definition (label)
"Return label, boundaries and definition of the footnote LABEL."

View File

@ -5272,20 +5272,20 @@ will be prompted for."
(defun org-activate-footnote-links (limit)
"Run through the buffer and add overlays to links."
(if (re-search-forward "\\(^\\|[^][]\\)\\(\\[\\([0-9]+\\]\\|fn:[^ \t\r\n:]+?[]:]\\)\\)"
limit t)
(progn
(org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0))
(add-text-properties (match-beginning 2) (match-end 2)
(let ((fn (org-footnote-next-reference-or-definition limit)))
(when fn
(let ((beg (nth 1 fn)) (end (nth 2 fn)))
(org-remove-flyspell-overlays-in beg end)
(add-text-properties beg end
(list 'mouse-face 'highlight
'keymap org-mouse-map
'help-echo
(if (= (point-at-bol) (match-beginning 2))
(if (= (point-at-bol) beg)
"Footnote definition"
"Footnote reference")
))
(org-rear-nonsticky-at (match-end 2))
t)))
"Footnote reference")))
(save-excursion
(goto-char beg)
(looking-at (regexp-quote (buffer-substring beg end))))))))
(defun org-activate-bracket-links (limit)
"Run through the buffer and add overlays to bracketed links."
@ -5581,7 +5581,7 @@ needs to be inserted at a specific position in the font-lock sequence.")
(if (memq 'radio lk) '(org-activate-target-links (0 'org-link t)))
(if (memq 'date lk) '(org-activate-dates (0 'org-date t)))
(if (memq 'footnote lk) '(org-activate-footnote-links
(2 'org-footnote t)))
(0 'org-footnote t)))
'("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t))
'(org-hide-wide-columns (0 nil append))
;; TODO lines