Browse Source

oc: Allow citations at footnote definition start

* lisp/oc.el (org-cite--allowed-p): Allow citations at footnote
definition start.
* testing/lisp/test-oc.el (test-org-cite/insert-capability): Add tests.
Nicolas Goaziou 3 years ago
parent
commit
b07c312f28
2 changed files with 48 additions and 1 deletions
  1. 5 1
      lisp/oc.el
  2. 43 0
      testing/lisp/test-oc.el

+ 5 - 1
lisp/oc.el

@@ -1436,7 +1436,11 @@ CONTEXT is the element or object at point, as returned by `org-element-context'.
 			  (skip-chars-backward " \r\t\n")
 			  (if (eq (org-element-class context) 'object) (point)
 			    (line-beginning-position 2)))))
-     ;; At the start of a list item is fine, as long as the bullet is unaffected.
+     ;; At the beginning of a footnote definition, right after the
+     ;; label, is OK.
+     ((eq type 'footnote-definition) (looking-at (rx space)))
+     ;; At the start of a list item is fine, as long as the bullet is
+     ;; unaffected.
      ((eq type 'item)
       (> (point) (+ (org-element-property :begin context)
                     (current-indentation)

+ 43 - 0
testing/lisp/test-oc.el

@@ -1792,6 +1792,49 @@ arguments.  Replace citation with \"@\" character in the output."
        (org-cite-register-processor 'foo
          :insert (lambda (_ _) (throw :exit 'success)))
        (call-interactively #'org-cite-insert))))
+  ;; Allow inserting citations at the beginning of a footnote
+  ;; definition, right after the label.
+  (should
+   (eq 'success
+       (catch :exit
+         (org-test-with-temp-text "[fn:1]<point>"
+           (let ((org-cite--processors nil)
+                 (org-cite-insert-processor 'foo))
+             (org-cite-register-processor 'foo
+               :insert (lambda (_ _) (throw :exit 'success)))
+             (call-interactively #'org-cite-insert))))))
+  (should
+   (eq 'success
+       (catch :exit
+         (org-test-with-temp-text "[fn:1] <point>"
+           (let ((org-cite--processors nil)
+                 (org-cite-insert-processor 'foo))
+             (org-cite-register-processor 'foo
+               :insert (lambda (_ _) (throw :exit 'success)))
+             (call-interactively #'org-cite-insert))))))
+  (should
+   (eq 'success
+       (catch :exit
+         (org-test-with-temp-text "[fn:1]<point>\nParagraph"
+           (let ((org-cite--processors nil)
+                 (org-cite-insert-processor 'foo))
+             (org-cite-register-processor 'foo
+               :insert (lambda (_ _) (throw :exit 'success)))
+             (call-interactively #'org-cite-insert))))))
+  (should-error
+   (org-test-with-temp-text "[fn:1<point>]"
+     (let ((org-cite--processors nil)
+           (org-cite-insert-processor 'foo))
+       (org-cite-register-processor 'foo
+         :insert (lambda (_ _) (throw :exit 'success)))
+       (call-interactively #'org-cite-insert))))
+  (should-error
+   (org-test-with-temp-text "<point>[fn:1]"
+     (let ((org-cite--processors nil)
+           (org-cite-insert-processor 'foo))
+       (org-cite-register-processor 'foo
+         :insert (lambda (_ _) (throw :exit 'success)))
+       (call-interactively #'org-cite-insert))))
   ;; Allow inserting citations in captions.
   (should
    (eq 'success