Selaa lähdekoodia

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 <tsd@tsdye.com>
<http://permalink.gmane.org/gmane.emacs.orgmode/96843>
Nicolas Goaziou 10 vuotta sitten
vanhempi
commit
7584200bb8
2 muutettua tiedostoa jossa 20 lisäystä ja 0 poistoa
  1. 12 0
      lisp/org-footnote.el
  2. 8 0
      testing/lisp/test-org-footnote.el

+ 12 - 0
lisp/org-footnote.el

@@ -467,6 +467,18 @@ buffer."
        ((eq type 'verse-block)
        ((eq type 'verse-block)
 	(and (>= (point) (org-element-property :contents-begin context))
 	(and (>= (point) (org-element-property :contents-begin context))
 	     (< (point) (org-element-property :contents-end 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
        ;; White spaces after an object or blank lines after an element
        ;; are OK.
        ;; are OK.
        ((>= (point)
        ((>= (point)

+ 8 - 0
testing/lisp/test-org-footnote.el

@@ -67,6 +67,14 @@
     (org-test-with-temp-text " <point>"
     (org-test-with-temp-text " <point>"
       (let ((org-footnote-auto-label t)) (org-footnote-new))
       (let ((org-footnote-auto-label t)) (org-footnote-new))
       (buffer-string))))
       (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<point>" (org-footnote-new) t))
+  (should
+   (org-test-with-temp-text "* H\n <point>\nParagraph" (org-footnote-new) t))
+  (should-error (org-test-with-temp-text "*<point> H" (org-footnote-new) t))
+  (should-error
+   (org-test-with-temp-text "* H <point>:tag:" (org-footnote-new) t))
   ;; Allow new footnotes within recursive objects, but not in links.
   ;; Allow new footnotes within recursive objects, but not in links.
   (should
   (should
    (string-match-p
    (string-match-p