diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5bbd422d5..696d29f37 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,8 @@ 2009-07-01 Carsten Dominik + * 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'. diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index cf0b38e25..3900465e0 100644 --- a/lisp/org-footnote.el +++ b/lisp/org-footnote.el @@ -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