GNU bug report logs - #810
23.0.60; atomic-change-group narrowing problem

Previous Next

Package: emacs;

Reported by: "Lennart Borgman (gmail)" <lennart.borgman <at> gmail.com>

Date: Thu, 28 Aug 2008 19:05:05 UTC

Severity: normal

Done: martin rudalics <rudalics <at> gmx.at>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 810 in the body.
You can then email your comments to 810 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#810; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to "Lennart Borgman (gmail)" <lennart.borgman <at> gmail.com>:
New bug report received and forwarded. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Message #5 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: "Lennart Borgman (gmail)" <lennart.borgman <at> gmail.com>
To: emacs-pretest-bug <at> gnu.org
Subject: 23.0.60; atomic-change-group narrowing problem
Date: Thu, 28 Aug 2008 20:58:42 +0200
When using atomic-change-group I got the message

  undo-more: Changes to be undone are outside visible portion of buffer

The changes are also not undone. This seems wrong to me.

If I put (widen) before the end of my code in the atomic-change-group
the message above disappears and the change is undone.


In GNU Emacs 23.0.60.1 (i386-mingw-nt5.1.2600)
 of 2008-08-10
Windowing system distributor `Microsoft Corp.', version 5.1.2600
configured using `configure --with-gcc (3.4) --no-opt --cflags
-Ic:/g/include -fno-crossjumping'




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#810; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to martin rudalics <rudalics <at> gmx.at>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Message #10 received at 810 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: "Lennart Borgman (gmail)" <lennart.borgman <at> gmail.com>,
        810 <at> debbugs.gnu.org
Subject: Re: bug#810: 23.0.60; atomic-change-group narrowing problem
Date: Thu, 28 Aug 2008 23:26:56 +0200
> When using atomic-change-group I got the message
>
>   undo-more: Changes to be undone are outside visible portion of buffer

This message is usually a consequence of narrowing the buffer within the
body of `atomic-change-group' or afterwards.

> The changes are also not undone. This seems wrong to me.

If you did narrow the buffer this is normal and not specific to
`atomic-change-group'.

martin




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#810; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to "Lennart Borgman (gmail)" <lennart.borgman <at> gmail.com>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Message #15 received at 810 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: "Lennart Borgman (gmail)" <lennart.borgman <at> gmail.com>
To: martin rudalics <rudalics <at> gmx.at>
Cc: 810 <at> debbugs.gnu.org
Subject: Re: bug#810: 23.0.60; atomic-change-group narrowing problem
Date: Thu, 28 Aug 2008 23:37:26 +0200
martin rudalics wrote:
>> When using atomic-change-group I got the message
>>
>>   undo-more: Changes to be undone are outside visible portion of buffer
> 
> This message is usually a consequence of narrowing the buffer within the
> body of `atomic-change-group' or afterwards.
> 
>> The changes are also not undone. This seems wrong to me.
> 
> If you did narrow the buffer this is normal and not specific to
> `atomic-change-group'.

Maybe, but what is specific to atomic-change-group is that the doc
string says

  Perform body as an atomic change group.
  This means that if body exits abnormally,
  all of its changes to the current buffer are undone.

AFAICS there is something wrong either in the doc string or in the function.

I would suggest that this is a bug in the function. Think for example of
the case that you want to test something during narrowing and be sure
that the buffer is not changed.




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#810; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to martin rudalics <rudalics <at> gmx.at>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Message #20 received at 810 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: "Lennart Borgman (gmail)" <lennart.borgman <at> gmail.com>
Cc: 810 <at> debbugs.gnu.org
Subject: Re: bug#810: 23.0.60; atomic-change-group narrowing problem
Date: Fri, 29 Aug 2008 11:27:04 +0200
[Message part 1 (text/plain, inline)]
> I would suggest that this is a bug in the function. Think for example of
> the case that you want to test something during narrowing and be sure
> that the buffer is not changed.

Does the attached patch do what you want?

