diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 8d71c79d3..c1af0ae06 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1220,10 +1220,11 @@ may have been stored before." (while (re-search-forward org-table-dataline-regexp end t) (pcase (org-element-lineage (org-element-at-point) '(table) t) (`nil nil) + ((and table + (guard (eq 'table.el (org-element-property :type table)))) + nil) (table - (goto-char (org-element-property :end table)) - (skip-chars-backward " \r\t\n") - (forward-line) + (goto-char (org-element-property :contents-end table)) (narrow-to-region (org-element-property :post-affiliated table) (point)) (throw :found t)))) diff --git a/testing/lisp/test-org-capture.el b/testing/lisp/test-org-capture.el index 4b9b4456d..2e4a3b7b1 100644 --- a/testing/lisp/test-org-capture.el +++ b/testing/lisp/test-org-capture.el @@ -233,6 +233,16 @@ :immediate-finish t)))) (org-capture nil "t")) (buffer-string)))) + ;; Properly insert row with formulas. + (should + (equal "| 1 |\n| 2 |\n#+TBLFM: " + (org-test-with-temp-text-in-file "| 1 |\n#+TBLFM: " + (let* ((file (buffer-file-name)) + (org-capture-templates + `(("t" "Table" table-line (file ,file) + "| 2 |" :immediate-finish t)))) + (org-capture nil "t")) + (buffer-string)))) ;; When `:prepend' is nil, add the row at the end of the table. (should (equal "| a |\n| x |\n"