oc: Allow inserting citations in table cells (part 2)

* lisp/oc.el (org-cite--allowed-p): Allow inserting a citation after
two or more spaces at the end of a table cell.
* testing/lisp/test-oc.el (test-org-cite/insert-capability): Add
tests.
This commit is contained in:
Nicolas Goaziou 2021-07-29 21:13:01 +02:00
parent 78c450247b
commit 7ea9099725
2 changed files with 30 additions and 1 deletions

View File

@ -1421,7 +1421,8 @@ ARG is the prefix argument received when calling `org-open-at-point', or nil."
((eq type 'table-cell)
;; :contents-begin is not reliable on empty cells, so special
;; case it.
(<= (point) (org-element-property :contents-end context)))
(<= (save-excursion (skip-chars-backward " \t") (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)))))))

View File

@ -1774,6 +1774,34 @@ arguments. Replace citation with \"@\" character in the output."
(eq 'success
(catch :exit
(org-test-with-temp-text "#+caption: <point>\n| table |"
(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 table cells.
(should
(eq 'success
(catch :exit
(org-test-with-temp-text "| <point>table |"
(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 "| table<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 "| table <point> |"
(let ((org-cite--processors nil)
(org-cite-insert-processor 'foo))
(org-cite-register-processor 'foo