1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-26 07:33:39 +00:00

org-footnote-new: Add an option to create new anonymous labels

* lisp/org-footnote.el (org-footnote-new, org-footnote-auto-label):
Add symbol `anonymous' to `org-footnote-auto-label'.  With this,
anonymous footnotes will be created.  This is sometimes useful in long
texts.  Mimics \footnote{} in LaTeX.  Modify `org-footnote-new' to
generate anonymous footnotes directly.

* lisp/org.el (org-startup-options): Add `fnanon' to startup options.

* testing/lisp/test-org-footnote.el (test-org-footnote/new-anon): Add
a test for creation of anonymous footnotes.

* etc/ORG-NEWS:
(~org-footnote-new~ can be configured to create anonymous footnotes):
Announce new anonymous footnote support.

* doc/org-manual.org (Summary of In-Buffer Settings): Document
"fnanon" startup option.
This commit is contained in:
Pedro A. Aranda Gutiérrez 2024-02-05 07:30:00 +01:00 committed by Ihor Radchenko
parent 7f5e085cad
commit 10d2868c58
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
5 changed files with 34 additions and 9 deletions

View File

@ -20381,6 +20381,7 @@ changes.
| =fnconfirm= | Offer automatic label for editing or confirmation. |
| =fnadjust= | Automatically renumber and sort footnotes. |
| =nofnadjust= | Do not renumber and sort automatically. |
| =fnanon= | Create anonymous footnotes with ~org-footnote-new~. |
#+vindex: org-hide-block-startup
#+vindex: org-hide-drawer-startup

View File

@ -917,6 +917,14 @@ Completion is enabled for links to man pages added using ~org-insert-link~:
=C-c C-l man RET emacscl TAB= to get =emacsclient=. Of course, the ~ol-man~
library should be loaded first.
*** ~org-footnote-new~ can be configured to create anonymous footnotes
When ~org-footnote-auto-label~ is set to ~'anonymous~, create
anonymous footnotes automatically with ~org-footnote-new~.
The same can be done via startup options:
: #+STARTUP: fnanon
** New functions and changes in function arguments
*** New API functions to store data within ~org-element-cache~

View File

@ -137,6 +137,7 @@ Possible values are:
nil Prompt the user for each label.
t Create unique labels of the form [fn:1], [fn:2], etc.
anonymous Create anonymous footnotes
confirm Like t, but let the user edit the created value.
The label can be removed from the minibuffer to create
an anonymous footnote.
@ -146,6 +147,7 @@ random Automatically generate a unique, random label."
(const :tag "Prompt for label" nil)
(const :tag "Create automatic [fn:N]" t)
(const :tag "Offer automatic [fn:N] for editing" confirm)
(const :tag "Create anoymous [fn::]" anonymous)
(const :tag "Create a random label" random))
:safe #'symbolp)
@ -666,15 +668,16 @@ or new, let the user edit the definition of the footnote."
(user-error "Cannot insert a footnote here"))
(let* ((all (org-footnote-all-labels))
(label
(if (eq org-footnote-auto-label 'random)
(format "%x" (abs (random)))
(org-footnote-normalize-label
(let ((propose (org-footnote-unique-label all)))
(if (eq org-footnote-auto-label t) propose
(completing-read
"Label (leave empty for anonymous): "
(mapcar #'list all) nil nil
(and (eq org-footnote-auto-label 'confirm) propose))))))))
(unless (eq org-footnote-auto-label 'anonymous)
(if (eq org-footnote-auto-label 'random)
(format "%x" (abs (random)))
(org-footnote-normalize-label
(let ((propose (org-footnote-unique-label all)))
(if (eq org-footnote-auto-label t) propose
(completing-read
"Label (leave empty for anonymous): "
(mapcar #'list all) nil nil
(and (eq org-footnote-auto-label 'confirm) propose)))))))))
(cond ((not label)
(insert "[fn::]")
(backward-char 1))

View File

@ -4125,6 +4125,7 @@ After a match, the following groups carry important information:
("fnplain" org-footnote-auto-label plain)
("fnadjust" org-footnote-auto-adjust t)
("nofnadjust" org-footnote-auto-adjust nil)
("fnanon" org-footnote-auto-label anonymous)
("constcgs" constants-unit-system cgs)
("constSI" constants-unit-system SI)
("noptag" org-tag-persistent-alist nil)

View File

@ -21,6 +21,18 @@
(require 'org-footnote)
(ert-deftest test-org-footnote/new-anon ()
"Test `org-footnote-new' specifications."
;; `org-footnote-auto-label' is `anonymous'.
(should
(string-match-p
"Test\\[fn::\\]"
(org-test-with-temp-text "Test<point>"
(let ((org-footnote-auto-label 'anonymous)
(org-footnote-section nil))
(org-footnote-new))
(buffer-string)))))
(ert-deftest test-org-footnote/new ()
"Test `org-footnote-new' specifications."
;; `org-footnote-auto-label' is t.