New option to create unique, random labels for footnotes.

* lisp/org-footnote.el: (org-footnote-auto-label): New random option
* lisp/org-footnote.el: (org-footnote-new): Create random footnote
  labels with unique ids
This commit is contained in:
Matt Lundin 2011-03-11 18:50:59 +00:00 committed by Bastien Guerry
parent 2444744985
commit 743bb4e14f
1 changed files with 12 additions and 4 deletions

View File

@ -113,12 +113,14 @@ t create unique labels of the form [fn:1], [fn:2], ...
confirm like t, but let the user edit the created value. In particular, confirm like t, but let the user edit the created value. In particular,
the label can be removed from the minibuffer, to create the label can be removed from the minibuffer, to create
an anonymous footnote. an anonymous footnote.
random Automatically generate a unique, random label.
plain Automatically create plain number labels like [1]" plain Automatically create plain number labels like [1]"
:group 'org-footnote :group 'org-footnote
:type '(choice :type '(choice
(const :tag "Prompt for label" nil) (const :tag "Prompt for label" nil)
(const :tag "Create automatic [fn:N]" t) (const :tag "Create automatic [fn:N]" t)
(const :tag "Offer automatic [fn:N] for editing" confirm) (const :tag "Offer automatic [fn:N] for editing" confirm)
(const :tag "Create a random label" random)
(const :tag "Create automatic [N]" plain))) (const :tag "Create automatic [N]" plain)))
(defcustom org-footnote-auto-adjust nil (defcustom org-footnote-auto-adjust nil
@ -253,16 +255,22 @@ This command prompts for a label. If this is a label referencing an
existing label, only insert the label. If the footnote label is empty existing label, only insert the label. If the footnote label is empty
or new, let the user edit the definition of the footnote." or new, let the user edit the definition of the footnote."
(interactive) (interactive)
(let* ((labels (org-footnote-all-labels)) (let* ((labels (and (not (equal org-footnote-auto-label 'random))
(org-footnote-all-labels)))
(propose (org-footnote-unique-label labels)) (propose (org-footnote-unique-label labels))
(label (label
(if (member org-footnote-auto-label '(t plain)) (cond
propose ((member org-footnote-auto-label '(t plain))
propose)
((equal org-footnote-auto-label 'random)
(require 'org-id)
(substring (org-id-uuid) 0 8))
(t
(completing-read (completing-read
"Label (leave empty for anonymous): " "Label (leave empty for anonymous): "
(mapcar 'list labels) nil nil (mapcar 'list labels) nil nil
(if (eq org-footnote-auto-label 'confirm) propose nil) (if (eq org-footnote-auto-label 'confirm) propose nil)
'org-footnote-label-history)))) 'org-footnote-label-history)))))
(setq label (org-footnote-normalize-label label)) (setq label (org-footnote-normalize-label label))
(cond (cond
((equal label "") ((equal label "")