From mboxrd@z Thu Jan 1 00:00:00 1970 From: Liu Hui Subject: Problem of refile in the org capture buffer Date: Mon, 6 Feb 2017 20:08:14 +0800 Message-ID: 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]:56249) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cai5p-0008Tu-Um for emacs-orgmode@gnu.org; Mon, 06 Feb 2017 07:08:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cai5l-00019g-0t for emacs-orgmode@gnu.org; Mon, 06 Feb 2017 07:08:25 -0500 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:33833) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cai5k-00019Q-Rv for emacs-orgmode@gnu.org; Mon, 06 Feb 2017 07:08:20 -0500 Received: by mail-pf0-x243.google.com with SMTP id y143so6807155pfb.1 for ; Mon, 06 Feb 2017 04:08:20 -0800 (PST) Received: from [0.0.0.0] ([188.166.240.79]) by smtp.gmail.com with ESMTPSA id b10sm2245612pga.21.2017.02.06.04.08.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Feb 2017 04:08:19 -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 (refine) 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 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/)