瀏覽代碼

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.
Nicolas Goaziou 14 年之前
父節點
當前提交
1eac25a438
共有 2 個文件被更改,包括 35 次插入16 次删除
  1. 24 5
      lisp/org-footnote.el
  2. 11 11
      lisp/org.el

+ 24 - 5
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."

+ 11 - 11
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