Ver código fonte

org-capture: Correctly store position of captured entry

* lisp/org-capture.el (org-capture-place-entry): Store position at the
  beginning of the capture entry, not at its end.
* testing/lisp/test-org-capture.el (test-org-caputre/entry): Add test.
Nicolas Goaziou 6 anos atrás
pai
commit
1d60d5ee03
2 arquivos alterados com 14 adições e 2 exclusões
  1. 1 1
      lisp/org-capture.el
  2. 13 1
      testing/lisp/test-org-capture.el

+ 1 - 1
lisp/org-capture.el

@@ -1133,9 +1133,9 @@ may have been stored before."
     (let ((origin (point)))
       (unless (bolp) (insert "\n"))
       (org-capture-empty-lines-before)
-      (org-capture-position-for-last-stored (point))
       (let ((beg (point)))
 	(org-paste-subtree level template 'for-yank)
+	(org-capture-position-for-last-stored beg)
 	(let ((end (if (org-at-heading-p) (line-end-position 0) (point))))
 	  (org-capture-empty-lines-after)
 	  (unless (org-at-heading-p) (outline-next-heading))

+ 13 - 1
testing/lisp/test-org-capture.el

@@ -206,7 +206,19 @@
 	(goto-char (point-max))
 	(insert "Capture text")
 	(org-capture-finalize))
-      (buffer-string)))))
+      (buffer-string))))
+  ;; Correctly save position of inserted entry.
+  (should
+   (equal
+    "** H"
+    (org-test-with-temp-text-in-file "* A"
+      (let* ((file (buffer-file-name))
+	     (org-capture-templates
+	      `(("t" "Test" entry (file+headline ,file "A") "** H\nFoo"
+		 :immediate-finish t))))
+	(org-capture nil "t")
+	(org-capture '(16))
+	(buffer-substring (point) (line-end-position)))))))
 
 (ert-deftest test-org-capture/item ()
   "Test `item' type in capture template."