From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Problem of refile in the org capture buffer Date: Sun, 19 Feb 2017 15:40:47 +0100 Message-ID: <87bmtyz1jk.fsf@nicolasgoaziou.fr> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38655) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cfSfT-0003OP-F1 for emacs-orgmode@gnu.org; Sun, 19 Feb 2017 09:40:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cfSfS-0008MY-5Z for emacs-orgmode@gnu.org; Sun, 19 Feb 2017 09:40:51 -0500 Received: from relay3-d.mail.gandi.net ([2001:4b98:c:538::195]:37211) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cfSfR-0008Ln-WB for emacs-orgmode@gnu.org; Sun, 19 Feb 2017 09:40:50 -0500 In-Reply-To: (Liu Hui's message of "Mon, 6 Feb 2017 20:08:14 +0800") 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: Liu Hui Cc: emacs-orgmode@gnu.org Hello, Liu Hui writes: > 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 Thank you for the patch and the analysis. I eventually fixed it with a slightly different solution, however. Regards, -- Nicolas Goaziou