branch: externals/org commit a62f75c84120d76ac04f1f2839f96e226134132b Author: Rens Oliemans <ha...@rensoliemans.nl> Commit: Ihor Radchenko <yanta...@posteo.net>
org-capture: Allow table-line entry to start without | * 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 05e3610555..34f9363e23 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1356,13 +1356,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 4e9139c409..f97d08bcea 100644 --- a/testing/lisp/test-org-capture.el +++ b/testing/lisp/test-org-capture.el @@ -613,6 +613,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"