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 1/2] org-capture: Allow entry template to start without heading
Date: Sun, 14 Apr 2024 13:24:49 +0200	[thread overview]
Message-ID: <87jzl0rxtq.fsf@rensoliemans.nl> (raw)
In-Reply-To: <877chnc0lr.fsf@localhost>

* lisp/org-capture.el (org-capture-place-entry): Prepend heading to
template if the template does not yet start with a heading.

* testing/lisp/test-org-capture.el (test-org-capture/entry): Add two
tests: no error is raised when org-capture is called with a template
that does not start with a heading; and org-capture should error with
a template with a lower heading after a higher heading.

Link: https://list.orgmode.org/877chnc0lr.fsf@localhost/
---
First iteration of these patches, please let me know if anything can be improved, either
about the code or patches themselves (I am not used to sending patches via email).

 lisp/org-capture.el              |  1 +
 testing/lisp/test-org-capture.el | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index da14f45c0..750778f8b 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -1198,6 +1198,7 @@ may have been stored before."
 	(exact-position (org-capture-get :exact-position))
 	(insert-here? (org-capture-get :insert-here))
 	(level 1))
+    (unless (string-match "^*" template) (setq template (concat "* " template)))
     (org-capture-verify-tree template)
     (when exact-position (goto-char exact-position))
     (cond
diff --git a/testing/lisp/test-org-capture.el b/testing/lisp/test-org-capture.el
index 0ed44c6af..9ab078193 100644
--- a/testing/lisp/test-org-capture.el
+++ b/testing/lisp/test-org-capture.el
@@ -244,6 +244,23 @@
 		:immediate-finish t))))
        (org-capture nil "t")
        (buffer-string))))
+  ;; Do not raise an error on templates that do not start with a heading.
+  (should
+   (org-test-with-temp-text-in-file ""
+     (let* ((file (buffer-file-name))
+            (org-capture-templates
+             `(("t" "Test" entry (file ,file) "Foo"
+                :immediate-finish t))))
+       (org-capture nil "t"))))
+  ;; Raise an error on templates with a lower level heading after a
+  ;; higher level one.
+  (should-error
+   (org-test-with-temp-text-in-file ""
+     (let* ((file (buffer-file-name))
+            (org-capture-templates
+             `(("t" "Test" entry (file ,file) "** X\n* Y"
+	        :immediate-finish t))))
+       (org-capture nil "t"))))
   ;; With a 0 prefix argument, ignore surrounding lists.
   (should
    (equal "Foo\n* X\nBar\n"
-- 
2.44.0


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

Thread overview: 13+ 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   ` Rens Oliemans [this message]
2024-04-14 13:41     ` [PATCH 1/2] org-capture: Allow entry template to start without heading Ihor Radchenko
2024-04-14 18:39       ` Rens Oliemans
2024-05-14  8:48         ` Ihor Radchenko
2024-05-14  9:49           ` Rens Oliemans
2024-05-27  7:54           ` Rens Oliemans
2024-05-27  8:29             ` Ihor Radchenko
2024-05-27  8:50               ` Bastien Guerry
2024-06-04 13:21       ` Ihor Radchenko
2024-06-05 10:25         ` Rens Oliemans
2024-04-14 11:24   ` [PATCH 2/2] org-capture: Allow table-line entry to start without | Rens Oliemans

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=87jzl0rxtq.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).