martin
[810.diff (text/plain, inline)]
*** subr.el.~1.602.~	2008-07-31 07:33:45.000000000 +0200
--- subr.el	2008-08-29 11:15:34.765625000 +0200
***************
*** 1991,2016 ****
    (dolist (elt handle)
      (with-current-buffer (car elt)
        (setq elt (cdr elt))
!       (let ((old-car
!              (if (consp elt) (car elt)))
!             (old-cdr
!              (if (consp elt) (cdr elt))))
!         ;; Temporarily truncate the undo log at ELT.
!         (when (consp elt)
!           (setcar elt nil) (setcdr elt nil))
!         (unless (eq last-command 'undo) (undo-start))
!         ;; Make sure there's no confusion.
!         (when (and (consp elt) (not (eq elt (last pending-undo-list))))
!           (error "Undoing to some unrelated state"))
!         ;; Undo it all.
!         (save-excursion
!           (while (listp pending-undo-list) (undo-more 1)))
!         ;; Reset the modified cons cell ELT to its original content.
!         (when (consp elt)
!           (setcar elt old-car)
!           (setcdr elt old-cdr))
!         ;; Revert the undo info to what it was when we grabbed the state.
!         (setq buffer-undo-list elt)))))
  
  ;;;; Display-related functions.
  
--- 1991,2018 ----
    (dolist (elt handle)
      (with-current-buffer (car elt)
        (setq elt (cdr elt))
!       (save-restriction
! 	(widen)
! 	(let ((old-car
! 	       (if (consp elt) (car elt)))
! 	      (old-cdr
! 	       (if (consp elt) (cdr elt))))
! 	  ;; Temporarily truncate the undo log at ELT.
! 	  (when (consp elt)
! 	    (setcar elt nil) (setcdr elt nil))
! 	  (unless (eq last-command 'undo) (undo-start))
! 	  ;; Make sure there's no confusion.
! 	  (when (and (consp elt) (not (eq elt (last pending-undo-list))))
! 	    (error "Undoing to some unrelated state"))
! 	  ;; Undo it all.
! 	  (save-excursion
! 	    (while (listp pending-undo-list) (undo-more 1)))
! 	  ;; Reset the modified cons cell ELT to its original content.
! 	  (when (consp elt)
! 	    (setcar elt old-car)
! 	    (setcdr elt old-cdr))
! 	  ;; Revert the undo info to what it was when we grabbed the state.
! 	  (setq buffer-undo-list elt))))))
  
  ;;;; Display-related functions.
  

Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#810; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to martin rudalics <rudalics <at> gmx.at>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Message #25 received at 810 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: "Lennart Borgman (gmail)" <lennart.borgman <at> gmail.com>,
        810 <at> debbugs.gnu.org
Subject: Re: bug#810: 23.0.60; atomic-change-group narrowing problem
Date: Mon, 01 Sep 2008 19:56:54 +0200
[Message part 1 (text/plain, inline)]
> When using atomic-change-group I got the message
>
>   undo-more: Changes to be undone are outside visible portion of buffer
>
> The changes are also not undone. This seems wrong to me.

The attached patch now also tries to restore any narrowing in force
before the atomic change.

martin
[810.diff (text/plain, inline)]
*** subr.el.~1.604.~	2008-08-31 09:48:50.531250000 +0200
--- subr.el	2008-09-01 19:52:32.843750000 +0200
***************
*** 1907,1912 ****
--- 1907,1917 ----
  
  ;;; Atomic change groups.
  
+ (defvar atomic-change-point-min nil
+   "Value returned by `point-min' before an atomic change.")
+ (defvar atomic-change-point-max nil
+   "Value returned by `point-max' before an atomic change.")
+ 
  (defmacro atomic-change-group (&rest body)
    "Perform BODY as an atomic change group.
  This means that if BODY exits abnormally,
***************
*** 1920,1925 ****
--- 1925,1932 ----
    (let ((handle (make-symbol "--change-group-handle--"))
  	(success (make-symbol "--change-group-success--")))
      `(let ((,handle (prepare-change-group))
+ 	   (atomic-change-point-min (point-min))
+ 	   (atomic-change-point-max (point-max))
  	   ;; Don't truncate any undo data in the middle of this.
  	   (undo-outer-limit nil)
  	   (undo-limit most-positive-fixnum)
***************
*** 1992,2017 ****
    (dolist (elt handle)
      (with-current-buffer (car elt)
        (setq elt (cdr elt))
!       (let ((old-car
!              (if (consp elt) (car elt)))
!             (old-cdr
!              (if (consp elt) (cdr elt))))
!         ;; Temporarily truncate the undo log at ELT.
!         (when (consp elt)
!           (setcar elt nil) (setcdr elt nil))
!         (unless (eq last-command 'undo) (undo-start))
!         ;; Make sure there's no confusion.
!         (when (and (consp elt) (not (eq elt (last pending-undo-list))))
!           (error "Undoing to some unrelated state"))
!         ;; Undo it all.
!         (save-excursion
!           (while (listp pending-undo-list) (undo-more 1)))
!         ;; Reset the modified cons cell ELT to its original content.
!         (when (consp elt)
!           (setcar elt old-car)
!           (setcdr elt old-cdr))
!         ;; Revert the undo info to what it was when we grabbed the state.
!         (setq buffer-undo-list elt)))))
  
  ;;;; Display-related functions.
  
--- 1999,2030 ----
    (dolist (elt handle)
      (with-current-buffer (car elt)
        (setq elt (cdr elt))
!       (save-restriction
! 	(widen)
! 	(let ((old-car
! 	       (if (consp elt) (car elt)))
! 	      (old-cdr
! 	       (if (consp elt) (cdr elt))))
! 	  ;; Temporarily truncate the undo log at ELT.
! 	  (when (consp elt)
! 	    (setcar elt nil) (setcdr elt nil))
! 	  (unless (eq last-command 'undo) (undo-start))
! 	  ;; Make sure there's no confusion.
! 	  (when (and (consp elt) (not (eq elt (last pending-undo-list))))
! 	    (error "Undoing to some unrelated state"))
! 	  ;; Undo it all.
! 	  (save-excursion
! 	    (while (listp pending-undo-list) (undo-more 1)))
! 	  ;; Reset the modified cons cell ELT to its original content.
! 	  (when (consp elt)
! 	    (setcar elt old-car)
! 	    (setcdr elt old-cdr))
! 	  ;; Revert the undo info to what it was when we grabbed the state.
! 	  (setq buffer-undo-list elt)))
!       (unless (and (= (point-min) atomic-change-point-min)
! 		   (= (point-max) atomic-change-point-max))
! 	;; Try to restore narrowing in force before atomic change.
! 	(narrow-to-region atomic-change-point-min atomic-change-point-max)))))
  
  ;;;; Display-related functions.
  

Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#810; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Message #30 received at 810 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: martin rudalics <rudalics <at> gmx.at>
Cc: 810 <at> debbugs.gnu.org,
        "Lennart Borgman \(gmail\)" <lennart.borgman <at> gmail.com>
Subject: Re: bug#810: 23.0.60; atomic-change-group narrowing problem
Date: Mon, 01 Sep 2008 16:43:59 -0400
>> When using atomic-change-group I got the message
>> undo-more: Changes to be undone are outside visible portion of buffer
>> The changes are also not undone. This seems wrong to me.

> The attached patch now also tries to restore any narrowing in force
> before the atomic change.

I'm not sure we should do that.  Currently, narrowing operations are not
saved to the undo-log, so making atomic-change-group save&restore the
narrowing makes it behave differently from the undo.


        Stefan




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#810; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to martin rudalics <rudalics <at> gmx.at>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Message #35 received at 810 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 810 <at> debbugs.gnu.org,
        "Lennart Borgman (gmail)" <lennart.borgman <at> gmail.com>
Subject: Re: bug#810: 23.0.60; atomic-change-group narrowing problem
Date: Mon, 01 Sep 2008 23:20:29 +0200
>>> When using atomic-change-group I got the message
>>> undo-more: Changes to be undone are outside visible portion of buffer
>>> The changes are also not undone. This seems wrong to me.
>
>> The attached patch now also tries to restore any narrowing in force
>> before the atomic change.
>
> I'm not sure we should do that.  Currently, narrowing operations are not
> saved to the undo-log, so making atomic-change-group save&restore the
> narrowing makes it behave differently from the undo.

I know what you mean but the present case is different.  When someone
uses narrowing within the atomic change group and we really want to undo
the changes (we still can decide that we won't fix the bug ;-)) we have
to widen the buffer.  If the buffer was narrowed _before_ entering the
atomic change group, it would be incorrect not to restore that.  Or am I
missing something?

martin




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#810; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to "Lennart Borgman (gmail)" <lennart.borgman <at> gmail.com>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Message #40 received at 810 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: "Lennart Borgman (gmail)" <lennart.borgman <at> gmail.com>
To: martin rudalics <rudalics <at> gmx.at>
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>, 810 <at> debbugs.gnu.org
Subject: Re: bug#810: 23.0.60; atomic-change-group narrowing problem
Date: Mon, 01 Sep 2008 23:53:06 +0200
martin rudalics wrote:
>>>> When using atomic-change-group I got the message
>>>> undo-more: Changes to be undone are outside visible portion of buffer
>>>> The changes are also not undone. This seems wrong to me.
>>
>>> The attached patch now also tries to restore any narrowing in force
>>> before the atomic change.
>>
>> I'm not sure we should do that.  Currently, narrowing operations are not
>> saved to the undo-log, so making atomic-change-group save&restore the
>> narrowing makes it behave differently from the undo.
> 
> I know what you mean but the present case is different.  When someone
> uses narrowing within the atomic change group and we really want to undo
> the changes (we still can decide that we won't fix the bug ;-)) we have
> to widen the buffer.  If the buffer was narrowed _before_ entering the
> atomic change group, it would be incorrect not to restore that.  Or am I
> missing something?


I agree. It would be very surprising if narrowing was not restored.




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#810; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Message #45 received at 810 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: "Lennart Borgman \(gmail\)" <lennart.borgman <at> gmail.com>
Cc: martin rudalics <rudalics <at> gmx.at>, 810 <at> debbugs.gnu.org
Subject: Re: bug#810: 23.0.60; atomic-change-group narrowing problem
Date: Mon, 01 Sep 2008 22:38:48 -0400
>>>>> When using atomic-change-group I got the message
>>>>> undo-more: Changes to be undone are outside visible portion of buffer
>>>>> The changes are also not undone. This seems wrong to me.
>>> 
>>>> The attached patch now also tries to restore any narrowing in force
>>>> before the atomic change.
>>> 
>>> I'm not sure we should do that.  Currently, narrowing operations are not
>>> saved to the undo-log, so making atomic-change-group save&restore the
>>> narrowing makes it behave differently from the undo.
>> 
>> I know what you mean but the present case is different.  When someone
>> uses narrowing within the atomic change group and we really want to undo
>> the changes (we still can decide that we won't fix the bug ;-)) we have
>> to widen the buffer.  If the buffer was narrowed _before_ entering the
>> atomic change group, it would be incorrect not to restore that.  Or am I
>> missing something?

The widening needs to be temporary around the call to undo, but that
doesn't seem to imply that atomic-change-group will preserve narrowing.


        Stefan




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#810; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to rms <at> gnu.org:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Message #50 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: "Richard M. Stallman" <rms <at> gnu.org>
To: martin rudalics <rudalics <at> gmx.at>, 810 <at> debbugs.gnu.org
Cc: monnier <at> iro.umontreal.ca, bug-submit-list <at> donarmstrong.com,
        810 <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org
Subject: Re: bug#810: 23.0.60; atomic-change-group narrowing problem
Date: Tue, 02 Sep 2008 10:13:59 -0400
    I know what you mean but the present case is different.  When someone
    uses narrowing within the atomic change group and we really want to undo
    the changes (we still can decide that we won't fix the bug ;-)) we have
    to widen the buffer.

We could say that if the body of the atomic-change-group does
narrowing, then it has the responsibility to widen again.
That seems logical.





Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#810; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to rms <at> gnu.org:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#810; Package emacs. Full text and rfc822 format available.

Acknowledgement sent to martin rudalics <rudalics <at> gmx.at>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. Full text and rfc822 format available.

Message #60 received at 810 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: "Lennart Borgman (gmail)" <lennart.borgman <at> gmail.com>,
        810 <at> debbugs.gnu.org
Subject: Re: bug#810: 23.0.60; atomic-change-group narrowing problem
Date: Sun, 07 Sep 2008 11:37:07 +0200
> The widening needs to be temporary around the call to undo, but that
> doesn't seem to imply that atomic-change-group will preserve narrowing.

OK.  Installed without restoring the initial narrowing state.  Any
narrowing within the group will remain effective when the change is
canceled.

martin





Reply sent to martin rudalics <rudalics <at> gmx.at>:
You have taken responsibility. Full text and rfc822 format available.

Notification sent to "Lennart Borgman (gmail)" <lennart.borgman <at> gmail.com>:
bug acknowledged by developer. Full text and rfc822 format available.

Message #65 received at 810-done <at> emacsbugs.donarmstrong.com (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: 810-done <at> debbugs.gnu.org
Cc: lennart.borgman <at> gmail.com
Subject: Re: bug#810: 23.0.60; atomic-change-group narrowing problem
Date: Sun, 07 Sep 2008 12:02:38 +0200
Fixed as

2008-09-07  Martin Rudalics  <rudalics <at> gmx.at>

	* subr.el (cancel-change-group): Widen buffer temporarily when
	undoing changes.  (Bug#810)

Thanks




bug archived. Request was from Debbugs Internal Request <don <at> donarmstrong.com> to internal_control <at> emacsbugs.donarmstrong.com. (Sun, 05 Oct 2008 14:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 16 years and 258 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.