emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Xavier Martinez-Hidalgo <xavier@martinezhidalgo.org>
To: emacs-orgmode@gnu.org
Subject: [PATCH] org-capture: cannot abort cleanly after inserting at end of buffer
Date: Thu, 2 Nov 2017 14:23:03 +0100	[thread overview]
Message-ID: <CAMKO=kKQdyW56L11+m8b1tTBO1QDw2-j7ddJntOQMmvXY1O-ow@mail.gmail.com> (raw)

[-- 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


             reply	other threads:[~2017-11-02 13:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-02 13:23 Xavier Martinez-Hidalgo [this message]
2017-11-03 21:22 ` [PATCH] org-capture: cannot abort cleanly after inserting at end of buffer Nicolas Goaziou
  -- strict thread matches above, loose matches on Subject: below --
2017-11-04 10:44 Xavier Martinez-Hidalgo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMKO=kKQdyW56L11+m8b1tTBO1QDw2-j7ddJntOQMmvXY1O-ow@mail.gmail.com' \
    --to=xavier@martinezhidalgo.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).