From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Burgess Subject: [PATCH] Save buffer in org-capture-refile Date: Wed, 5 Sep 2018 11:32:45 +0100 Message-ID: <20180905103245.26222-1-andrew.burgess@embecosm.com> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37273) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxV7T-0008Gd-Q3 for emacs-orgmode@gnu.org; Wed, 05 Sep 2018 06:33:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxV7P-0004gw-QS for emacs-orgmode@gnu.org; Wed, 05 Sep 2018 06:33:07 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:35482) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fxV7P-0004f9-Hf for emacs-orgmode@gnu.org; Wed, 05 Sep 2018 06:33:03 -0400 Received: by mail-wr1-x443.google.com with SMTP id j26-v6so7110379wre.2 for ; Wed, 05 Sep 2018 03:33:03 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Cc: Andrew Burgess I notice that if a capture template sets ':kill-buffer t', and I use org-capture-refile to refile into a different file then I don't get the result I expect. Let me give an example, here's my setup: $ mkdir ~/tmp $ cd ~/tmp $ echo "* loc1/tasks" > loc1.org $ echo "* inbox/tasks" > inbox.org $ cat test.el (setq org-capture-templates '(("t" "TASK that needs completing" entry (file+headline "~/tmp/inbox.org" "inbox/tasks") "** TODO %?" :prepend t :kill-buffer t))) (setq org-refile-targets (quote (("~/tmp/loc1.org" :maxlevel . 2)))) $ emacs -Q -l test.el Now in emacs: org-capture # Start a capture t # Select the template 't' AAAAAA # Fill in a task title org-capture-refile # Start refiling l # Select refile location, should complete to # 'loc1/tasks (loc1.org)' At this point you should see the message: Buffer inbox.org modified; kill anyway? (yes or no) Neither answer gets you the result you want (I think). If you choose 'yes', then quit emacs (saving buffers as you go[1]) you'll find that task 'AAAAAA' is now in both inbox.org and loc1.org. If you choose 'no', then quit emacs (saving buffers as you go) you'll find that the task has moved out of inbox.org into loc1.org, but, clearly the requested ':kill-buffer t' wasn't respected. The problem is that org-capture-refile calls org-capture-finalize, but suppresses the call to kill-buffer in org-capture-finalize, instead performing that call itself. However, org-capture-finalize calls save-buffer, before calling kill-buffer, org-capture-refile doesn't. If I add a call to save-buffer into org-capture-refile in a similar fashion to the call in org-capture-finalize, then I get the behaviour I expect. My employer Embecosm should already have a copyright assignment on file for emacs. [1] I think that there's an argument to be made that, if the refile destination is opened just for the purpose of refiling this item, and ':kill-buffer t' is in place, then org-capture-refile should probably kill the refile destination too. However, though related, I think that's a separate issue. Thanks, Andrew --- In org-capture-finalize if the capture template requests that the capture buffer be killed, we first save the buffer, and then kill it. However, org-capture-refile suppresses the killing of the buffer in org-capture-finalize and performs the call to kill-buffer itself, however, it doesn't save the buffer. The result is that the user is prompted with a "buffer has been modified, kill anyway?" message. At this point answering yes will leave the item being refiled in both the source and destination locations, while answering no will leave the buffer around (which isn't what the user wanted). The solution is to call save-buffer in org-capture-refile, just like it is called in org-capture-finalize. --- lisp/org-capture.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 993526fcb..33f1af147 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -877,7 +877,9 @@ for `entry'-type templates")) (org-with-wide-buffer (goto-char pos) (call-interactively 'org-refile)))) - (when kill-buffer (kill-buffer base)) + (when kill-buffer + (with-current-buffer base (save-buffer)) + (kill-buffer base)) (when jump-to-captured (org-capture-goto-last-stored))) (set-marker pos nil)))) -- 2.14.4