From af0b56f3338b8700bd6096e4963c95436b1a14b0 Mon Sep 17 00:00:00 2001 Message-ID: In-Reply-To: <36639ac711f099b49900d886ad28d29abc1b29ed.1713102029.git.yantar92@posteo.net> References: <36639ac711f099b49900d886ad28d29abc1b29ed.1713102029.git.yantar92@posteo.net> From: Rens Oliemans Date: Sun, 14 Apr 2024 13:24:51 +0200 Subject: [PATCH v2 2/2] 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 a95a38162..205d09da8 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1356,13 +1356,14 @@ (defun org-capture-place-item () (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 4e9139c40..f97d08bce 100644 --- a/testing/lisp/test-org-capture.el +++ b/testing/lisp/test-org-capture.el @@ -613,6 +613,16 @@ (ert-deftest test-org-capture/table-line () "| 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