ソースを参照

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.
Nicolas Goaziou 3 年 前
コミット
7ea9099725
2 ファイル変更30 行追加1 行削除
  1. 2 1
      lisp/oc.el
  2. 28 0
      testing/lisp/test-oc.el

+ 2 - 1
lisp/oc.el

@@ -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)))))))

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

@@ -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