From 13c78a590001d7966a63c2ac35ce803a7a54fc26 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Thu, 20 May 2021 15:44:27 +0200 Subject: [PATCH] footnote: Allow new footnotes in empty cells * lisp/org-footnote.el (org-footnote--allow-reference-p): allow inserting new footnotes in empty cells. * testing/lisp/test-org-footnote.el (test-org-footnote/new): Add tests. Reported-by: Uwe Brauer --- lisp/org-footnote.el | 4 ++++ testing/lisp/test-org-footnote.el | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index 676966396..fdf4b3c9d 100644 --- a/lisp/org-footnote.el +++ b/lisp/org-footnote.el @@ -288,6 +288,10 @@ otherwise." ((= (point) (org-element-property :begin context))) ;; Within recursive object too, but not in a link. ((eq type 'link) nil) + ((eq type 'table-cell) + ;; :contents-begin is not reliable on empty cells, so special + ;; case it. + (<= (point) (org-element-property :contents-end context))) ((let ((cbeg (org-element-property :contents-begin context)) (cend (org-element-property :contents-end context))) (and cbeg (>= (point) cbeg) (<= (point) cend)))))))) diff --git a/testing/lisp/test-org-footnote.el b/testing/lisp/test-org-footnote.el index 50a430785..5525626d2 100644 --- a/testing/lisp/test-org-footnote.el +++ b/testing/lisp/test-org-footnote.el @@ -90,6 +90,25 @@ (org-test-with-temp-text " *bold*" (let ((org-footnote-auto-label t)) (org-footnote-new)) (buffer-string)))) + ;; Arrow new footnotes in empty cells. + (should + (string-match-p + " \\[fn:1\\]" + (org-test-with-temp-text "| |" + (let ((org-footnote-auto-label t)) (org-footnote-new)) + (buffer-string)))) + (should + (string-match-p + "|\\[fn:1\\]" + (org-test-with-temp-text "| |" + (let ((org-footnote-auto-label t)) (org-footnote-new)) + (buffer-string)))) + (should + (string-match-p + " \\[fn:1\\]" + (org-test-with-temp-text "| |" + (let ((org-footnote-auto-label t)) (org-footnote-new)) + (buffer-string)))) ;; When creating a new footnote, move to its definition. (should (string=