summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2018-10-22 22:22:21 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-10-22 22:22:21 +0200
commit0fa8bb4c513f980669d70da9819ff4bbab9a575e (patch)
tree5af4425ee1a61867976658bae876879380746566
parentbddd287cce4d4926ab3fec712b0f78d0feb39a0d (diff)
downloadorg-mode-0fa8bb4c513f980669d70da9819ff4bbab9a575e.tar.gz
org-capture: Inserting an entry doesn't break structure
* lisp/org-capture.el (org-capture-place-entry): Carefully narrow buffer to not alter following headline. Also include leading empty lines in region to remove when cancelling capture. * testing/lisp/test-org-capture.el (test-org-caputre/entry): New test. (test-org-capture/abort): Rename test. Reported-by: Martin Yrjölä <martin.yrjola@gmail.com> <http://lists.gnu.org/r/emacs-orgmode/2018-10/msg00256.html>
-rw-r--r--lisp/org-capture.el12
-rw-r--r--testing/lisp/test-org-capture.el18
2 files changed, 23 insertions, 7 deletions
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index cbc72d4..862aac2 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -1128,20 +1128,20 @@ may have been stored before."
(unless (org-at-heading-p) (outline-next-heading)))
;; Otherwise, insert as a top-level entry at the end of the file.
(t (goto-char (point-max))))
- (unless (bolp) (insert "\n"))
- (org-capture-empty-lines-before)
(let ((beg (point))
(template (org-capture-get :template)))
+ (unless (bolp) (insert "\n"))
+ (org-capture-empty-lines-before)
(org-capture-verify-tree template)
(org-paste-subtree level template 'for-yank)
(org-capture-empty-lines-after)
(org-capture-position-for-last-stored beg)
(unless (org-at-heading-p) (outline-next-heading))
- (let ((end (point)))
- (org-capture-mark-kill-region beg end)
+ (org-capture-mark-kill-region beg (point))
+ (let ((end (if (org-at-heading-p) (line-end-position 0) (point))))
(org-capture-narrow beg end)
- (when (or (re-search-backward "%\\?" beg t)
- (re-search-forward "%\\?" end t))
+ (when (or (search-backward "%?" beg t)
+ (search-forward "%?" end t))
(replace-match ""))))))
(defun org-capture-place-item ()
diff --git a/testing/lisp/test-org-capture.el b/testing/lisp/test-org-capture.el
index 31522c1..3f3338f 100644
--- a/testing/lisp/test-org-capture.el
+++ b/testing/lisp/test-org-capture.el
@@ -145,7 +145,7 @@
(org-capture-refile)
(list file1 file2 (buffer-file-name)))))))))
-(ert-deftest test-org-capture/insert-at-end-abort ()
+(ert-deftest test-org-capture/abort ()
"Test that capture can be aborted after inserting at end of capture buffer."
(should
(equal
@@ -160,6 +160,22 @@
(org-capture-kill))
(buffer-string)))))
+(ert-deftest test-org-caputre/entry ()
+ "Test `entry' type in capture template."
+ ;; Do not break next headline.
+ (should
+ (equal
+ "* A\n** H1 Capture text\n* B\n"
+ (org-test-with-temp-text-in-file "* A\n* B\n"
+ (let* ((file (buffer-file-name))
+ (org-capture-templates
+ `(("t" "Todo" entry (file+headline ,file "A") "** H1 %?"))))
+ (org-capture nil "t")
+ (goto-char (point-max))
+ (insert "Capture text")
+ (org-capture-finalize))
+ (buffer-string)))))
+
(ert-deftest test-org-capture/table-line ()
"Test `table-line' type in capture template."
;; When a only file is specified, use the first table available.