emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Bug: Refile sometimes loses the last line [7.7 (release_7.7.15.gc363)]
@ 2011-08-01  4:18 Bernt Hansen
  2011-08-03 15:05 ` Jason Dunsmore
  0 siblings, 1 reply; 10+ messages in thread
From: Bernt Hansen @ 2011-08-01  4:18 UTC (permalink / raw)
  To: emacs-orgmode, Jason Dunsmore

Hi Jason,

I noticed a nasty refile bug this evening.  The problem commit is
identified as:

,----
| 85f03c0859d84d0b3b51764f379644d1461733df is the first bad commit
| commit 85f03c0859d84d0b3b51764f379644d1461733df
| Author: Jason Dunsmore <emacs-orgmode@deathroller.dunsmor.com>
| Date:   Tue Feb 15 21:31:17 2011 +0000
| 
|     Bugfix: honor `org-blank-before-new-entry' correctly in various contexts.
|     
|     * org.el (org-back-over-empty-lines): Bugfix.  Honor
|     `org-blank-before-new-entry' correctly in various contexts.
| 
| :040000 040000 b820d279cd7b170907d9171494dc65dd4c944d0b f45fdfa1a6e6181c4b9de712cafbd40fac38deb9 M      lisp
`----

I have the following minimal emacs setup to reproduce the problem:

~/bin/minimal-emacs
--8<---------------cut here---------------start------------->8---
#!/bin/sh
TESTEL=
TESTFILE=/tmp/test.el
if test -e $TESTFILE
then
  TESTEL="-l /tmp/test.el"
fi
emacs -q -l ~/minimal.emacs $TESTEL $1
--8<---------------cut here---------------end--------------->8---

