forked from mirrors/org-mode
org-capture-finalize: Do not save new file with :no-save aborted capture
* lisp/org-capture.el (org-capture-finalize): Do not save the newly created file buffer when the capture is aborted and org-capture is not asked to save upon capture. * testing/lisp/test-org-capture.el (test-org-capture/abort): Add test.
This commit is contained in:
parent
005c9ae747
commit
b34bdc8719
|
@ -889,10 +889,16 @@ captured item after finalizing."
|
||||||
(goto-char (+ size pos))
|
(goto-char (+ size pos))
|
||||||
(goto-char (if (< ipt pos) (+ size pos) pos))))))
|
(goto-char (if (< ipt pos) (+ size pos) pos))))))
|
||||||
|
|
||||||
|
(if (and base-buffer org-note-abort new-buffer)
|
||||||
|
;; Unconditionally kill the new buffer when capture is
|
||||||
|
;; aborted.
|
||||||
|
(with-current-buffer base-buffer
|
||||||
|
(set-buffer-modified-p nil)
|
||||||
|
(kill-buffer))
|
||||||
;; Kill the target buffer if that is desired
|
;; Kill the target buffer if that is desired
|
||||||
(when (and base-buffer new-buffer kill-buffer)
|
(when (and base-buffer new-buffer kill-buffer)
|
||||||
(with-current-buffer base-buffer (save-buffer))
|
(with-current-buffer base-buffer (save-buffer))
|
||||||
(kill-buffer base-buffer))
|
(kill-buffer base-buffer)))
|
||||||
|
|
||||||
;; Restore the window configuration before capture
|
;; Restore the window configuration before capture
|
||||||
(set-window-configuration return-wconf))
|
(set-window-configuration return-wconf))
|
||||||
|
|
|
@ -152,6 +152,18 @@
|
||||||
|
|
||||||
(ert-deftest test-org-capture/abort ()
|
(ert-deftest test-org-capture/abort ()
|
||||||
"Test aborting a capture process."
|
"Test aborting a capture process."
|
||||||
|
;; Newly create capture buffer should not be saved.
|
||||||
|
(let ((capture-file (make-temp-name
|
||||||
|
(org-file-name-concat
|
||||||
|
temporary-file-directory
|
||||||
|
"org-test"))))
|
||||||
|
(unwind-protect
|
||||||
|
(let ((org-capture-templates `(("t" "Todo" entry (file ,capture-file) nil :no-save t))))
|
||||||
|
(org-capture nil "t")
|
||||||
|
(org-capture-kill)
|
||||||
|
(should-not (file-exists-p capture-file)))
|
||||||
|
(when (file-exists-p capture-file)
|
||||||
|
(delete-file capture-file))))
|
||||||
;; Test that capture can be aborted after inserting at end of
|
;; Test that capture can be aborted after inserting at end of
|
||||||
;; capture buffer.
|
;; capture buffer.
|
||||||
(should
|
(should
|
||||||
|
|
Loading…
Reference in a new issue