* [PATCH] org-capture: cannot abort cleanly after inserting at end of buffer
@ 2017-11-02 13:23 Xavier Martinez-Hidalgo
2017-11-03 21:22 ` Nicolas Goaziou
0 siblings, 1 reply; 3+ messages in thread
From: Xavier Martinez-Hidalgo @ 2017-11-02 13:23 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 576 bytes --]
Hi,
After the following steps:
- Start a capture.
- Move to end of capture buffer (M->).
- Type some text.
- Abort capture (C-c C-k).
the capture is aborted but its contents are not removed from the
target buffer and the following message is shown:
"Capture process aborted, but target buffer could not be cleaned up
correctly"
I am a attaching a patch that adds a test case showing up the problem
and includes a proposed fix (setting the capture kill end marker
insertion type).
I am not sure whether the fix might affect something else. Does the
fix makes sense?
[-- Attachment #2: 0001-org-capture-Fix-aborting-after-inserting-text-at-end.patch --]
[-- Type: text/x-patch, Size: 2312 bytes --]
From 24130d37652acda6e3554d83b1506e93efc42a14 Mon Sep 17 00:00:00 2001
From: Xavier Martinez-Hidalgo <xavier@martinezhidalgo.org>
Date: Thu, 2 Nov 2017 11:47:19 +0100
Subject: [PATCH] org-capture: Fix aborting after inserting text at end of
buffer
* lisp/org-capture.el (org-capture-mark-kill-region): Set end marker
insertion type so that it advances when inserting text at the end of
the capture buffer.
* testing/lisp/test-org-capture.el (test-org-capture/insert-at-end-abort):
Add test case.
Inserting text at the end of the capture buffer does not advance the
end kill marker. This causes the narrowing region and the kill
markers to get out of sync, which prevents 'org-capture-finalize' from
correctly cleaning the target buffer when aborting the capture.
Setting the kill end marker insertion type fixes this.
TINYCHANGE
---
lisp/org-capture.el | 1 +
testing/lisp/test-org-capture.el | 13 +++++++++++++
2 files changed, 14 insertions(+)
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 25af674b8..59561d666 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -1313,6 +1313,7 @@ Of course, if exact position has been required, just put it there."
"Mark the region that will have to be killed when aborting capture."
(let ((m1 (move-marker (make-marker) beg))
(m2 (move-marker (make-marker) end)))
+ (set-marker-insertion-type m2 t)
(org-capture-put :begin-marker m1)
(org-capture-put :end-marker m2)))
diff --git a/testing/lisp/test-org-capture.el b/testing/lisp/test-org-capture.el
index 4d5dfb713..5e41f972b 100644
--- a/testing/lisp/test-org-capture.el
+++ b/testing/lisp/test-org-capture.el
@@ -146,5 +146,18 @@
(list file1 file2 (buffer-file-name)))))))))
+(ert-deftest test-org-capture/insert-at-end-abort ()
+ "Test that capture can be aborted after inserting at end of capture buffer."
+ (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-kill))
+ (should (string= "* A\n* B\n" (buffer-string)))))
+
+
(provide 'test-org-capture)
;;; test-org-capture.el ends here
--
2.11.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] org-capture: cannot abort cleanly after inserting at end of buffer
2017-11-02 13:23 Xavier Martinez-Hidalgo
@ 2017-11-03 21:22 ` Nicolas Goaziou
0 siblings, 0 replies; 3+ messages in thread
From: Nicolas Goaziou @ 2017-11-03 21:22 UTC (permalink / raw)
To: Xavier Martinez-Hidalgo; +Cc: emacs-orgmode
Hello,
Xavier Martinez-Hidalgo <xavier@martinezhidalgo.org> writes:
> After the following steps:
>
> - Start a capture.
> - Move to end of capture buffer (M->).
> - Type some text.
> - Abort capture (C-c C-k).
>
> the capture is aborted but its contents are not removed from the
> target buffer and the following message is shown:
>
> "Capture process aborted, but target buffer could not be cleaned up
> correctly"
>
> I am a attaching a patch that adds a test case showing up the problem
> and includes a proposed fix (setting the capture kill end marker
> insertion type).
Applied, with a slight twist. Thank you!
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] org-capture: cannot abort cleanly after inserting at end of buffer
@ 2017-11-04 10:44 Xavier Martinez-Hidalgo
0 siblings, 0 replies; 3+ messages in thread
From: Xavier Martinez-Hidalgo @ 2017-11-04 10:44 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode
On Fri, Nov 3, 2017 at 10:22 PM, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
> Applied, with a slight twist. Thank you!
It does look much cleaner using 'copy-marker'. Thanks a lot for the review!
Regards,
--
Xavier Martinez-Hidalgo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-11-04 10:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-04 10:44 [PATCH] org-capture: cannot abort cleanly after inserting at end of buffer Xavier Martinez-Hidalgo
-- strict thread matches above, loose matches on Subject: below --
2017-11-02 13:23 Xavier Martinez-Hidalgo
2017-11-03 21:22 ` Nicolas Goaziou
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.