瀏覽代碼

Merge branch 'maint'

Nicolas Goaziou 6 年之前
父節點
當前提交
21fa859c4d
共有 2 個文件被更改,包括 43 次插入2 次删除
  1. 8 2
      lisp/org-capture.el
  2. 35 0
      testing/lisp/test-org-capture.el

+ 8 - 2
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"))

+ 35 - 0
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