From 10d2868c587360d3d17d7ef5fbf11ca036bb2f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20A=2E=20Aranda=20Guti=C3=A9rrez?= Date: Mon, 5 Feb 2024 07:30:00 +0100 Subject: [PATCH] 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. --- doc/org-manual.org | 1 + etc/ORG-NEWS | 8 ++++++++ lisp/org-footnote.el | 21 ++++++++++++--------- lisp/org.el | 1 + testing/lisp/test-org-footnote.el | 12 ++++++++++++ 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/doc/org-manual.org b/doc/org-manual.org index 06869fd97..2eb991a4a 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -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 diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 9847083b3..965872d23 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -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~ diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index c9584c3b8..16ab7f279 100644 --- a/lisp/org-footnote.el +++ b/lisp/org-footnote.el @@ -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)) diff --git a/lisp/org.el b/lisp/org.el index fe8c12734..a728f485d 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -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) diff --git a/testing/lisp/test-org-footnote.el b/testing/lisp/test-org-footnote.el index 1ab58a989..90a917c6a 100644 --- a/testing/lisp/test-org-footnote.el +++ b/testing/lisp/test-org-footnote.el @@ -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" + (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.