emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* bug#12905: 24.2.50; org: edit source block causes data loss
       [not found] <50A62865.8010904@gmail.com>
@ 2012-12-07 15:36 ` Chong Yidong
       [not found] ` <87sj7han8a.fsf__16482.9143243425$1354894646$gmane$org@gnu.org>
  1 sibling, 0 replies; 29+ messages in thread
From: Chong Yidong @ 2012-12-07 15:36 UTC (permalink / raw)
  To: Bastien Guerry; +Cc: 12905

Hi Bastien,

Could you please take a look at Bug#12905?  If it causes data loss, I
think it should be fixed in the emacs-24 branch.  Thanks.

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

* bug#12905: 24.2.50; org: edit source block causes data loss
       [not found] ` <87sj7han8a.fsf__16482.9143243425$1354894646$gmane$org@gnu.org>
@ 2012-12-12 16:55   ` Bastien
  2012-12-12 21:05     ` Bernt Hansen
       [not found]   ` <87wqwnyzud.fsf@bzg.ath.cx>
  1 sibling, 1 reply; 29+ messages in thread
From: Bastien @ 2012-12-12 16:55 UTC (permalink / raw)
  To: Chong Yidong; +Cc: 12905-done

Hi Chong,

Chong Yidong <cyd@gnu.org> writes:

> Could you please take a look at Bug#12905?  If it causes data loss, I
> think it should be fixed in the emacs-24 branch.  Thanks.

This is fixed, thanks for the heads up.

I just merged the Org bugfix branch into emacs-24.

I made one mistake: I backported Paul's fixes about whitespaces in 
our bugfix branch*, so those fixes are now in emacs-24 too, not in 
the trunk only.  I hope this won't create merge conflicts.

* http://orgmode.org/cgit.cgi/org-mode.git/commit/?h=maint&id=e5ea08

-- 
 Bastien

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

* bug#12905: 24.2.50; org: edit source block causes data loss
       [not found]   ` <87wqwnyzud.fsf@bzg.ath.cx>
@ 2012-12-12 17:39     ` Andy Moreton
  0 siblings, 0 replies; 29+ messages in thread
From: Andy Moreton @ 2012-12-12 17:39 UTC (permalink / raw)
  To: 12905

On Wed 12 Dec 2012, Bastien wrote:

> This is fixed, thanks for the heads up.
>
> I just merged the Org bugfix branch into emacs-24.

I can confirm the bug is fixed for emacs-24 after this merge.

Thanks Bastien,

    AndyM

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-12 16:55   ` Bastien
@ 2012-12-12 21:05     ` Bernt Hansen
  2012-12-12 21:34       ` Jonathan Leech-Pepin
  2012-12-12 23:18       ` Bastien
  0 siblings, 2 replies; 29+ messages in thread
From: Bernt Hansen @ 2012-12-12 21:05 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

Hi Bastien,

I'm not sure if this is related or not - I don't have time to track down
the offending commit right now.

