emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rens Oliemans <hallo@rensoliemans.nl>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: emacs-orgmode@gnu.org
Subject: [PATCH 2/2] org-capture: Allow table-line entry to start without |
Date: Sun, 14 Apr 2024 13:24:51 +0200	[thread overview]
Message-ID: <87il0krxto.fsf@rensoliemans.nl> (raw)
In-Reply-To: <877chnc0lr.fsf@localhost>

* 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



      parent reply	other threads:[~2024-04-14 11:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-27 10:47 "Bad template" when creating org-capture for table-line without '|' Rens Oliemans
2024-03-27 12:37 ` Ihor Radchenko
2024-04-14 11:24   ` [PATCH 1/2] org-capture: Allow entry template to start without heading Rens Oliemans
2024-04-14 13:41     ` Ihor Radchenko
2024-04-14 18:39       ` Rens Oliemans
2024-04-14 11:24   ` Rens Oliemans [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87il0krxto.fsf@rensoliemans.nl \
    --to=hallo@rensoliemans.nl \
    --cc=emacs-orgmode@gnu.org \
    --cc=yantar92@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).