summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2018-10-22 23:40:49 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-10-22 23:40:49 +0200
commitaaa3372b8bf159c37d935decea3bca7afb0f5337 (patch)
tree47b4b9ba27f4bffe9c6a51ba6a29f638c65a74f8
parent0fa8bb4c513f980669d70da9819ff4bbab9a575e (diff)
downloadorg-mode-aaa3372b8bf159c37d935decea3bca7afb0f5337.tar.gz
org-capture: Fix capture aborting
* lisp/org-capture.el (org-capture-place-entry): Fix delimiters for region to delete when aborting capture. * testing/lisp/test-org-capture.el (test-org-capture/abort): Add test.
-rw-r--r--lisp/org-capture.el27
-rw-r--r--testing/lisp/test-org-capture.el16
2 files changed, 29 insertions, 14 deletions
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 862aac2..54fbe39 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -1128,21 +1128,22 @@ 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))))
- (let ((beg (point))
- (template (org-capture-get :template)))
+ (let ((origin (point)))
(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))
- (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 (search-backward "%?" beg t)
- (search-forward "%?" end t))
- (replace-match ""))))))
+ (let ((beg (point)))
+ (org-capture-position-for-last-stored beg)
+ (let ((template (org-capture-get :template)))
+ (org-capture-verify-tree template)
+ (org-paste-subtree level template 'for-yank))
+ (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))
+ (org-capture-mark-kill-region origin (point))
+ (org-capture-narrow beg end)
+ (when (or (search-backward "%?" beg t)
+ (search-forward "%?" end t))
+ (replace-match "")))))))
(defun org-capture-place-item ()
"Place the template as a new plain list item."
diff --git a/testing/lisp/test-org-capture.el b/testing/lisp/test-org-capture.el
index 3f3338f..10cb457 100644
--- a/testing/lisp/test-org-capture.el
+++ b/testing/lisp/test-org-capture.el
@@ -146,7 +146,9 @@
(list file1 file2 (buffer-file-name)))))))))
(ert-deftest test-org-capture/abort ()
- "Test that capture can be aborted after inserting at end of capture buffer."
+ "Test aborting a capture process."
+ ;; Test that capture can be aborted after inserting at end of
+ ;; capture buffer.
(should
(equal
"* A\n* B\n"
@@ -158,6 +160,18 @@
(goto-char (point-max))
(insert "Capture text")
(org-capture-kill))
+ (buffer-string))))
+ ;; Test aborting a capture that split the line.
+ (should
+ (equal
+ "* AB\n"
+ (org-test-with-temp-text-in-file "* AB\n"
+ (let* ((file (buffer-file-name))
+ (org-capture-templates
+ `(("t" "Todo" entry
+ (file+function ,file (lambda () (goto-char 4))) "** H1 %?"))))
+ (org-capture nil "t")
+ (org-capture-kill))
(buffer-string)))))
(ert-deftest test-org-caputre/entry ()