org-edit-special (C-c ') is currently broken in master.

I get the following backtrace

--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
  copy-marker(nil t)
  org-edit-src-code()
  org-edit-special()
  call-interactively(org-edit-special nil nil)
--8<---------------cut here---------------end--------------->8---

GNU Emacs 23.2.1 (i486-pc-linux-gnu, GTK+ Version 2.20.0) of 2010-12-11
on raven, modified by Debian

Org-mode version 7.9.2 (release_7.9.2-664-gb1f369 @
/home/bernt/git/org-mode/lisp/)

Thanks,
Bernt


Bastien <bzg@altern.org> writes:

> Hi Chong,
>
> Chong Yidong <cyd@gnu.org> writes:
>
>> Could you please take a look at Bug#12905?  If it causes data loss, I
>> think it should be fixed in the emacs-24 branch.  Thanks.
>
> This is fixed, thanks for the heads up.
>
> I just merged the Org bugfix branch into emacs-24.
>
> I made one mistake: I backported Paul's fixes about whitespaces in 
> our bugfix branch*, so those fixes are now in emacs-24 too, not in 
> the trunk only.  I hope this won't create merge conflicts.
>
> * http://orgmode.org/cgit.cgi/org-mode.git/commit/?h=maint&id=e5ea08

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-12 21:05     ` Bernt Hansen
@ 2012-12-12 21:34       ` Jonathan Leech-Pepin
  2012-12-12 21:51         ` Bernt Hansen
  2012-12-12 23:18       ` Bastien
  1 sibling, 1 reply; 29+ messages in thread
From: Jonathan Leech-Pepin @ 2012-12-12 21:34 UTC (permalink / raw)
  To: Bernt Hansen; +Cc: Bastien, Org Mode Mailing List

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

On 12 December 2012 16:05, Bernt Hansen <bernt@norang.ca> wrote:

> Hi Bastien,
>
> I'm not sure if this is related or not - I don't have time to track down
> the offending commit right now.
>
> org-edit-special (C-c ') is currently broken in master.
>
>
I get the same thing when trying (C-c ') on the #+begin_src line.  When
trying
it within the body of the source block it works properly

> I get the following backtrace
>
> --8<---------------cut here---------------start------------->8---
> Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
>   copy-marker(nil t)
>   org-edit-src-code()
>   org-edit-special()
>   call-interactively(org-edit-special nil nil)
> --8<---------------cut here---------------end--------------->8---
>
> GNU Emacs 23.2.1 (i486-pc-linux-gnu, GTK+ Version 2.20.0) of 2010-12-11
> on raven, modified by Debian
>
> Org-mode version 7.9.2 (release_7.9.2-664-gb1f369 @
> /home/bernt/git/org-mode/lisp/)
>
> Thanks,
> Bernt
>
>
Regards,
Jon

>
> Bastien <bzg@altern.org> writes:
>
> > Hi Chong,
> >
> > Chong Yidong <cyd@gnu.org> writes:
> >
> >> Could you please take a look at Bug#12905?  If it causes data loss, I
> >> think it should be fixed in the emacs-24 branch.  Thanks.
> >
> > This is fixed, thanks for the heads up.
> >
> > I just merged the Org bugfix branch into emacs-24.
> >
> > I made one mistake: I backported Paul's fixes about whitespaces in
> > our bugfix branch*, so those fixes are now in emacs-24 too, not in
> > the trunk only.  I hope this won't create merge conflicts.
> >
> > * http://orgmode.org/cgit.cgi/org-mode.git/commit/?h=maint&id=e5ea08
>
>

[-- Attachment #2: Type: text/html, Size: 2745 bytes --]

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-12 21:34       ` Jonathan Leech-Pepin
@ 2012-12-12 21:51         ` Bernt Hansen
  0 siblings, 0 replies; 29+ messages in thread
From: Bernt Hansen @ 2012-12-12 21:51 UTC (permalink / raw)
  To: Jonathan Leech-Pepin; +Cc: Bastien, Org Mode Mailing List

For me it occurs both inside the block (begin_src or begin_example) and
on the first line.

Regards,
Bernt

Jonathan Leech-Pepin <jonathan.leechpepin@gmail.com> writes:

> On 12 December 2012 16:05, Bernt Hansen <bernt@norang.ca> wrote:
>
>     Hi Bastien,
>    
>     I'm not sure if this is related or not - I don't have time to track down
>     the offending commit right now.
>    
>     org-edit-special (C-c ') is currently broken in master.
>
> I get the same thing when trying (C-c ') on the #+begin_src line.  When trying
> it within the body of the source block it works properly
>
>     I get the following backtrace
>    
>     --8<---------------cut here---------------start------------->8---
>     Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
>       copy-marker(nil t)
>       org-edit-src-code()
>       org-edit-special()
>       call-interactively(org-edit-special nil nil)
>     --8<---------------cut here---------------end--------------->8---
>    
>     GNU Emacs 23.2.1 (i486-pc-linux-gnu, GTK+ Version 2.20.0) of 2010-12-11
>     on raven, modified by Debian
>    
>     Org-mode version 7.9.2 (release_7.9.2-664-gb1f369 @
>     /home/bernt/git/org-mode/lisp/)
>    
>     Thanks,
>     Bernt
>
> Regards,
> Jon
>
>     Bastien <bzg@altern.org> writes:
>    
>     > Hi Chong,
>     >
>     > Chong Yidong <cyd@gnu.org> writes:
>     >
>     >> Could you please take a look at Bug#12905?  If it causes data loss, I
>     >> think it should be fixed in the emacs-24 branch.  Thanks.
>     >
>     > This is fixed, thanks for the heads up.
>     >
>     > I just merged the Org bugfix branch into emacs-24.
>     >
>     > I made one mistake: I backported Paul's fixes about whitespaces in
>     > our bugfix branch*, so those fixes are now in emacs-24 too, not in
>     > the trunk only.  I hope this won't create merge conflicts.
>     >
>     > * http://orgmode.org/cgit.cgi/org-mode.git/commit/?h=maint&id=e5ea08

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-12 21:05     ` Bernt Hansen
  2012-12-12 21:34       ` Jonathan Leech-Pepin
@ 2012-12-12 23:18       ` Bastien
  2012-12-13  3:27         ` Bernt Hansen
  1 sibling, 1 reply; 29+ messages in thread
From: Bastien @ 2012-12-12 23:18 UTC (permalink / raw)
  To: Bernt Hansen; +Cc: emacs-orgmode

Hi Bernt,

Bernt Hansen <bernt@norang.ca> writes:

> I'm not sure if this is related or not - I don't have time to track down
> the offending commit right now.

There is nothing new regarding editing source code in master, 
except Eric's last few patches.

> org-edit-special (C-c ') is currently broken in master.
>
> I get the following backtrace

Mhh.. I can't reproduce this.

> Org-mode version 7.9.2 (release_7.9.2-664-gb1f369 @
> /home/bernt/git/org-mode/lisp/)

I'm on release_7.9.2-692-g627d57
                     ^^^

Are you sure you are using master HEAD?

Thanks,

-- 
 Bastien

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-12 23:18       ` Bastien
@ 2012-12-13  3:27         ` Bernt Hansen
  2012-12-13  3:37           ` Bernt Hansen
  0 siblings, 1 reply; 29+ messages in thread
From: Bernt Hansen @ 2012-12-13  3:27 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

Bastien <bzg@altern.org> writes:

> Hi Bernt,
>
> Bernt Hansen <bernt@norang.ca> writes:
>
>> I'm not sure if this is related or not - I don't have time to track down
>> the offending commit right now.
>
> There is nothing new regarding editing source code in master, 
> except Eric's last few patches.
>
>> org-edit-special (C-c ') is currently broken in master.
>>
>> I get the following backtrace
>
> Mhh.. I can't reproduce this.
>
>> Org-mode version 7.9.2 (release_7.9.2-664-gb1f369 @
>> /home/bernt/git/org-mode/lisp/)
>
> I'm on release_7.9.2-692-g627d57
>                      ^^^
>
> Are you sure you are using master HEAD?

I think so.  I just updated and have the same behaviour

Org-mode version 7.9.2 (release_7.9.2-693-g8c04fb @
/home/bernt/git/org-mode/lisp/)

I'll try and locate the problem commit.

Regards,
Bernt

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-13  3:27         ` Bernt Hansen
@ 2012-12-13  3:37           ` Bernt Hansen
  2012-12-13  4:50             ` Nick Dokos
  2012-12-13 10:36             ` Bastien
  0 siblings, 2 replies; 29+ messages in thread
From: Bernt Hansen @ 2012-12-13  3:37 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

Bernt Hansen <bernt@norang.ca> writes:

> Bastien <bzg@altern.org> writes:
>
>> Hi Bernt,
>>
>> Bernt Hansen <bernt@norang.ca> writes:
>>
>>> I'm not sure if this is related or not - I don't have time to track down
>>> the offending commit right now.
>>
>> There is nothing new regarding editing source code in master, 
>> except Eric's last few patches.
>>
>>> org-edit-special (C-c ') is currently broken in master.
>>>
>>> I get the following backtrace
>>
>> Mhh.. I can't reproduce this.
>>
>>> Org-mode version 7.9.2 (release_7.9.2-664-gb1f369 @
>>> /home/bernt/git/org-mode/lisp/)
>>
>> I'm on release_7.9.2-692-g627d57
>>                      ^^^
>>
>> Are you sure you are using master HEAD?
>
> I think so.  I just updated and have the same behaviour
>
> Org-mode version 7.9.2 (release_7.9.2-693-g8c04fb @
> /home/bernt/git/org-mode/lisp/)
>
> I'll try and locate the problem commit.

git bisect identifies the following commit:

--8<---------------cut here---------------start------------->8---
206257aa7eb83a0a62f297e7cf0e3a7c32ff6f05 is the first bad commit
commit 206257aa7eb83a0a62f297e7cf0e3a7c32ff6f05
Author: Le Wang <le.wang@agworld.com.au>
Date:   Sun Nov 18 13:39:51 2012 +0800

    org-src: Fix org-edit-src-code for empty blocks and block with just an empty line
    
    * lisp/org-src.el (org-edit-src-code): Use marker with insertion type
    t to track end and remove hack requiring delete from beg to (1- end).

:040000 040000 91825ba365592800804e652e3ad66db0f8302772 25f089bf9456b306afd2a0e538bcbfefc4a124f0 M	lisp
--8<---------------cut here---------------end--------------->8---

I'm just trying to edit a lisp source block

--8<---------------cut here---------------start------------->8---
* test
[2012-12-09 Sun 20:53]

#+begin_src lisp
(defun bh/show-org-agenda ()
  (interactive)
  (switch-to-buffer "*Org Agenda*")
  (delete-other-windows))

; Use the current window for C-c ' source editing
(setq org-src-window-setup 'current-window)

#+end_src
--8<---------------cut here---------------end--------------->8---

using C-c ' inside the block.

Reverting this commit fixes it for me.

Regards,
Bernt

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-13  3:37           ` Bernt Hansen
@ 2012-12-13  4:50             ` Nick Dokos
  2012-12-13 12:45               ` Bernt Hansen
  2012-12-13 10:36             ` Bastien
  1 sibling, 1 reply; 29+ messages in thread
From: Nick Dokos @ 2012-12-13  4:50 UTC (permalink / raw)
  To: Bernt Hansen; +Cc: Bastien, emacs-orgmode

Bernt Hansen <bernt@norang.ca> wrote:

> Bernt Hansen <bernt@norang.ca> writes:
> 
> > Bastien <bzg@altern.org> writes:
> >
> >> Hi Bernt,
> >>
> >> Bernt Hansen <bernt@norang.ca> writes:
> >>
> >>> I'm not sure if this is related or not - I don't have time to track down
> >>> the offending commit right now.
> >>
> >> There is nothing new regarding editing source code in master, 
> >> except Eric's last few patches.
> >>
> >>> org-edit-special (C-c ') is currently broken in master.
> >>>
> >>> I get the following backtrace
> >>
> >> Mhh.. I can't reproduce this.
> >>
> >>> Org-mode version 7.9.2 (release_7.9.2-664-gb1f369 @
> >>> /home/bernt/git/org-mode/lisp/)
> >>
> >> I'm on release_7.9.2-692-g627d57
> >>                      ^^^
> >>
> >> Are you sure you are using master HEAD?
> >
> > I think so.  I just updated and have the same behaviour
> >
> > Org-mode version 7.9.2 (release_7.9.2-693-g8c04fb @
> > /home/bernt/git/org-mode/lisp/)
> >
> > I'll try and locate the problem commit.
> 
> git bisect identifies the following commit:
> 
> 206257aa7eb83a0a62f297e7cf0e3a7c32ff6f05 is the first bad commit
> commit 206257aa7eb83a0a62f297e7cf0e3a7c32ff6f05
> Author: Le Wang <le.wang@agworld.com.au>
> Date:   Sun Nov 18 13:39:51 2012 +0800
> 
>     org-src: Fix org-edit-src-code for empty blocks and block with just an empty line
>     
>     * lisp/org-src.el (org-edit-src-code): Use marker with insertion type
>     t to track end and remove hack requiring delete from beg to (1- end).
> 
> :040000 040000 91825ba365592800804e652e3ad66db0f8302772 25f089bf9456b306afd2a0e538bcbfefc4a124f0 M	lisp
> 
> I'm just trying to edit a lisp source block
> 
> * test
> [2012-12-09 Sun 20:53]
> 
> #+begin_src lisp
> (defun bh/show-org-agenda ()
>   (interactive)
>   (switch-to-buffer "*Org Agenda*")
>   (delete-other-windows))
> 
> ; Use the current window for C-c ' source editing
> (setq org-src-window-setup 'current-window)
> 
> #+end_src
> 
> using C-c ' inside the block.
> 
> Reverting this commit fixes it for me.
> 

FWIW, I cannot reproduce this and I do have the commit you fingered in my
tree. Could it be the emacs version that makes a difference here?

Mine is

GNU Emacs 24.2.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.4) of 2012-09-21

Nick

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-13  3:37           ` Bernt Hansen
  2012-12-13  4:50             ` Nick Dokos
@ 2012-12-13 10:36             ` Bastien
  2012-12-13 13:42               ` Bernt Hansen
  2012-12-13 13:48               ` Bernt Hansen
  1 sibling, 2 replies; 29+ messages in thread
From: Bastien @ 2012-12-13 10:36 UTC (permalink / raw)
  To: Bernt Hansen; +Cc: emacs-orgmode

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

Hi Bernt,

thanks for chasing this down.  I tried to install emacs-23.2 but 
it does not compile on my machine.

Does this patch fixes the problem for you?

My guess is that (copy-marker nil t) returns an error on emacs-23.2.
It's a weird sexp anyway, make-marker and set-marker-insertion-type 
are cleaner IMO.

Thanks for testing,


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-src.el.patch --]
[-- Type: text/x-patch, Size: 741 bytes --]

diff --git a/lisp/org-src.el b/lisp/org-src.el
index f91da19..d2c3e19 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -228,12 +228,11 @@ buffer."
 	 (full-info (org-babel-get-src-block-info 'light))
 	 (org-mode-p (derived-mode-p 'org-mode)) ;; derived-mode-p is reflexive
 	 (beg (make-marker))
-	 ;; Move marker with inserted text for case when src block is
-	 ;; just one empty line, i.e. beg == end.
-	 (end (copy-marker nil t))
+	 (end (make-marker))
 	 (allow-write-back-p (null code))
 	 block-nindent total-nindent ovl lang lang-f single lfmt buffer msg
 	 begline markline markcol line col transmitted-variables)
+    (set-marker-insertion-type end t)
     (if (not info)
 	nil
       (setq beg (move-marker beg (nth 0 info))

[-- Attachment #3: Type: text/plain, Size: 14 bytes --]


-- 
 Bastien

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-13  4:50             ` Nick Dokos
@ 2012-12-13 12:45               ` Bernt Hansen
  2012-12-13 13:41                 ` Bernt Hansen
  0 siblings, 1 reply; 29+ messages in thread
From: Bernt Hansen @ 2012-12-13 12:45 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: Bastien, emacs-orgmode

Nick Dokos <nicholas.dokos@hp.com> writes:

> Bernt Hansen <bernt@norang.ca> wrote:
>
>> git bisect identifies the following commit:
>> 
>> 206257aa7eb83a0a62f297e7cf0e3a7c32ff6f05 is the first bad commit
>> commit 206257aa7eb83a0a62f297e7cf0e3a7c32ff6f05
>> Author: Le Wang <le.wang@agworld.com.au>
>> Date:   Sun Nov 18 13:39:51 2012 +0800

<snip>

>> 
>> Reverting this commit fixes it for me.
>> 
>
> FWIW, I cannot reproduce this and I do have the commit you fingered in my
> tree. Could it be the emacs version that makes a difference here?
>
> Mine is
>
> GNU Emacs 24.2.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.4) of 2012-09-21
>
> Nick

Possibly, but this happens for me at work as well which is Windows 23.3
I think.

GNU Emacs 23.2.1 (i486-pc-linux-gnu, GTK+ Version 2.20.0) of 2010-12-11
on raven, modified by Debian

Bernt

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-13 12:45               ` Bernt Hansen
@ 2012-12-13 13:41                 ` Bernt Hansen
  0 siblings, 0 replies; 29+ messages in thread
From: Bernt Hansen @ 2012-12-13 13:41 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: Bastien, emacs-orgmode

Bernt Hansen <bernt@norang.ca> writes:

> Nick Dokos <nicholas.dokos@hp.com> writes:
>
>> Bernt Hansen <bernt@norang.ca> wrote:
>>
>>> git bisect identifies the following commit:
>>> 
>>> 206257aa7eb83a0a62f297e7cf0e3a7c32ff6f05 is the first bad commit
>>> commit 206257aa7eb83a0a62f297e7cf0e3a7c32ff6f05
>>> Author: Le Wang <le.wang@agworld.com.au>
>>> Date:   Sun Nov 18 13:39:51 2012 +0800
>
> <snip>
>
>>> 
>>> Reverting this commit fixes it for me.
>>> 
>>
>> FWIW, I cannot reproduce this and I do have the commit you fingered in my
>> tree. Could it be the emacs version that makes a difference here?
>>
>> Mine is
>>
>> GNU Emacs 24.2.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.4) of 2012-09-21
>>
>> Nick
>
> Possibly, but this happens for me at work as well which is Windows 23.3
> I think.

For the record, this is my emacs version at work with the same symptoms.

GNU Emacs 23.3.1 (i386-mingw-nt5.1.2600) of 2011-03-10 on 3249CTO 

Thanks,
Bernt

>
> GNU Emacs 23.2.1 (i486-pc-linux-gnu, GTK+ Version 2.20.0) of 2010-12-11
> on raven, modified by Debian
>
> Bernt

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-13 10:36             ` Bastien
@ 2012-12-13 13:42               ` Bernt Hansen
  2012-12-13 14:36                 ` Le Wang
  2012-12-13 13:48               ` Bernt Hansen
  1 sibling, 1 reply; 29+ messages in thread
From: Bernt Hansen @ 2012-12-13 13:42 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

Bastien <bzg@altern.org> writes:

> Hi Bernt,
>
> thanks for chasing this down.  I tried to install emacs-23.2 but 
> it does not compile on my machine.
>
> Does this patch fixes the problem for you?
>
> My guess is that (copy-marker nil t) returns an error on emacs-23.2.
> It's a weird sexp anyway, make-marker and set-marker-insertion-type 
> are cleaner IMO.
>
> Thanks for testing,

Thanks,

I'll try this patch and report back later today.

Regards,
Bernt

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-13 10:36             ` Bastien
  2012-12-13 13:42               ` Bernt Hansen
@ 2012-12-13 13:48               ` Bernt Hansen
  2012-12-13 16:05                 ` Bastien
  1 sibling, 1 reply; 29+ messages in thread
From: Bernt Hansen @ 2012-12-13 13:48 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

Bastien <bzg@altern.org> writes:

> Hi Bernt,
>
> thanks for chasing this down.  I tried to install emacs-23.2 but 
> it does not compile on my machine.
>
> Does this patch fixes the problem for you?
>
> My guess is that (copy-marker nil t) returns an error on emacs-23.2.
> It's a weird sexp anyway, make-marker and set-marker-insertion-type 
> are cleaner IMO.
>
> Thanks for testing,


Your patch fixes it for me on both versions (linux 23.2.1, windows
23.3.1)

Thanks!

Regards,
Bernt

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-13 13:42               ` Bernt Hansen
@ 2012-12-13 14:36                 ` Le Wang
  2012-12-13 15:17                   ` Bastien
  0 siblings, 1 reply; 29+ messages in thread
From: Le Wang @ 2012-12-13 14:36 UTC (permalink / raw)
  To: Bernt Hansen; +Cc: Bastien, emacs-orgmode

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

On Thu, Dec 13, 2012 at 9:42 PM, Bernt Hansen <bernt@norang.ca> wrote:
> I'll try this patch and report back later today.

That commit was from me, and I did not test against Emacs < 24.2.  I
will submit another patch to add some tests.  Do tests get
automatically run on some kind of Travis CI setup?

In the mean time, I think my included patch (logic identically to
Bastien's) is more lisp-ly.


-- 
Le

[-- Attachment #2: org-src.el.le.patch --]
[-- Type: application/octet-stream, Size: 566 bytes --]

diff --git a/lisp/org-src.el b/lisp/org-src.el
index f91da19..6515987 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -230,7 +230,9 @@ buffer."
 	 (beg (make-marker))
 	 ;; Move marker with inserted text for case when src block is
 	 ;; just one empty line, i.e. beg == end.
-	 (end (copy-marker nil t))
+	 (end (let ((marker (make-marker)))
+		(set-marker-insertion-type marker t)
+		marker))
 	 (allow-write-back-p (null code))
 	 block-nindent total-nindent ovl lang lang-f single lfmt buffer msg
 	 begline markline markcol line col transmitted-variables)

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-13 14:36                 ` Le Wang
@ 2012-12-13 15:17                   ` Bastien
  2012-12-13 16:06                     ` Le Wang
  0 siblings, 1 reply; 29+ messages in thread
From: Bastien @ 2012-12-13 15:17 UTC (permalink / raw)
  To: Le Wang; +Cc: Bernt Hansen, emacs-orgmode

Hi Le,

Le Wang <l26wang@gmail.com> writes:

> On Thu, Dec 13, 2012 at 9:42 PM, Bernt Hansen <bernt@norang.ca> wrote:
>> I'll try this patch and report back later today.
>
> That commit was from me, and I did not test against Emacs < 24.2.  I
> will submit another patch to add some tests.  Do tests get
> automatically run on some kind of Travis CI setup?

No we don't.  If anyone knows how to set this up for our needs,
please share.

> In the mean time, I think my included patch (logic identically to
> Bastien's) is more lisp-ly.

Whatever works -- we first need to make sure this fixes it and try 
to understand why ;)

Thanks for taking care of this,

-- 
 Bastien

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-13 13:48               ` Bernt Hansen
@ 2012-12-13 16:05                 ` Bastien
  2012-12-14  0:04                   ` Bernt Hansen
  0 siblings, 1 reply; 29+ messages in thread
From: Bastien @ 2012-12-13 16:05 UTC (permalink / raw)
  To: Bernt Hansen; +Cc: emacs-orgmode

Hi Bernt,

Bernt Hansen <bernt@norang.ca> writes:

> Your patch fixes it for me on both versions (linux 23.2.1, windows
> 23.3.1)
>
> Thanks!

I pushed the patch, thanks for confirming this.

PS: Le, I used my version, shorter, and not that unlispy IMO.
But thanks for the patch anyway!

-- 
 Bastien

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-13 15:17                   ` Bastien
@ 2012-12-13 16:06                     ` Le Wang
  2012-12-13 16:25                       ` Bastien
  0 siblings, 1 reply; 29+ messages in thread
From: Le Wang @ 2012-12-13 16:06 UTC (permalink / raw)
  To: Bastien; +Cc: Bernt Hansen, emacs-orgmode

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

On Thu, Dec 13, 2012 at 11:17 PM, Bastien <bzg@altern.org> wrote:
> Hi Le,
>
> No we don't.  If anyone knows how to set this up for our needs,
> please share.

I've only done this for projects hosted on github, others may have
more experience.  But having a continuous integration service is
definitely helpful.  For example, there were 10 failures when I ran
tests against master just now:

10 unexpected results:
   FAILED  ob-exp/exports-inline
   FAILED  ob-exp/noweb-strip-export-ensure-strips
   FAILED  test-ob/org-babel-remove-result--results-default
   FAILED  test-ob/org-babel-results-indented-wrap
   FAILED  test-org-babel/combining-scalar-and-raw-result-types
   FAILED  test-org-babel/inline-src-blocks
   FAILED  test-org-babel/inline-src_blk-default-results-replace-line-1
   FAILED  test-org-babel/just-one-results-block
   FAILED  test-org-babel/nested-code-block
   FAILED  test-org-babel/partial-nested-code-block

I haven't investigated further though.

> Whatever works -- we first need to make sure this fixes it and try
> to understand why ;)

I can confirm that copy-marker does not work as I've used it on Emacs 23.3.1.

> Thanks for taking care of this,

You're welcome.

I've attached 3 patches to fix this and another bug I found while writing tests.

-- 
Le

[-- Attachment #2: 0001-don-t-use-copy-marker-nil-t-for-Emacs-23-compat.patch --]
[-- Type: application/octet-stream, Size: 879 bytes --]

From 5b3e628b3bc8afd0c082faef059126b30d174d29 Mon Sep 17 00:00:00 2001
From: Le Wang <le.wang@agworld.com.au>
Date: Thu, 13 Dec 2012 23:40:59 +0800
Subject: [PATCH 1/3] don't use (copy-marker nil t) for Emacs 23 compat

---
 lisp/org-src.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index f91da19..6515987 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -230,7 +230,9 @@ buffer."
 	 (beg (make-marker))
 	 ;; Move marker with inserted text for case when src block is
 	 ;; just one empty line, i.e. beg == end.
-	 (end (copy-marker nil t))
+	 (end (let ((marker (make-marker)))
+		(set-marker-insertion-type marker t)
+		marker))
 	 (allow-write-back-p (null code))
 	 block-nindent total-nindent ovl lang lang-f single lfmt buffer msg
 	 begline markline markcol line col transmitted-variables)
-- 
1.7.11.4


[-- Attachment #3: 0002-fix-org-edit-src-code-invoked-outside-src-block.patch --]
[-- Type: application/octet-stream, Size: 1027 bytes --]

From 2e6dd57930dcb5b57d567855d0834df50de7e89e Mon Sep 17 00:00:00 2001
From: Le Wang <le.wang@agworld.com.au>
Date: Thu, 13 Dec 2012 23:46:00 +0800
Subject: [PATCH 2/3] fix org-edit-src-code invoked outside src block

---
 lisp/org-src.el | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index 6515987..97f473a 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -221,10 +221,13 @@ buffer."
 	  (let* ((temp (org-edit-src-find-region-and-lang))
 		 (beg (nth 0 temp))
 		 (end (nth 1 temp)))
-	    (if (>= end beg) temp
-	      (goto-char beg)
-	      (insert "\n")
-	      (org-edit-src-find-region-and-lang))))
+	    (if (and beg end)
+		(if (>= end beg)
+		    temp
+		  (goto-char beg)
+		  (insert "\n")
+		  (org-edit-src-find-region-and-lang))
+	      (error "Point not in src block."))))
 	 (full-info (org-babel-get-src-block-info 'light))
 	 (org-mode-p (derived-mode-p 'org-mode)) ;; derived-mode-p is reflexive
 	 (beg (make-marker))
-- 
1.7.11.4


[-- Attachment #4: 0003-add-tests-for-org-src-edit.patch --]
[-- Type: application/octet-stream, Size: 2964 bytes --]

From 3299e5ce8cac9f3a0cbd912020955fc502d5ada7 Mon Sep 17 00:00:00 2001
From: Le Wang <le.wang@agworld.com.au>
Date: Thu, 13 Dec 2012 23:46:40 +0800
Subject: [PATCH 3/3] add tests for org-src-edit

---
 testing/lisp/test-org-src.el | 98 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)
 create mode 100644 testing/lisp/test-org-src.el

diff --git a/testing/lisp/test-org-src.el b/testing/lisp/test-org-src.el
new file mode 100644
index 0000000..42b0f9e
--- /dev/null
+++ b/testing/lisp/test-org-src.el
@@ -0,0 +1,98 @@
+;;; test-org-src.el --- Tests for org-src.el
+
+;; Copyright (C) 2012  Le Wang
+
+;; Author: Le Wang <l26wang at gmail dot com>
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+
+(require 'org-test)
+
+\f
+
+(ert-deftest test-org-src/basic ()
+  "Editing regular block works. with point on
+
+#+begin_src line
+"
+  (org-test-with-temp-text
+   "
+#+begin_src emacs-lisp
+  (message hello)
+#+end_src
+"
+   (goto-line 2)
+   (org-edit-special)
+   (insert "blah")
+   (org-edit-src-exit)
+   (should (equal (buffer-string) "
+#+begin_src emacs-lisp
+  blah(message hello)
+#+end_src
+"))
+   (should (equal (word-at-point) "blah"))))
+
+(ert-deftest test-org-src/point-outside-block ()
+  "Editing with point before/after block signals expected error."
+  (org-test-with-temp-text
+      "
+#+begin_src emacs-lisp
+  (message hello)
+#+end_src
+"
+    (goto-line 1)
+    (should-error (org-edit-special))
+    (goto-char (point-max))
+    (should-error (org-edit-special))))
+
+(ert-deftest test-org-src/empty-block ()
+  "Editing empty block."
+  (org-test-with-temp-text
+      "
+#+begin_src emacs-lisp
+#+end_src
+"
+    (goto-line 2)
+    (org-edit-special)
+    (insert "blah")
+    (org-edit-src-exit)
+    (should (equal (buffer-string) "
+#+begin_src emacs-lisp
+  blah
+#+end_src
+"))
+    (should (equal (word-at-point) "blah"))))
+
+(ert-deftest test-org-src/blank-line-block ()
+  "Editing block with just a blank line."
+  (org-test-with-temp-text
+      "
+#+begin_src emacs-lisp
+
+#+end_src
+"
+    (goto-line 3)
+    (org-edit-special)
+    (insert "blah")
+    (org-edit-src-exit)
+    (should (equal (buffer-string) "
+#+begin_src emacs-lisp
+  blah
+#+end_src
+"))
+    (should (equal (word-at-point) "blah"))))
+
+(provide 'test-org-src)
+;;; test-org-src.el ends here
-- 
1.7.11.4


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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-13 16:06                     ` Le Wang
@ 2012-12-13 16:25                       ` Bastien
  2012-12-13 23:40                         ` Le Wang
  0 siblings, 1 reply; 29+ messages in thread
From: Bastien @ 2012-12-13 16:25 UTC (permalink / raw)
  To: Le Wang; +Cc: Bernt Hansen, emacs-orgmode

Le Wang <l26wang@gmail.com> writes:

> I haven't investigated further though.

We can easily setup a mirror on github and use the platform
from this repo.  But I'm unsure how this would work.  If someone
wants to take this in charge, let me know.

> I've attached 3 patches to fix this and another bug I found while
> writing tests.

Ah, our patches crossed.

I superseded the first one with my patch, and just applied the 
third one.  

Can you explain the bug behind the second one?

Thanks!

-- 
 Bastien

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-13 16:25                       ` Bastien
@ 2012-12-13 23:40                         ` Le Wang
  2012-12-13 23:50                           ` Le Wang
                                             ` (3 more replies)
  0 siblings, 4 replies; 29+ messages in thread
From: Le Wang @ 2012-12-13 23:40 UTC (permalink / raw)
  To: Bastien; +Cc: Bernt Hansen, emacs-orgmode

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

On Fri, Dec 14, 2012 at 12:25 AM, Bastien <bzg@altern.org> wrote:
> I superseded the first one with my patch, and just applied the
> third one.
>
> Can you explain the bug behind the second one?


If I press C-' before on a line BEFORE "+begin_src ...", then doing
comparison with ">=" with beg==nil and end==nil causes
"wrong-type-argument" error.

"test-org-src/point-outside-block" test case should fail, but because
"wrong-type-argument" is also an error, it is passing.  :(

I've changed "(error ..." to raise an org-src specific error to
facilitate testing.  Commits rebased to master are attached.

A note:

I did change this line:

    (end (copy-marker (make-marker) t))

(make-marker) makes a temporary new marker that's never used.  ;)


-- 
Le

[-- Attachment #2: 0001-don-t-use-copy-marker-nil-t-for-Emacs-23-compat.patch --]
[-- Type: application/octet-stream, Size: 889 bytes --]

From 1b55d713a60a3b61b4af6bb314c0bcfb780d3b34 Mon Sep 17 00:00:00 2001
From: Le Wang <le.wang@agworld.com.au>
Date: Thu, 13 Dec 2012 23:40:59 +0800
Subject: [PATCH 1/5] don't use (copy-marker nil t) for Emacs 23 compat

---
 lisp/org-src.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index 188f9d2..6515987 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -230,7 +230,9 @@ buffer."
 	 (beg (make-marker))
 	 ;; Move marker with inserted text for case when src block is
 	 ;; just one empty line, i.e. beg == end.
-	 (end (copy-marker (make-marker) t))
+	 (end (let ((marker (make-marker)))
+		(set-marker-insertion-type marker t)
+		marker))
 	 (allow-write-back-p (null code))
 	 block-nindent total-nindent ovl lang lang-f single lfmt buffer msg
 	 begline markline markcol line col transmitted-variables)
-- 
1.7.11.4


[-- Attachment #3: 0002-fix-org-edit-src-code-invoked-outside-src-block.patch --]
[-- Type: application/octet-stream, Size: 1027 bytes --]

From 2e19391476b76263dcbc0cf73e5ee1d0b260ddf3 Mon Sep 17 00:00:00 2001
From: Le Wang <le.wang@agworld.com.au>
Date: Thu, 13 Dec 2012 23:46:00 +0800
Subject: [PATCH 2/5] fix org-edit-src-code invoked outside src block

---
 lisp/org-src.el | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index 6515987..97f473a 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -221,10 +221,13 @@ buffer."
 	  (let* ((temp (org-edit-src-find-region-and-lang))
 		 (beg (nth 0 temp))
 		 (end (nth 1 temp)))
-	    (if (>= end beg) temp
-	      (goto-char beg)
-	      (insert "\n")
-	      (org-edit-src-find-region-and-lang))))
+	    (if (and beg end)
+		(if (>= end beg)
+		    temp
+		  (goto-char beg)
+		  (insert "\n")
+		  (org-edit-src-find-region-and-lang))
+	      (error "Point not in src block."))))
 	 (full-info (org-babel-get-src-block-info 'light))
 	 (org-mode-p (derived-mode-p 'org-mode)) ;; derived-mode-p is reflexive
 	 (beg (make-marker))
-- 
1.7.11.4


[-- Attachment #4: 0003-test-org-src-checks-for-org-src-generated-error.patch --]
[-- Type: application/octet-stream, Size: 960 bytes --]

From a4cf5825f49a30664ca95b6794200f32e94424d8 Mon Sep 17 00:00:00 2001
From: Le Wang <le.wang@agworld.com.au>
Date: Fri, 14 Dec 2012 06:51:31 +0800
Subject: [PATCH 3/5] test-org-src checks for org-src generated error

- We need to check the error raised is not a generic error, but the one
  we expect our code to generate.
---
 testing/lisp/test-org-src.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/testing/lisp/test-org-src.el b/testing/lisp/test-org-src.el
index 8205fd1..65d52d3 100644
--- a/testing/lisp/test-org-src.el
+++ b/testing/lisp/test-org-src.el
@@ -56,9 +56,9 @@
 #+end_src
 "
     (goto-line 1)
-    (should-error (org-edit-special))
+    (should-error (org-edit-special) :type '(org-src-error))
     (goto-char (point-max))
-    (should-error (org-edit-special))))
+    (should-error (org-edit-special) :type '(org-src-error))))
 
 (ert-deftest test-org-src/empty-block ()
   "Editing empty block."
-- 
1.7.11.4


[-- Attachment #5: 0004-add-org-src-error-error-condition.patch --]
[-- Type: application/octet-stream, Size: 2793 bytes --]

From f8c4bee3a4223d77f44c961c4eab9afa4cb1345b Mon Sep 17 00:00:00 2001
From: Le Wang <le.wang@agworld.com.au>
Date: Fri, 14 Dec 2012 06:46:15 +0800
Subject: [PATCH 4/5] add org-src-error error-condition

- This makes code more testable, because we can expect org specific
  errors instead of the generic error.
---
 lisp/org-src.el | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index 97f473a..ad6ec60 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -192,6 +192,11 @@ the existing edit buffer.")
 
 (defvar org-src-babel-info nil)
 
+(put 'org-src-error
+     'error-conditions
+     '(error org-src-error))
+(put 'org-src-error 'error-message "Org Src Error")
+
 (define-minor-mode org-src-mode
   "Minor mode for language major mode buffers generated by org.
 This minor mode is turned on in two situations:
@@ -227,7 +232,7 @@ buffer."
 		  (goto-char beg)
 		  (insert "\n")
 		  (org-edit-src-find-region-and-lang))
-	      (error "Point not in src block."))))
+	      (signal 'org-src-error '("Point not in src block.")))))
 	 (full-info (org-babel-get-src-block-info 'light))
 	 (org-mode-p (derived-mode-p 'org-mode)) ;; derived-mode-p is reflexive
 	 (beg (make-marker))
@@ -280,7 +285,7 @@ buffer."
 			 (table-recognize)
 			 (org-set-local 'org-edit-src-content-indentation 0))))
       (unless (functionp lang-f)
-	(error "No such language mode: %s" lang-f))
+	(signal 'org-src-error "No such language mode: %s" lang-f))
       (save-excursion
 	(if (> (point) end) (goto-char end))
 	(setq line (org-current-line)
@@ -322,7 +327,7 @@ buffer."
 	  (condition-case e
 	      (funcall lang-f)
 	    (error
-	     (error "Language mode `%s' fails with: %S" lang-f (nth 1 e)))))
+	     (signal 'org-src-error "Language mode `%s' fails with: %S" lang-f (nth 1 e)))))
 	(dolist (pair transmitted-variables)
 	  (org-set-local (car pair) (cadr pair)))
 	;; Remove protecting commas from visible part of buffer.
@@ -353,7 +358,7 @@ buffer."
   (mouse-set-point e)
   (let ((buf (get-char-property (point) 'edit-buffer)))
     (if buf (org-src-switch-to-buffer buf 'continue)
-      (error "Something is wrong here"))))
+      (signal 'org-src-error "Something is wrong here"))))
 
 (defun org-src-switch-to-buffer (buffer context)
   (case org-src-window-setup
@@ -636,7 +641,7 @@ with \",*\", \",#+\", \",,*\" and \",,#+\"."
   "Exit special edit and protect problematic lines."
   (interactive)
   (unless (org-bound-and-true-p org-edit-src-from-org-mode)
-    (error "This is not a sub-editing buffer, something is wrong"))
+    (signal 'org-src-error "This is not a sub-editing buffer, something is wrong"))
   (widen)
   (let* ((beg org-edit-src-beg-marker)
 	 (end org-edit-src-end-marker)
-- 
1.7.11.4


[-- Attachment #6: 0005-remove-extraneous-if-condition.patch --]
[-- Type: application/octet-stream, Size: 9852 bytes --]

From 949b2cd4c378872345f3f3a026beb5d1a228288d Mon Sep 17 00:00:00 2001
From: Le Wang <le.wang@agworld.com.au>
Date: Fri, 14 Dec 2012 07:31:15 +0800
Subject: [PATCH 5/5] remove extraneous if condition

- We signal org-src-error before ever reaching here.
---
 lisp/org-src.el | 210 ++++++++++++++++++++++++++++----------------------------
 1 file changed, 104 insertions(+), 106 deletions(-)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index ad6ec60..d4747ab 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -244,113 +244,111 @@ buffer."
 	 (allow-write-back-p (null code))
 	 block-nindent total-nindent ovl lang lang-f single lfmt buffer msg
 	 begline markline markcol line col transmitted-variables)
-    (if (not info)
-	nil
-      (setq beg (move-marker beg (nth 0 info))
-	    end (move-marker end (nth 1 info))
-	    msg (if allow-write-back-p
-		    (substitute-command-keys
-		     "Edit, then exit with C-c ' (C-c and single quote)")
-		  "Exit with C-c ' (C-c and single quote)")
-	    code (or code (buffer-substring-no-properties beg end))
-	    lang (or (cdr (assoc (nth 2 info) org-src-lang-modes))
-                     (nth 2 info))
-	    lang (if (symbolp lang) (symbol-name lang) lang)
-	    single (nth 3 info)
-	    block-nindent (nth 5 info)
-	    lang-f (intern (concat lang "-mode"))
-	    begline (save-excursion (goto-char beg) (org-current-line))
-	    transmitted-variables
-	    `((org-edit-src-content-indentation
-	       ,org-edit-src-content-indentation)
-	      (org-edit-src-force-single-line ,single)
-	      (org-edit-src-from-org-mode ,org-mode-p)
-	      (org-edit-src-allow-write-back-p ,allow-write-back-p)
-	      (org-src-preserve-indentation ,org-src-preserve-indentation)
-	      (org-src-babel-info ,(org-babel-get-src-block-info 'light))
-	      (org-coderef-label-format
-	       ,(or (nth 4 info) org-coderef-label-format))
-	      (org-edit-src-beg-marker ,beg)
-	      (org-edit-src-end-marker ,end)
-	      (org-edit-src-block-indentation ,block-nindent)))
-      (if (and mark (>= mark beg) (<= mark (1+ end)))
-	  (save-excursion (goto-char (min mark end))
-			  (setq markline (org-current-line)
-				markcol (current-column))))
-      (if (equal lang-f 'table.el-mode)
-	  (setq lang-f (lambda ()
-			 (text-mode)
-			 (if (org-bound-and-true-p flyspell-mode)
-			     (flyspell-mode -1))
-			 (table-recognize)
-			 (org-set-local 'org-edit-src-content-indentation 0))))
-      (unless (functionp lang-f)
-	(signal 'org-src-error "No such language mode: %s" lang-f))
-      (save-excursion
-	(if (> (point) end) (goto-char end))
-	(setq line (org-current-line)
-	      col (current-column)))
-      (if (and (setq buffer (org-edit-src-find-buffer beg end))
-	       (or (eq context 'save)
-		   (if org-src-ask-before-returning-to-edit-buffer
-		       (y-or-n-p "Return to existing edit buffer ([n] will revert changes)? ") t)))
-	  (org-src-switch-to-buffer buffer 'return)
-	(when buffer
-	  (with-current-buffer buffer
-	    (if (boundp 'org-edit-src-overlay)
-		(delete-overlay org-edit-src-overlay)))
-	  (kill-buffer buffer))
-	(setq buffer (generate-new-buffer
-		      (or edit-buffer-name
-			  (org-src-construct-edit-buffer-name (buffer-name) lang))))
-	(setq ovl (make-overlay beg end))
-	(overlay-put ovl 'edit-buffer buffer)
-	(overlay-put ovl 'help-echo "Click with mouse-1 to switch to buffer editing this segment")
-	(overlay-put ovl 'face 'secondary-selection)
-	(overlay-put ovl
-		     'keymap
-		     (let ((map (make-sparse-keymap)))
-		       (define-key map [mouse-1] 'org-edit-src-continue)
-		       map))
-	(overlay-put ovl :read-only "Leave me alone")
-	(setq transmitted-variables
-	      (append transmitted-variables `((org-edit-src-overlay ,ovl))))
-	(org-src-switch-to-buffer buffer 'edit)
-	(if (eq single 'macro-definition)
-	    (setq code (replace-regexp-in-string "\\\\n" "\n" code t t)))
-	(insert code)
-	(remove-text-properties (point-min) (point-max)
-				'(display nil invisible nil intangible nil))
-	(unless (cadr (assq 'org-src-preserve-indentation transmitted-variables))
-	  (setq total-nindent (or (org-do-remove-indentation) 0)))
-	(let ((org-inhibit-startup t))
-	  (condition-case e
-	      (funcall lang-f)
-	    (error
-	     (signal 'org-src-error "Language mode `%s' fails with: %S" lang-f (nth 1 e)))))
-	(dolist (pair transmitted-variables)
-	  (org-set-local (car pair) (cadr pair)))
-	;; Remove protecting commas from visible part of buffer.
-	(org-unescape-code-in-region (point-min) (point-max))
-	(when markline
-	  (org-goto-line (1+ (- markline begline)))
-	  (org-move-to-column
-	   (if org-src-preserve-indentation markcol
-	     (max 0 (- markcol total-nindent))))
-	  (push-mark (point) 'no-message t)
-	  (setq deactivate-mark nil))
-	(org-goto-line (1+ (- line begline)))
+    (setq beg (move-marker beg (nth 0 info))
+	  end (move-marker end (nth 1 info))
+	  msg (if allow-write-back-p
+		  (substitute-command-keys
+		   "Edit, then exit with C-c ' (C-c and single quote)")
+		"Exit with C-c ' (C-c and single quote)")
+	  code (or code (buffer-substring-no-properties beg end))
+	  lang (or (cdr (assoc (nth 2 info) org-src-lang-modes))
+		   (nth 2 info))
+	  lang (if (symbolp lang) (symbol-name lang) lang)
+	  single (nth 3 info)
+	  block-nindent (nth 5 info)
+	  lang-f (intern (concat lang "-mode"))
+	  begline (save-excursion (goto-char beg) (org-current-line))
+	  transmitted-variables
+	  `((org-edit-src-content-indentation
+	     ,org-edit-src-content-indentation)
+	    (org-edit-src-force-single-line ,single)
+	    (org-edit-src-from-org-mode ,org-mode-p)
+	    (org-edit-src-allow-write-back-p ,allow-write-back-p)
+	    (org-src-preserve-indentation ,org-src-preserve-indentation)
+	    (org-src-babel-info ,(org-babel-get-src-block-info 'light))
+	    (org-coderef-label-format
+	     ,(or (nth 4 info) org-coderef-label-format))
+	    (org-edit-src-beg-marker ,beg)
+	    (org-edit-src-end-marker ,end)
+	    (org-edit-src-block-indentation ,block-nindent)))
+    (if (and mark (>= mark beg) (<= mark (1+ end)))
+	(save-excursion (goto-char (min mark end))
+			(setq markline (org-current-line)
+			      markcol (current-column))))
+    (if (equal lang-f 'table.el-mode)
+	(setq lang-f (lambda ()
+		       (text-mode)
+		       (if (org-bound-and-true-p flyspell-mode)
+			   (flyspell-mode -1))
+		       (table-recognize)
+		       (org-set-local 'org-edit-src-content-indentation 0))))
+    (unless (functionp lang-f)
+      (signal 'org-src-error "No such language mode: %s" lang-f))
+    (save-excursion
+      (if (> (point) end) (goto-char end))
+      (setq line (org-current-line)
+	    col (current-column)))
+    (if (and (setq buffer (org-edit-src-find-buffer beg end))
+	     (or (eq context 'save)
+		 (if org-src-ask-before-returning-to-edit-buffer
+		     (y-or-n-p "Return to existing edit buffer ([n] will revert changes)? ") t)))
+	(org-src-switch-to-buffer buffer 'return)
+      (when buffer
+	(with-current-buffer buffer
+	  (if (boundp 'org-edit-src-overlay)
+	      (delete-overlay org-edit-src-overlay)))
+	(kill-buffer buffer))
+      (setq buffer (generate-new-buffer
+		    (or edit-buffer-name
+			(org-src-construct-edit-buffer-name (buffer-name) lang))))
+      (setq ovl (make-overlay beg end))
+      (overlay-put ovl 'edit-buffer buffer)
+      (overlay-put ovl 'help-echo "Click with mouse-1 to switch to buffer editing this segment")
+      (overlay-put ovl 'face 'secondary-selection)
+      (overlay-put ovl
+		   'keymap
+		   (let ((map (make-sparse-keymap)))
+		     (define-key map [mouse-1] 'org-edit-src-continue)
+		     map))
+      (overlay-put ovl :read-only "Leave me alone")
+      (setq transmitted-variables
+	    (append transmitted-variables `((org-edit-src-overlay ,ovl))))
+      (org-src-switch-to-buffer buffer 'edit)
+      (if (eq single 'macro-definition)
+	  (setq code (replace-regexp-in-string "\\\\n" "\n" code t t)))
+      (insert code)
+      (remove-text-properties (point-min) (point-max)
+			      '(display nil invisible nil intangible nil))
+      (unless (cadr (assq 'org-src-preserve-indentation transmitted-variables))
+	(setq total-nindent (or (org-do-remove-indentation) 0)))
+      (let ((org-inhibit-startup t))
+	(condition-case e
+	    (funcall lang-f)
+	  (error
+	   (signal 'org-src-error "Language mode `%s' fails with: %S" lang-f (nth 1 e)))))
+      (dolist (pair transmitted-variables)
+	(org-set-local (car pair) (cadr pair)))
+      ;; Remove protecting commas from visible part of buffer.
+      (org-unescape-code-in-region (point-min) (point-max))
+      (when markline
+	(org-goto-line (1+ (- markline begline)))
 	(org-move-to-column
-	 (if org-src-preserve-indentation col (max 0 (- col total-nindent))))
-	(org-src-mode)
-	(set-buffer-modified-p nil)
-	(setq buffer-file-name nil)
-	(and org-edit-src-persistent-message
-	     (org-set-local 'header-line-format msg))
-	(let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang))))
-	  (when (fboundp edit-prep-func)
-	    (funcall edit-prep-func full-info))))
-      t)))
+	 (if org-src-preserve-indentation markcol
+	   (max 0 (- markcol total-nindent))))
+	(push-mark (point) 'no-message t)
+	(setq deactivate-mark nil))
+      (org-goto-line (1+ (- line begline)))
+      (org-move-to-column
+       (if org-src-preserve-indentation col (max 0 (- col total-nindent))))
+      (org-src-mode)
+      (set-buffer-modified-p nil)
+      (setq buffer-file-name nil)
+      (and org-edit-src-persistent-message
+	   (org-set-local 'header-line-format msg))
+      (let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang))))
+	(when (fboundp edit-prep-func)
+	  (funcall edit-prep-func full-info))))
+    t))
 
 (defun org-edit-src-continue (e)
   "Continue editing source blocks." ;; Fixme: be more accurate
-- 
1.7.11.4


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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-13 23:40                         ` Le Wang
@ 2012-12-13 23:50                           ` Le Wang
  2012-12-14  9:38                           ` Bastien
                                             ` (2 subsequent siblings)
  3 siblings, 0 replies; 29+ messages in thread
From: Le Wang @ 2012-12-13 23:50 UTC (permalink / raw)
  To: Bastien; +Cc: Bernt Hansen, emacs-orgmode

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

... one more to fix misuse of signal

-- 
Le

[-- Attachment #2: 0006-fix-mix-use-of-signal.patch --]
[-- Type: application/octet-stream, Size: 2058 bytes --]

From 343ce4349e688660859f24069975215836a69ddd Mon Sep 17 00:00:00 2001
From: Le Wang <le.wang@agworld.com.au>
Date: Fri, 14 Dec 2012 07:47:44 +0800
Subject: [PATCH 6/6] fix mix-use of signal

---
 lisp/org-src.el | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lisp/org-src.el b/lisp/org-src.el
index d4747ab..f4953a6 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -283,7 +283,7 @@ buffer."
 		       (table-recognize)
 		       (org-set-local 'org-edit-src-content-indentation 0))))
     (unless (functionp lang-f)
-      (signal 'org-src-error "No such language mode: %s" lang-f))
+      (signal 'org-src-error (list (format "No such language mode: %s" lang-f))))
     (save-excursion
       (if (> (point) end) (goto-char end))
       (setq line (org-current-line)
@@ -325,7 +325,7 @@ buffer."
 	(condition-case e
 	    (funcall lang-f)
 	  (error
-	   (signal 'org-src-error "Language mode `%s' fails with: %S" lang-f (nth 1 e)))))
+	   (signal 'org-src-error (list (format "Language mode `%s' fails with: %S" lang-f (nth 1 e)))))))
       (dolist (pair transmitted-variables)
 	(org-set-local (car pair) (cadr pair)))
       ;; Remove protecting commas from visible part of buffer.
@@ -356,7 +356,7 @@ buffer."
   (mouse-set-point e)
   (let ((buf (get-char-property (point) 'edit-buffer)))
     (if buf (org-src-switch-to-buffer buf 'continue)
-      (signal 'org-src-error "Something is wrong here"))))
+      (signal 'org-src-error '("Something is wrong here")))))
 
 (defun org-src-switch-to-buffer (buffer context)
   (case org-src-window-setup
@@ -639,7 +639,7 @@ with \",*\", \",#+\", \",,*\" and \",,#+\"."
   "Exit special edit and protect problematic lines."
   (interactive)
   (unless (org-bound-and-true-p org-edit-src-from-org-mode)
-    (signal 'org-src-error "This is not a sub-editing buffer, something is wrong"))
+    (signal 'org-src-error '("This is not a sub-editing buffer, something is wrong")))
   (widen)
   (let* ((beg org-edit-src-beg-marker)
 	 (end org-edit-src-end-marker)
-- 
1.7.11.4


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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-13 16:05                 ` Bastien
@ 2012-12-14  0:04                   ` Bernt Hansen
  2012-12-14  9:35                     ` Bastien
  2012-12-14  9:57                     ` Le Wang
  0 siblings, 2 replies; 29+ messages in thread
From: Bernt Hansen @ 2012-12-14  0:04 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

Bastien <bzg@altern.org> writes:

> Hi Bernt,
>
> Bernt Hansen <bernt@norang.ca> writes:
>
>> Your patch fixes it for me on both versions (linux 23.2.1, windows
>> 23.3.1)
>>
>> Thanks!
>
> I pushed the patch, thanks for confirming this.
>
> PS: Le, I used my version, shorter, and not that unlispy IMO.
> But thanks for the patch anyway!

I get the following error when doing C-c ' in a table

--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  org-edit-src-code()
  org-edit-special()
  call-interactively(org-edit-special nil nil)
--8<---------------cut here---------------end--------------->8---

I'm trying to get to the table editor.

GNU Emacs 23.2.1 (i486-pc-linux-gnu, GTK+ Version 2.20.0) of 2010-12-11
on raven, modified by Debian

Regards,
Bernt

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-14  0:04                   ` Bernt Hansen
@ 2012-12-14  9:35                     ` Bastien
  2012-12-14  9:57                     ` Le Wang
  1 sibling, 0 replies; 29+ messages in thread
From: Bastien @ 2012-12-14  9:35 UTC (permalink / raw)
  To: Bernt Hansen; +Cc: emacs-orgmode

Hi Bernt,

Bernt Hansen <bernt@norang.ca> writes:

> I get the following error when doing C-c ' in a table
>
> Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
>   org-edit-src-code()
>   org-edit-special()
>   call-interactively(org-edit-special nil nil)

I fixed this, thanks!

-- 
 Bastien

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-13 23:40                         ` Le Wang
  2012-12-13 23:50                           ` Le Wang
@ 2012-12-14  9:38                           ` Bastien
  2012-12-14  9:39                           ` Bastien
  2012-12-14  9:40                           ` Bastien
  3 siblings, 0 replies; 29+ messages in thread
From: Bastien @ 2012-12-14  9:38 UTC (permalink / raw)
  To: Le Wang; +Cc: Bernt Hansen, emacs-orgmode

Hi Le,

Le Wang <l26wang@gmail.com> writes:

> If I press C-' before on a line BEFORE "+begin_src ...", then doing
> comparison with ">=" with beg==nil and end==nil causes
> "wrong-type-argument" error.

I think the check should happen before, see how I did it here:
http://orgmode.org/cgit.cgi/org-mode.git/commit/?id=81d5eb

> "test-org-src/point-outside-block" test case should fail, but because
> "wrong-type-argument" is also an error, it is passing.  :(
>
> I've changed "(error ..." to raise an org-src specific error to
> facilitate testing.  Commits rebased to master are attached.

Using signal makes sense if our testing suite uses it, yes.
Can you merge your patches and provide a ChangeLog when the
change affects org-src.el (and possibly test-org-src.el too)?  

Thanks a lot!

-- 
 Bastien

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-13 23:40                         ` Le Wang
  2012-12-13 23:50                           ` Le Wang
  2012-12-14  9:38                           ` Bastien
@ 2012-12-14  9:39                           ` Bastien
  2012-12-16 14:39                             ` Le Wang
  2012-12-14  9:40                           ` Bastien
  3 siblings, 1 reply; 29+ messages in thread
From: Bastien @ 2012-12-14  9:39 UTC (permalink / raw)
  To: Le Wang; +Cc: Bernt Hansen, emacs-orgmode

Le Wang <l26wang@gmail.com> writes:

>  	 ;; Move marker with inserted text for case when src block is
>  	 ;; just one empty line, i.e. beg == end.
> -	 (end (copy-marker (make-marker) t))
> +	 (end (let ((marker (make-marker)))
> +		(set-marker-insertion-type marker t)
> +		marker))

There is a (make-marker) in both case, the first one is okay.

Best,

-- 
 Bastien

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-13 23:40                         ` Le Wang
                                             ` (2 preceding siblings ...)
  2012-12-14  9:39                           ` Bastien
@ 2012-12-14  9:40                           ` Bastien
  3 siblings, 0 replies; 29+ messages in thread
From: Bastien @ 2012-12-14  9:40 UTC (permalink / raw)
  To: Le Wang; +Cc: Bernt Hansen, emacs-orgmode

> -	    (if (>= end beg) temp
> -	      (goto-char beg)
> -	      (insert "\n")
> -	      (org-edit-src-find-region-and-lang))))
> +	    (if (and beg end)
> +		(if (>= end beg)
> +		    temp
> +		  (goto-char beg)
> +		  (insert "\n")
> +		  (org-edit-src-find-region-and-lang))
> +	      (error "Point not in src block."))))

Note: this is 

  (if (and beg end (>= end beg)) ... ...)

Let's try to optimize such tiny refactoring :)

-- 
 Bastien

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-14  0:04                   ` Bernt Hansen
  2012-12-14  9:35                     ` Bastien
@ 2012-12-14  9:57                     ` Le Wang
  1 sibling, 0 replies; 29+ messages in thread
From: Le Wang @ 2012-12-14  9:57 UTC (permalink / raw)
  To: Bernt Hansen; +Cc: Bastien, emacs-orgmode

On Fri, Dec 14, 2012 at 8:04 AM, Bernt Hansen <bernt@norang.ca> wrote:
> I get the following error when doing C-c ' in a table
>
> --8<---------------cut here---------------start------------->8---
> Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
>   org-edit-src-code()
>   org-edit-special()
>   call-interactively(org-edit-special nil nil)
> --8<---------------cut here---------------end--------------->8---

I have repro of the issue.  I didn't take into account the full usage
org-edit-special.  I'll redo this with new tests within the next few
hours.

-- 
Le

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

* Re: bug#12905: 24.2.50; org: edit source block causes data loss
  2012-12-14  9:39                           ` Bastien
@ 2012-12-16 14:39                             ` Le Wang
  0 siblings, 0 replies; 29+ messages in thread
From: Le Wang @ 2012-12-16 14:39 UTC (permalink / raw)
  To: Bastien; +Cc: Bernt Hansen, emacs-orgmode

On Fri, Dec 14, 2012 at 5:39 PM, Bastien <bzg@altern.org> wrote:
> Le Wang <l26wang@gmail.com> writes:
>
>>        ;; Move marker with inserted text for case when src block is
>>        ;; just one empty line, i.e. beg == end.
>> -      (end (copy-marker (make-marker) t))
>> +      (end (let ((marker (make-marker)))
>> +             (set-marker-insertion-type marker t)
>> +             marker))
>
> There is a (make-marker) in both case, the first one is okay.

Well in the first case two marker are made (make-marker, then
copy-marker), in the second one is made, IIUC of course; but it's not
a big deal.

I just had a chance to catch up on your changes.  Tests pass fine now
without structured error handling.  So I'm happy with the state of
things.


Thanks.

-- 
Le

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

end of thread, other threads:[~2012-12-16 14:39 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <50A62865.8010904@gmail.com>
2012-12-07 15:36 ` bug#12905: 24.2.50; org: edit source block causes data loss Chong Yidong
     [not found] ` <87sj7han8a.fsf__16482.9143243425$1354894646$gmane$org@gnu.org>
2012-12-12 16:55   ` Bastien
2012-12-12 21:05     ` Bernt Hansen
2012-12-12 21:34       ` Jonathan Leech-Pepin
2012-12-12 21:51         ` Bernt Hansen
2012-12-12 23:18       ` Bastien
2012-12-13  3:27         ` Bernt Hansen
2012-12-13  3:37           ` Bernt Hansen
2012-12-13  4:50             ` Nick Dokos
2012-12-13 12:45               ` Bernt Hansen
2012-12-13 13:41                 ` Bernt Hansen
2012-12-13 10:36             ` Bastien
2012-12-13 13:42               ` Bernt Hansen
2012-12-13 14:36                 ` Le Wang
2012-12-13 15:17                   ` Bastien
2012-12-13 16:06                     ` Le Wang
2012-12-13 16:25                       ` Bastien
2012-12-13 23:40                         ` Le Wang
2012-12-13 23:50                           ` Le Wang
2012-12-14  9:38                           ` Bastien
2012-12-14  9:39                           ` Bastien
2012-12-16 14:39                             ` Le Wang
2012-12-14  9:40                           ` Bastien
2012-12-13 13:48               ` Bernt Hansen
2012-12-13 16:05                 ` Bastien
2012-12-14  0:04                   ` Bernt Hansen
2012-12-14  9:35                     ` Bastien
2012-12-14  9:57                     ` Le Wang
     [not found]   ` <87wqwnyzud.fsf@bzg.ath.cx>
2012-12-12 17:39     ` Andy Moreton

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