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.
This commit is contained in:
Nicolas Goaziou 2011-09-29 22:34:15 +02:00
parent 2e2bd083da
commit 1effad02be
1 changed files with 13 additions and 13 deletions

View File

@ -888,19 +888,19 @@ If LABEL is non-nil, delete that footnote instead."
(defun org-footnote-renumber-fn:N () (defun org-footnote-renumber-fn:N ()
"Renumber the simple footnotes like fn:17 into a sequence in the document." "Renumber the simple footnotes like fn:17 into a sequence in the document."
(interactive) (interactive)
(let (map i (n 0)) (let (map (n 0))
(save-excursion (org-with-wide-buffer
(save-restriction (goto-char (point-min))
(widen) (while (re-search-forward "\\[fn:\\([0-9]+\\)[]:]" nil t)
(goto-char (point-min)) (goto-char (match-beginning 0))
(while (re-search-forward "\\[fn:\\([0-9]+\\)[]:]" nil t) ;; Ensure match is a footnote reference or definition.
(setq i (string-to-number (match-string 1))) (when (or (and (bolp) (save-match-data (org-footnote-at-definition-p)))
(when (not (assq i map)) (save-match-data (org-footnote-at-reference-p)))
(push (cons i (number-to-string (incf n))) map))) (let ((new-val (or (cdr (assoc (match-string 1) map))
(goto-char (point-min)) (number-to-string (incf n)))))
(while (re-search-forward "\\(\\[fn:\\)\\([0-9]+\\)\\([]:]\\)" nil t) (unless (assoc (match-string 1) map)
(setq i (cdr (assq (string-to-number (match-string 2)) map))) (push (cons (match-string 1) new-val) map))
(replace-match (concat "\\1" i "\\3"))))))) (replace-match new-val nil nil nil 1)))))))
(defun org-footnote-auto-adjust-maybe () (defun org-footnote-auto-adjust-maybe ()
"Renumber and/or sort footnotes according to user settings." "Renumber and/or sort footnotes according to user settings."