From 7584200bb88b7995b87f065320886b0813de22dd Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sun, 12 Apr 2015 00:25:33 +0200 Subject: [PATCH] org-footnote: Allow new footnotes in headlines * lisp/org-footnote.el (org-footnote--allow-reference-p): Allow new footnotes in headlines. * testing/lisp/test-org-footnote.el (test-org-footnote/new): Add test. Reported-by: Thomas S. Dye --- lisp/org-footnote.el | 12 ++++++++++++ testing/lisp/test-org-footnote.el | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el index 7bcaa62c5..2b04e00c6 100644 --- a/lisp/org-footnote.el +++ b/lisp/org-footnote.el @@ -467,6 +467,18 @@ buffer." ((eq type 'verse-block) (and (>= (point) (org-element-property :contents-begin context)) (< (point) (org-element-property :contents-end context)))) + ;; In an headline or inlinetask, point must be either on the + ;; heading itself or on the blank lines below. + ((memq type '(headline inlinetask)) + (or (not (org-at-heading-p)) + (and (save-excursion (beginning-of-line) + (and (let ((case-fold-search t)) + (not (looking-at "\\*+ END[ \t]*$"))) + (looking-at org-complex-heading-regexp))) + (match-beginning 4) + (>= (point) (match-beginning 4)) + (or (not (match-beginning 5)) + (< (point) (match-beginning 5)))))) ;; White spaces after an object or blank lines after an element ;; are OK. ((>= (point) diff --git a/testing/lisp/test-org-footnote.el b/testing/lisp/test-org-footnote.el index e73dbf8d5..1a10faa21 100644 --- a/testing/lisp/test-org-footnote.el +++ b/testing/lisp/test-org-footnote.el @@ -67,6 +67,14 @@ (org-test-with-temp-text " " (let ((org-footnote-auto-label t)) (org-footnote-new)) (buffer-string)))) + ;; In an headline or inlinetask, point must be either on the + ;; heading itself or on the blank lines below. + (should (org-test-with-temp-text "* H" (org-footnote-new) t)) + (should + (org-test-with-temp-text "* H\n \nParagraph" (org-footnote-new) t)) + (should-error (org-test-with-temp-text "* H" (org-footnote-new) t)) + (should-error + (org-test-with-temp-text "* H :tag:" (org-footnote-new) t)) ;; Allow new footnotes within recursive objects, but not in links. (should (string-match-p -- 2.11.4.GIT