* lisp/org-capture.el (org-capture-place-table-line): Prepend table-line begin ('|') if the template does not start with it.
* testing/lisp/test-org-capture.el (test-org-capture/table-line): Verify that a template gets prepended with a '|' if it does not start with it. --- lisp/org-capture.el | 15 ++++++++------- testing/lisp/test-org-capture.el | 10 ++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 750778f8b..a56e75fda 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1355,13 +1355,14 @@ may have been stored before." (defun org-capture-place-table-line () "Place the template as a table line." (require 'org-table) - (let ((text - (pcase (org-trim (org-capture-get :template)) - ((pred (string-match-p org-table-border-regexp)) - "| %?Bad template |") - (text (concat text "\n")))) - (table-line-pos (org-capture-get :table-line-pos)) - beg end) + (let* ((template (org-trim (org-capture-get :template))) + (text + (pcase template + ((pred (string-match-p org-table-border-regexp)) + (concat "| " template)) + (text (concat text "\n")))) + (table-line-pos (org-capture-get :table-line-pos)) + beg end) (cond ((org-capture-get :exact-position) (org-with-point-at (org-capture-get :exact-position) diff --git a/testing/lisp/test-org-capture.el b/testing/lisp/test-org-capture.el index 9ab078193..6c13e8283 100644 --- a/testing/lisp/test-org-capture.el +++ b/testing/lisp/test-org-capture.el @@ -606,6 +606,16 @@ "| 2 |" :immediate-finish t)))) (org-capture nil "t")) (buffer-string)))) + ;; Prepend | when the template does not start with it + (should + (equal "| 1 |\n| 2 |\n" + (org-test-with-temp-text-in-file "| 1 |\n" + (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" -- 2.44.0