branch: externals/org commit 0c8fba93fefcdd60720c5189cc70c96c4605ad43 Author: Rens Oliemans <ha...@rensoliemans.nl> Commit: Ihor Radchenko <yanta...@posteo.net>
org-capture: Allow entry template to start without heading * 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/ --- lisp/org-capture.el | 2 ++ testing/lisp/test-org-capture.el | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 6603b5e017..05e3610555 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -1198,6 +1198,8 @@ may have been stored before." (exact-position (org-capture-get :exact-position)) (insert-here? (org-capture-get :insert-here)) (level 1)) + (unless (string-match org-outline-regexp-bol 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 0ed44c6af0..4e9139c409 100644 --- a/testing/lisp/test-org-capture.el +++ b/testing/lisp/test-org-capture.el @@ -244,6 +244,30 @@ :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")))) + (should + (org-test-with-temp-text-in-file "" + (let* ((file (buffer-file-name)) + (org-capture-templates + `(("t" "Test" entry (file ,file) "*bold*" + :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"