emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Problem of refile in the org capture buffer
@ 2017-02-06 12:08 Liu Hui
  2017-02-19 14:40 ` Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Liu Hui @ 2017-02-06 12:08 UTC (permalink / raw)
  To: emacs-orgmode

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/)

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Problem of refile in the org capture buffer
@ 2017-02-08  7:42 Liu Hui
  0 siblings, 0 replies; 3+ messages in thread
From: Liu Hui @ 2017-02-08  7:42 UTC (permalink / raw)
  To: emacs-orgmode

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/)

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: Problem of refile in the org capture buffer
  2017-02-06 12:08 Problem of refile in the org capture buffer Liu Hui
@ 2017-02-19 14:40 ` Nicolas Goaziou
  0 siblings, 0 replies; 3+ messages in thread
From: Nicolas Goaziou @ 2017-02-19 14:40 UTC (permalink / raw)
  To: Liu Hui; +Cc: emacs-orgmode

Hello,

Liu Hui <liuhui1610@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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-02-19 14:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-06 12:08 Problem of refile in the org capture buffer Liu Hui
2017-02-19 14:40 ` Nicolas Goaziou
  -- strict thread matches above, loose matches on Subject: below --
2017-02-08  7:42 Liu Hui

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).