Hello, Liu Hui <liuhui1...@gmail.com> 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