From 5f6e199143d8b66077c41202ff1b0d5f7064a50b Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Wed, 6 Oct 2021 14:34:14 +0200 Subject: [PATCH 1/2] footnote: Allow footnotes at footnote definition start * lisp/org-footnote.el (org-footnote--allow-reference-p): Allow footnotes at footnote definition start, right after label. * testing/lisp/test-org-footnote.el (test-org-footnote/new): Add tests. --- lisp/org-footnote.el | 3 +++ testing/lisp/test-org-footnote.el | 29 ++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index c8c4dae80..fcd85228b 100644 --- a/lisp/org-footnote.el +++ b/lisp/org-footnote.el @@ -282,6 +282,9 @@ otherwise." (skip-chars-backward " \r\t\n") (if (eq (org-element-class context) 'object) (point) (1+ (line-beginning-position 2)))))) + ;; At the beginning of a footnote definition, right after the + ;; label, is OK. + ((eq type 'footnote-definition) (looking-at (rx (or space buffer-end)))) ;; Other elements are invalid. ((eq (org-element-class context) 'element) nil) ;; Just before object is fine. diff --git a/testing/lisp/test-org-footnote.el b/testing/lisp/test-org-footnote.el index 6d8ba2f44..8751dc842 100644 --- a/testing/lisp/test-org-footnote.el +++ b/testing/lisp/test-org-footnote.el @@ -90,7 +90,34 @@ (org-test-with-temp-text " *bold*" (let ((org-footnote-auto-label t)) (org-footnote-new)) (buffer-string)))) - ;; Arrow new footnotes in table cells. + ;; Allow new footnotes at the start of a footnote definition. + (should + (string-match-p + "\\[fn:1\\]\\[fn:2\\]" + (org-test-with-temp-text "[fn:1]" + (let ((org-footnote-auto-label t)) (org-footnote-new)) + (buffer-string)))) + (should + (string-match-p + "\\[fn:1\\] \\[fn:2\\]" + (org-test-with-temp-text "[fn:1] " + (let ((org-footnote-auto-label t)) (org-footnote-new)) + (buffer-string)))) + (should + (string-match-p + "\\[fn:1\\]\\[fn:2\\]" + (org-test-with-temp-text "[fn:1] \nParagraph" + (let ((org-footnote-auto-label t)) (org-footnote-new)) + (buffer-string)))) + (should-error + (org-test-with-temp-text "[fn:1]" + (let ((org-footnote-auto-label t)) (org-footnote-new)) + (buffer-string))) + (should-error + (org-test-with-temp-text "[fn:1]" + (let ((org-footnote-auto-label t)) (org-footnote-new)) + (buffer-string))) + ;; Allow new footnotes in table cells. (should (string-match-p " \\[fn:1\\]" From 94b410b32c3b2b3a047f08f67af0dc9915cb0e64 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Wed, 6 Oct 2021 14:41:50 +0200 Subject: [PATCH 2/2] footnote: Improve last commit * lisp/org-footnote.el (org-footnote--allow-reference-p): Improve last commit. --- lisp/org-footnote.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index fcd85228b..fcc7579ba 100644 --- a/lisp/org-footnote.el +++ b/lisp/org-footnote.el @@ -281,10 +281,10 @@ otherwise." (save-excursion (goto-char (org-element-property :end context)) (skip-chars-backward " \r\t\n") (if (eq (org-element-class context) 'object) (point) - (1+ (line-beginning-position 2)))))) + (line-beginning-position 2))))) ;; At the beginning of a footnote definition, right after the ;; label, is OK. - ((eq type 'footnote-definition) (looking-at (rx (or space buffer-end)))) + ((eq type 'footnote-definition) (looking-at (rx space))) ;; Other elements are invalid. ((eq (org-element-class context) 'element) nil) ;; Just before object is fine.