Footnotes: Allow renumbering the fn:N-like footnotes

This commit adds a new action to the footnote actions:
It allows to renumber footnote marks that have the simple form
fn:N where N is a number.  After this action, numbers will start from
1 and increase through the document.
This commit is contained in:
Carsten Dominik 2009-07-01 10:37:03 +02:00
parent d3f4bf811c
commit de6b866f27
2 changed files with 24 additions and 1 deletions

View File

@ -1,5 +1,8 @@
2009-07-01 Carsten Dominik <carsten.dominik@gmail.com>
* org-footnote.el (org-footnote-renumber-fn:N): New command.
(org-footnote-action): Offer renumbering.
* org.el (org-cycle): Honor the `integrate' value of
org-cycle-include-plain-lists'.

View File

@ -296,11 +296,13 @@ With prefix arg SPECIAL, offer additional commands in a menu."
(let (tmp c)
(cond
(special
(message "Footnotes: [s]ort | convert to [n]umeric | [d]elete")
(message "Footnotes: [s]ort | [r]enumber fn:N | convert to [n]umeric | [d]elete")
(setq c (read-char-exclusive))
(cond
((equal c ?s)
(org-footnote-normalize 'sort))
((equal c ?r)
(org-footnote-renumber-fn:N))
((equal c ?n)
(org-footnote-normalize))
((equal c ?d)
@ -508,6 +510,24 @@ and all references of a footnote label."
(message "%d definition(s) of and %d reference(s) of footnote %s removed"
ndef nref label))))
(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 (and (string-match "\\S-" (buffer-substring
(point-at-bol) (match-beginning 0)))
(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)
(replace-match (concat "\\1" (cdr (assq (string-to-number (match-string 2)) map)) "\\3")))))))
(provide 'org-footnote)
;; arch-tag: 1b5954df-fb5d-4da5-8709-78d944dbfc37