From mboxrd@z Thu Jan 1 00:00:00 1970 From: Liu Hui Subject: Problem of refile in the org capture buffer Date: Wed, 8 Feb 2017 15:42:41 +0800 Message-ID: <29a80eb8-bb33-9778-ed82-271a0148db1e@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41786) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cbMty-0001Lz-Fz for emacs-orgmode@gnu.org; Wed, 08 Feb 2017 02:42:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cbMtv-0006Rj-Cr for emacs-orgmode@gnu.org; Wed, 08 Feb 2017 02:42:54 -0500 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:34858) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cbMtv-0006Nm-5W for emacs-orgmode@gnu.org; Wed, 08 Feb 2017 02:42:51 -0500 Received: by mail-pg0-x244.google.com with SMTP id 204so14455901pge.2 for ; Tue, 07 Feb 2017 23:42:48 -0800 (PST) Received: from [0.0.0.0] ([188.166.240.79]) by smtp.gmail.com with ESMTPSA id t185sm17233504pgb.32.2017.02.07.23.42.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Feb 2017 23:42:47 -0800 (PST) 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 Hello, I find C-c C-w (refile) in the org capture buffer doesn't work correctly when there are empty lines (containing the point) in the end of buffer. Steps to reproduce: 1. echo -e "* A\n* B" > /tmp/test.org; cat /tmp/test.org * A * B 2. Emacs -Q, and evaluate the code: (setq org-capture-templates '(("t" "Todo" entry (file+headline "/tmp/test.org" "A") "** test1 %?"))) 3. M-x org-capture, and press t to open the org capture buffer 4. In the capture buffer, press C-j to insert a newline, then C-c C-w: => the subtree "B" will be refiled rather than the "test1". The problem is caused by org-capture-finalize, which deletes the empty lines and, as a result, makes the point saved by org-capture-refile invalid. The following patch should fix the problem: diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 1a1a500..27cb60b 100644 --- a/lisp/org-capture.el +++ b/lisp/org-capture.el @@ -827,6 +827,9 @@ already gone. Any prefix argument will be passed to the refile command." (base (buffer-base-buffer (current-buffer))) (org-capture-is-refiling t) (kill-buffer (org-capture-get :kill-buffer 'local))) + (and (< (skip-chars-backward " \t\n") 0) + (not (bobp)) + (setq pos (point))) (org-capture-put :kill-buffer nil) (org-capture-finalize) (save-window-excursion Emacs : GNU Emacs 26.0.50.2 (x86_64-pc-linux-gnu, GTK+ Version 3.18.9) of 2016-12-17 Package: Org mode version 9.0.4 (release_9.0.4-283-g2064b0 @ ~/org-mode/lisp/)