summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2019-04-09 09:24:46 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2019-04-09 09:24:46 +0200
commit21fa859c4d693a8d23233aa332d8d2e141b1ab07 (patch)
tree4b513dc44d55475af7e4adf09b9c30e7b2086a09
parent285486c23bf09c6c3c46f9242f6ac2a4ebc883d0 (diff)
parent6efe53cf0b4f4c973ebc9ea4e72b6d7a4310d498 (diff)
downloadorg-mode-21fa859c4d693a8d23233aa332d8d2e141b1ab07.tar.gz
Merge branch 'maint'
-rw-r--r--lisp/org-capture.el10
-rw-r--r--testing/lisp/test-org-capture.el35
2 files changed, 43 insertions, 2 deletions
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 2548074..eedbd21 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -1196,8 +1196,14 @@ may have been stored before."
item))
(throw :found t)))
;; No list found. Move to the location when to insert
- ;; template.
- (goto-char (if prepend? beg end)))))
+ ;; template. Skip planning info and properties drawers, if
+ ;; any.
+ (goto-char (cond ((not prepend?) end)
+ ((org-before-first-heading-p) beg)
+ (t (max (save-excursion
+ (org-end-of-meta-data)
+ (point))
+ beg)))))))
;; Insert template.
(let ((origin (point)))
(unless (bolp) (insert "\n"))
diff --git a/testing/lisp/test-org-capture.el b/testing/lisp/test-org-capture.el
index cdc70f1..d1474e2 100644
--- a/testing/lisp/test-org-capture.el
+++ b/testing/lisp/test-org-capture.el
@@ -292,6 +292,41 @@
(org-capture nil "t")
(org-capture-finalize))
(buffer-string))))
+ ;; If there is no list and `:prepend' is non-nil, insert list at the
+ ;; beginning of the entry, or the beginning of the buffer. However,
+ ;; preserve properties drawer and planning info, if any.
+ (should
+ (equal
+ "* A\n- X\nSome text\n"
+ (org-test-with-temp-text-in-file "* A\nSome text"
+ (let* ((file (buffer-file-name))
+ (org-capture-templates
+ `(("t" "Item" item (file+headline ,file "A") "- X"
+ :prepend t))))
+ (org-capture nil "t")
+ (org-capture-finalize))
+ (buffer-string))))
+ (should
+ (equal
+ "- X\nText\n"
+ (org-test-with-temp-text-in-file "Text"
+ (let* ((file (buffer-file-name))
+ (org-capture-templates
+ `(("t" "Item" item (file ,file) "- X" :prepend t))))
+ (org-capture nil "t")
+ (org-capture-finalize))
+ (buffer-string))))
+ (should
+ (equal
+ "* A\nSCHEDULED: <2012-03-29 Thu>\n- X\nText\n"
+ (org-test-with-temp-text-in-file "* A\nSCHEDULED: <2012-03-29 Thu>\nText"
+ (let* ((file (buffer-file-name))
+ (org-capture-templates
+ `(("t" "Item" item (file+headline ,file "A") "- X"
+ :prepend t))))
+ (org-capture nil "t")
+ (org-capture-finalize))
+ (buffer-string))))
;; When `:prepend' is nil, insert new item as the last top-level
;; item.
(should