diff options
author | Nicolas Goaziou <n.goaziou@gmail.com> | 2011-09-29 22:34:15 +0200 |
---|---|---|
committer | Nicolas Goaziou <n.goaziou@gmail.com> | 2011-09-29 22:34:15 +0200 |
commit | 1effad02beb79b2fb26506bd4142cb74bbe3a906 (patch) | |
tree | f6397c3b3eec31d76a83816a50ad22e0b1b4bd63 | |
parent | 2e2bd083dac993b1f7a2ae09029602fe683d367e (diff) | |
download | org-mode-1effad02beb79b2fb26506bd4142cb74bbe3a906.tar.gz |
org-footnote: Only renumber real footnotes references or definitions
* lisp/org-footnote.el (org-footnote-renumber-fn:N): Verify point is
at a real footnote reference or definition before renumbering it.
-rw-r--r-- | lisp/org-footnote.el | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index c219051..afb7b47 100644 --- a/lisp/org-footnote.el +++ b/lisp/org-footnote.el @@ -888,19 +888,19 @@ If LABEL is non-nil, delete that footnote instead." (defun org-footnote-renumber-fn:N () "Renumber the simple footnotes like fn:17 into a sequence in the document." (interactive) - (let (map i (n 0)) - (save-excursion - (save-restriction - (widen) - (goto-char (point-min)) - (while (re-search-forward "\\[fn:\\([0-9]+\\)[]:]" nil t) - (setq i (string-to-number (match-string 1))) - (when (not (assq i map)) - (push (cons i (number-to-string (incf n))) map))) - (goto-char (point-min)) - (while (re-search-forward "\\(\\[fn:\\)\\([0-9]+\\)\\([]:]\\)" nil t) - (setq i (cdr (assq (string-to-number (match-string 2)) map))) - (replace-match (concat "\\1" i "\\3"))))))) + (let (map (n 0)) + (org-with-wide-buffer + (goto-char (point-min)) + (while (re-search-forward "\\[fn:\\([0-9]+\\)[]:]" nil t) + (goto-char (match-beginning 0)) + ;; Ensure match is a footnote reference or definition. + (when (or (and (bolp) (save-match-data (org-footnote-at-definition-p))) + (save-match-data (org-footnote-at-reference-p))) + (let ((new-val (or (cdr (assoc (match-string 1) map)) + (number-to-string (incf n))))) + (unless (assoc (match-string 1) map) + (push (cons (match-string 1) new-val) map)) + (replace-match new-val nil nil nil 1))))))) (defun org-footnote-auto-adjust-maybe () "Renumber and/or sort footnotes according to user settings." |