~/minimal.emacs
--8<---------------cut here---------------start------------->8---
(add-to-list 'load-path (expand-file-name "~/git/org-mode/lisp"))
(add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\|txt\\)$" . org-mode))
(require 'org-install)

(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)
--8<---------------cut here---------------end--------------->8---

/tmp/test.el
--8<---------------cut here---------------start------------->8---
(setq org-blank-before-new-entry (quote ((heading)
					 (plain-list-item))))
(setq org-refile-targets (quote ((nil :maxlevel . 3)
				 (org-agenda-files :maxlevel . 3))))
--8<---------------cut here---------------end--------------->8---

/tmp/scratch.org
--8<---------------cut here---------------start------------->8---
* Target for refile
* Tasks
** Refile me
this is a test
** TODO Refile me too
this loses the last line
** Foo
no end on this line
--8<---------------cut here---------------end--------------->8---

There is no newline at end of file in /tmp/scratch.org

Steps to reproduce:
| Keystrokes                       | Notes                               |
|----------------------------------+-------------------------------------|
| $ minimal-emacs /tmp/scratch.org | Start minimal emacs session         |
| C-u C-u C-u TAB                  | Reveal the entire file              |
| M-S-.                            | Go to end of file                   |
| backspace                        | Delete last newline in file         |
| C-c C-w                          | Refile * Foo to * Target for refile |
| TargetTAB                        | Complete * Target for refile name   |
| RET                              | Refile                              |

This refiles * Foo under * Target for refile but the "no end on this
line" is left behind.

If you repeat the above but refile to * Tasks instead of * Target for
refile then the last line "no end on this line" is deleted and lost.

I've locally reverted the above problem commit which seems to fix this
for me.

Regards,
Bernt

----------------------------------------------------------------------
Emacs  : GNU Emacs 23.2.1 (i486-pc-linux-gnu, GTK+ Version 2.20.0)
 of 2010-12-11 on raven, modified by Debian
Package: Org-mode version 7.7 (release_7.7.15.gc363)

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

* Re: Bug: Refile sometimes loses the last line [7.7 (release_7.7.15.gc363)]
  2011-08-01  4:18 Bug: Refile sometimes loses the last line [7.7 (release_7.7.15.gc363)] Bernt Hansen
@ 2011-08-03 15:05 ` Jason Dunsmore
  2011-08-04  1:35   ` Bernt Hansen
  0 siblings, 1 reply; 10+ messages in thread
From: Jason Dunsmore @ 2011-08-03 15:05 UTC (permalink / raw)
  To: Bernt Hansen; +Cc: emacs-orgmode

Hi Bernt,

Can you see if this patch fixes the problem?

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/org.el b/lisp/org.el
index c7b28dd..41ac8c6 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -19212,7 +19212,9 @@ Returns the number of empty lines passed."
   (let ((pos (point)))
     (if (cdr (assoc 'heading org-blank-before-new-entry))
        (skip-chars-backward " \t\n\r")
-      (forward-line -1))
+      (unless (eq (line-number-at-pos)
+                 (count-lines (point-min) (point-max)))
+       (forward-line -1)))
     (beginning-of-line 2)
     (goto-char (min (point) pos))
     (count-lines (point) pos)))
--8<---------------cut here---------------end--------------->8---

Thanks,
Jason

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

* Re: Bug: Refile sometimes loses the last line [7.7 (release_7.7.15.gc363)]
  2011-08-03 15:05 ` Jason Dunsmore
@ 2011-08-04  1:35   ` Bernt Hansen
  2011-08-04 14:07     ` David Maus
  0 siblings, 1 reply; 10+ messages in thread
From: Bernt Hansen @ 2011-08-04  1:35 UTC (permalink / raw)
  To: Jason Dunsmore; +Cc: emacs-orgmode

Jason Dunsmore <emacs-orgmode@deathroller.dunsmor.com> writes:

> Hi Bernt,
>
> Can you see if this patch fixes the problem?
>
> diff --git a/lisp/org.el b/lisp/org.el
> index c7b28dd..41ac8c6 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -19212,7 +19212,9 @@ Returns the number of empty lines passed."
>    (let ((pos (point)))
>      (if (cdr (assoc 'heading org-blank-before-new-entry))
>         (skip-chars-backward " \t\n\r")
> -      (forward-line -1))
> +      (unless (eq (line-number-at-pos)
> +                 (count-lines (point-min) (point-max)))
> +       (forward-line -1)))
>      (beginning-of-line 2)
>      (goto-char (min (point) pos))
>      (count-lines (point) pos)))

This patch fixes it for me.  Thanks!!

Regards,
Bernt

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

* Re: Bug: Refile sometimes loses the last line [7.7 (release_7.7.15.gc363)]
  2011-08-04  1:35   ` Bernt Hansen
@ 2011-08-04 14:07     ` David Maus
  2011-08-04 14:35       ` Jason Dunsmore
  2011-08-16 13:17       ` Bastien
  0 siblings, 2 replies; 10+ messages in thread
From: David Maus @ 2011-08-04 14:07 UTC (permalink / raw)
  To: Bernt Hansen; +Cc: emacs-orgmode, Jason Dunsmore

[-- Attachment #1: Type: text/plain, Size: 1064 bytes --]

At Wed, 03 Aug 2011 21:35:40 -0400,
Bernt Hansen wrote:
>
> Jason Dunsmore <emacs-orgmode@deathroller.dunsmor.com> writes:
>
> > Hi Bernt,
> >
> > Can you see if this patch fixes the problem?
> >
> > diff --git a/lisp/org.el b/lisp/org.el
> > index c7b28dd..41ac8c6 100644
> > --- a/lisp/org.el
> > +++ b/lisp/org.el
> > @@ -19212,7 +19212,9 @@ Returns the number of empty lines passed."
> >    (let ((pos (point)))
> >      (if (cdr (assoc 'heading org-blank-before-new-entry))
> >         (skip-chars-backward " \t\n\r")
> > -      (forward-line -1))
> > +      (unless (eq (line-number-at-pos)
> > +                 (count-lines (point-min) (point-max)))
> > +       (forward-line -1)))
> >      (beginning-of-line 2)
> >      (goto-char (min (point) pos))
> >      (count-lines (point) pos)))
>
> This patch fixes it for me.  Thanks!!

I just pushed a simplified version of the solution: No need to count
lines, just check if point is at end of buffer.

Best,
  -- David
--
OpenPGP... 0x99ADB83B5A4478E6
Jabber.... dmjena@jabber.org
Email..... dmaus@ictsoc.de

[-- Attachment #2: Type: application/pgp-signature, Size: 230 bytes --]

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

* Re: Bug: Refile sometimes loses the last line [7.7 (release_7.7.15.gc363)]
  2011-08-04 14:07     ` David Maus
@ 2011-08-04 14:35       ` Jason Dunsmore
  2011-08-04 15:46         ` David Maus
  2011-08-16 13:17       ` Bastien
  1 sibling, 1 reply; 10+ messages in thread
From: Jason Dunsmore @ 2011-08-04 14:35 UTC (permalink / raw)
  To: David Maus; +Cc: Bernt Hansen, emacs-orgmode

Hi David,

> I just pushed a simplified version of the solution: No need to count
> lines, just check if point is at end of buffer.

I just tried out your patch.  The logic in your patch is slightly
different - it checks if the point is at the end of the last line in the
buffer, whereas mine checks if the point is anywhere on the last line.
I don't think it fixes the problem.  Bernt, can you test it?

Thanks,
Jason

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

* Re: Bug: Refile sometimes loses the last line [7.7 (release_7.7.15.gc363)]
  2011-08-04 14:35       ` Jason Dunsmore
@ 2011-08-04 15:46         ` David Maus
  2011-08-04 23:07           ` Bernt Hansen
  0 siblings, 1 reply; 10+ messages in thread
From: David Maus @ 2011-08-04 15:46 UTC (permalink / raw)
  To: Jason Dunsmore; +Cc: David Maus, emacs-orgmode, Bernt Hansen

[-- Attachment #1: Type: text/plain, Size: 1716 bytes --]

At Thu, 04 Aug 2011 09:35:24 -0500,
Jason Dunsmore wrote:
>
> Hi David,
>
> > I just pushed a simplified version of the solution: No need to count
> > lines, just check if point is at end of buffer.
>
> I just tried out your patch.  The logic in your patch is slightly
> different - it checks if the point is at the end of the last line in the
> buffer, whereas mine checks if the point is anywhere on the last line.
> I don't think it fixes the problem.  Bernt, can you test it?

I does it for me and should do the trick. I tracked down the problem
to `org-copy-subtree' not beeing able to correctly determine the end
of the subtree to copy.

The problem is here:

,----
|     (setq beg (point))
|     (skip-chars-forward " \t\r\n")
|     (save-match-data
|       (save-excursion (outline-end-of-heading)
| 		      (setq folded (outline-invisible-p)))
|       (condition-case nil
| 	  (org-forward-same-level (1- n) t)
| 	(error nil))
|       (org-end-of-subtree t t))
|     (org-back-over-empty-lines)
`----

(org-end-of-subtree t t) moves point to either 1/ the beginning of the
following sibling, 2/ the beginning of the last empty line in buffer
if it is present, or 3/ to the end of the last line if an last empty
line is missing.

3/ is the edge-case in question. 1/ and 2/ work with the assumption
that point is /not/ inside the entry if back-over-empty-lines is
called. Thus

(forward-line -1)
(beginning-of-line 2)

for 1/ and 2/ means: Stay where you are. For 3/ it doesn't. For 3/ it
moves point to the beginning of the last line in buffer, i.e. in front
of the last line of content in the entry.

Best,
  -- David
--
OpenPGP... 0x99ADB83B5A4478E6
Jabber.... dmjena@jabber.org
Email..... dmaus@ictsoc.de

[-- Attachment #2: Type: application/pgp-signature, Size: 230 bytes --]

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

* Re: Bug: Refile sometimes loses the last line [7.7 (release_7.7.15.gc363)]
  2011-08-04 15:46         ` David Maus
@ 2011-08-04 23:07           ` Bernt Hansen
  0 siblings, 0 replies; 10+ messages in thread
From: Bernt Hansen @ 2011-08-04 23:07 UTC (permalink / raw)
  To: David Maus; +Cc: emacs-orgmode, Jason Dunsmore

David Maus <dmaus@ictsoc.de> writes:

> At Thu, 04 Aug 2011 09:35:24 -0500,
> Jason Dunsmore wrote:

>> I just tried out your patch.  The logic in your patch is slightly
>> different - it checks if the point is at the end of the last line in the
>> buffer, whereas mine checks if the point is anywhere on the last line.
>> I don't think it fixes the problem.  Bernt, can you test it?
>
> I does it for me and should do the trick. I tracked down the problem
> to `org-copy-subtree' not beeing able to correctly determine the end
> of the subtree to copy.

David's patch works fine for me.  Thanks both.

Regards,
Bernt

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

* Re: Bug: Refile sometimes loses the last line [7.7 (release_7.7.15.gc363)]
  2011-08-04 14:07     ` David Maus
  2011-08-04 14:35       ` Jason Dunsmore
@ 2011-08-16 13:17       ` Bastien
  2011-08-16 16:19         ` Bastien
  1 sibling, 1 reply; 10+ messages in thread
From: Bastien @ 2011-08-16 13:17 UTC (permalink / raw)
  To: David Maus; +Cc: Bernt Hansen, emacs-orgmode, Jason Dunsmore

David Maus <dmaus@ictsoc.de> writes:

> I just pushed a simplified version of the solution: No need to count
> lines, just check if point is at end of buffer.

Thanks for your this fix!

-- 
 Bastien

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

* Re: Bug: Refile sometimes loses the last line [7.7 (release_7.7.15.gc363)]
  2011-08-16 13:17       ` Bastien
@ 2011-08-16 16:19         ` Bastien
  2011-08-16 17:18           ` Achim Gratz
  0 siblings, 1 reply; 10+ messages in thread
From: Bastien @ 2011-08-16 16:19 UTC (permalink / raw)
  To: David Maus; +Cc: Bernt Hansen, emacs-orgmode, Jason Dunsmore

Bastien <bzg@altern.org> writes:

> David Maus <dmaus@ictsoc.de> writes:
>
>> I just pushed a simplified version of the solution: No need to count
>> lines, just check if point is at end of buffer.
>
> Thanks for your this fix!

Wow, how can someone munge his words so badly? :)

-- 
 Bastien

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

* Re: Bug: Refile sometimes loses the last line [7.7 (release_7.7.15.gc363)]
  2011-08-16 16:19         ` Bastien
@ 2011-08-16 17:18           ` Achim Gratz
  0 siblings, 0 replies; 10+ messages in thread
From: Achim Gratz @ 2011-08-16 17:18 UTC (permalink / raw)
  To: emacs-orgmode

Bastien <bzg@altern.org> writes:
> Wow, how can someone munge his words so badly? :)

In the force if Yoda's so strong, construct a sentence
with words in the proper order then why can't he?


Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

SD adaptations for Waldorf Q V3.00R3 and Q+ V3.54R2:
http://Synth.Stromeko.net/Downloads.html#WaldorfSDada

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

end of thread, other threads:[~2011-08-16 17:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-01  4:18 Bug: Refile sometimes loses the last line [7.7 (release_7.7.15.gc363)] Bernt Hansen
2011-08-03 15:05 ` Jason Dunsmore
2011-08-04  1:35   ` Bernt Hansen
2011-08-04 14:07     ` David Maus
2011-08-04 14:35       ` Jason Dunsmore
2011-08-04 15:46         ` David Maus
2011-08-04 23:07           ` Bernt Hansen
2011-08-16 13:17       ` Bastien
2011-08-16 16:19         ` Bastien
2011-08-16 17:18           ` Achim Gratz

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