Subject: bug#810: 23.0.60; atomic-change-group narrowing problem

From: martin rudalics <[email-masked]>
Date: Fri, 29 Aug 2008 11:27:04 +0200

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