From 1eac25a438b821ed71df31a6e7d551ef8fa5fb35 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Mon, 2 May 2011 11:34:06 +0200 Subject: [PATCH] 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. --- lisp/org-footnote.el | 29 ++++++++++++++++++++++++----- lisp/org.el | 22 +++++++++++----------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index 6e06dc395..ae74eaf56 100644 --- a/lisp/org-footnote.el +++ b/lisp/org-footnote.el @@ -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." diff --git a/lisp/org.el b/lisp/org.el index 5e09119a4..827008dc7 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -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