0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-07-16 00:16:27 +00:00

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

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
(widen)
(goto-char (point-min)) (goto-char (point-min))
(while (re-search-forward "\\[fn:\\([0-9]+\\)[]:]" nil t) (while (re-search-forward "\\[fn:\\([0-9]+\\)[]:]" nil t)
(setq i (string-to-number (match-string 1))) (goto-char (match-beginning 0))
(when (not (assq i map)) ;; Ensure match is a footnote reference or definition.
(push (cons i (number-to-string (incf n))) map))) (when (or (and (bolp) (save-match-data (org-footnote-at-definition-p)))
(goto-char (point-min)) (save-match-data (org-footnote-at-reference-p)))
(while (re-search-forward "\\(\\[fn:\\)\\([0-9]+\\)\\([]:]\\)" nil t) (let ((new-val (or (cdr (assoc (match-string 1) map))
(setq i (cdr (assq (string-to-number (match-string 2)) map))) (number-to-string (incf n)))))
(replace-match (concat "\\1" i "\\3"))))))) (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 () (defun org-footnote-auto-adjust-maybe ()
"Renumber and/or sort footnotes according to user settings." "Renumber and/or sort footnotes according to user settings."