GNU bug report logs - #34405
26.1; atomic change group after undo fails to cancel

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Braun Gábor <braungb88@HIDDEN>; merged with #26287; dated Sat, 9 Feb 2019 18:04:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Merged 26287 34405. Request was from Glenn Morris <rgm@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 9 Feb 2019 18:03:11 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Feb 09 13:03:11 2019
Received: from localhost ([127.0.0.1]:41490 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gsWy6-00088K-Ey
	for submit <at> debbugs.gnu.org; Sat, 09 Feb 2019 13:03:11 -0500
Received: from eggs.gnu.org ([209.51.188.92]:49973)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <braungb88@HIDDEN>) id 1gsUsp-0004kr-PK
 for submit <at> debbugs.gnu.org; Sat, 09 Feb 2019 10:49:36 -0500
Received: from lists.gnu.org ([209.51.188.17]:38182)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <braungb88@HIDDEN>) id 1gsUsk-0001bk-HR
 for submit <at> debbugs.gnu.org; Sat, 09 Feb 2019 10:49:30 -0500
Received: from eggs.gnu.org ([209.51.188.92]:36121)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <braungb88@HIDDEN>) id 1gsUsj-0005VB-4k
 for bug-gnu-emacs@HIDDEN; Sat, 09 Feb 2019 10:49:30 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: *
X-Spam-Status: No, score=1.1 required=5.0 tests=BAYES_50,
 FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,URIBL_BLOCKED autolearn=disabled
 version=3.3.2
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <braungb88@HIDDEN>) id 1gsUsh-0001Yq-TG
 for bug-gnu-emacs@HIDDEN; Sat, 09 Feb 2019 10:49:29 -0500
Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:56155)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
 (Exim 4.71) (envelope-from <braungb88@HIDDEN>) id 1gsUsh-0001Xu-Ib
 for bug-gnu-emacs@HIDDEN; Sat, 09 Feb 2019 10:49:27 -0500
Received: by mail-wm1-x330.google.com with SMTP id r17so8840961wmh.5
 for <bug-gnu-emacs@HIDDEN>; Sat, 09 Feb 2019 07:49:27 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:subject:date:message-id:mime-version
 :content-transfer-encoding;
 bh=x7b1yxKZo1CGnNXreoWdKbovYEUINo2za2rK19ugnKE=;
 b=aP8k71cGRwwECMuDWLYwPuXJD7nhTNqwCoaw4Qs6HhJRFldR87V458UHaUZ/D/fPYp
 FT276EopVcMFrXLT8J/2nwq+2bC4JDCMGSj1PGXqv6Ebe37lKkw/savu7V1SY5lXtFXJ
 u39K4oub8RvyrJ3Fg8ZvOvufPI8as6ZefJIesX7e46DEF5DPFdCrILrnKgnskcEX5Ych
 9qfss+wfHVJs/X4dkgAb2dgLT21Vg1cjax29ako7iTIExS2gHOipLhHc4Er6I2iQ3d3k
 Njg/3fDm5shdm78kW9+fd5jqoi1tV6hVpvPllc1y5M1HFODsZuM6BieX6y2GlbqJxMTt
 MgJg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:subject:date:message-id:mime-version
 :content-transfer-encoding;
 bh=x7b1yxKZo1CGnNXreoWdKbovYEUINo2za2rK19ugnKE=;
 b=m9H4w44aLNCbQiccxVHzR6GoZJ2KTteypqrq1PFCxpHjlmvquXCscBnXlV2FO/hd2/
 xcgXF/l00B+EBpB/lbQn5bVh8Oz+yHCaRMAX5EVZ260O6eu7P25pP2kzpvrU+wHAEs/4
 dg0hFpEpoQdJcaOmv2pKKfD0+fD/SiHvFV86leLOKMH3DCzpt+VfvMGO8Tqdn2nvU1ih
 7/lBzn2dg5rVUGpPGepb0UJIPPIaX9YOs1xanFLaH8zEU2zS5i4K7Or3G+rIeyUJIzpk
 H3FsL6hfjLPc0b2HZyXilkhyKBLw2PJViSQdNqRYhks48UdKgV900J4xxeqV0GJRhC1Y
 4ZUA==
X-Gm-Message-State: AHQUAuaC+DO3NeFdZj+q9JgtPX6t/Q6zXoF2onwWpniooElp7x4VHQLK
 Yrsa0ldgcke+ReIvL7Lyvul9TVI4
X-Google-Smtp-Source: AHgI3IaaOllrw890jGekrGqe/z1ivrhyA7fl00s82QXg0B/JUZce8gepTPpNbwKAlT2Utm7xBeJmnA==
X-Received: by 2002:a1c:384:: with SMTP id 126mr3242238wmd.26.1549727365786;
 Sat, 09 Feb 2019 07:49:25 -0800 (PST)
Received: from gabor.localnet (254C439A.nat.pool.telekom.hu. [37.76.67.154])
 by smtp.gmail.com with ESMTPSA id 2sm13645760wrg.89.2019.02.09.07.49.24
 for <bug-gnu-emacs@HIDDEN>
 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
 Sat, 09 Feb 2019 07:49:25 -0800 (PST)
From: Braun =?ISO-8859-1?Q?G=E1bor?= <braungb88@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 26.1; atomic change group after undo fails to cancel
Date: Sat, 09 Feb 2019 16:49:23 +0100
Message-ID: <1631063.cd5q6Ms6ql@gabor>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="utf-8"
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
 recognized.
X-Received-From: 2a00:1450:4864:20::330
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Spam-Score: 1.2 (+)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 Content preview:  Hi, File test.el ; ; -*- lexical-binding: t;
 -*- (defun test-fun
 () "Test atomic change group, no visible effect." (interactive) (catch 'test
 (atomic [...] 
 Content analysis details:   (1.2 points, 10.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 0.0 URIBL_BLOCKED          ADMINISTRATOR NOTICE: The query to URIBL was
 blocked.  See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block
 for more information. [URIs: x.org]
 0.0 FREEMAIL_FROM          Sender email is commonly abused enduser mail
 provider (braungb88[at]gmail.com)
 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends
 in digit (braungb88[at]gmail.com)
 1.0 SPF_SOFTFAIL           SPF: sender does not match SPF record (softfail)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Sat, 09 Feb 2019 13:03:08 -0500
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.2 (/)

Hi,

=2D------------------- File test.el ----------------------------------
;; -*- lexical-binding: t; -*-
(defun test-fun ()
  "Test atomic change group, no visible effect."
  (interactive)
  (catch 'test
    (atomic-change-group
      (save-excursion
        (goto-char (point-min))
        (insert "!!! TEST: you shouldn't see this !!!")
        (throw 'test t)))))

(global-set-key [(control c) ?a] #'test-fun)
=2D-------------------------------------------------------------------

Start emacs by the command

emacs -Q -l test.el

Press the following keys: a C-_ C-c a

A "!!! TEST: you shouldn't see this !!!" gets inserted at the top of
buffer *scratch*, and the message "Undoing to some unrelated state"
appears in the echo area.  I expect that "C-c a" has no visible effect
(as is the case if one omits "a C-_" before "C-c a").


A variant: in function cancel-change-group change line
"(unless (eq last-command 'undo) (undo-start))"
into "(undo-start)".
I.e. to have a self-containd test:

=2D------------------ file test2.el ----------------------------------
;; -*- lexical-binding: t; -*-
(defun test-fun ()
  "Test atomic change group, no visible effect."
  (interactive)
  (catch 'test
    (atomic-change-group
      (save-excursion
        (goto-char (point-min))
        (insert "!!! TEST: you shouldn't see this !!!")
        (throw 'test t)))))

(global-set-key [(control c) ?a] #'test-fun)

(defun cancel-change-group (handle)
  "Finish a change group made with `prepare-change-group' (which see).
This finishes the change group by reverting all of its changes."
  (dolist (elt handle)
    (with-current-buffer (car elt)
      (setq elt (cdr elt))
      (save-restriction
        ;; Widen buffer temporarily so if the buffer was narrowed within
        ;; the body of `atomic-change-group' all changes can be undone.
        (widen)
        (let ((old-car (car-safe elt))
              (old-cdr (cdr-safe elt)))
          (unwind-protect
              (progn
                ;; Temporarily truncate the undo log at ELT.
                (when (consp elt)
                  (setcar elt nil) (setcdr elt nil))
                (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)))
                ;; Revert the undo info to what it was when we grabbed
                ;; the state.
                (setq buffer-undo-list elt))
            ;; Reset the modified cons cell ELT to its original content.
            (when (consp elt)
              (setcar elt old-car)
              (setcdr elt old-cdr))))))))
=2D-------------------------------------------------------------------

Run emacs as

emacs -Q -l test2.el

Press the following keys (same as above): a C-_ C-c a

Now the displayed buffer *scratch* is in its original form, no message
in the echo area as expected.

Discussion:

I do not claim that the change above in cancel-change-group is a correct
fix, especially no claim that pending-undo-list will not get corrupted.
It is intended only as a proof that in its original definition
cancel-change-group fails while it was still possible to properly cancel
the change group.

Best wishes,

     G=C3=A1bor

System information (for the first test, not the second one):

In GNU Emacs 26.1 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.2)
 of 2018-12-26, modified by Debian built on x86-ubc-01
Windowing system distributor 'The X.Org Foundation', version=20
11.0.12003000
System Description:	Debian GNU/Linux buster/sid

Recent messages:
=46or information about GNU Emacs and the GNU system, type C-h C-a.
Undo!
cancel-change-group: Undoing to some unrelated state

Configured using:
 'configure --build x86_64-linux-gnu --prefix=3D/usr
 --sharedstatedir=3D/var/lib --libexecdir=3D/usr/lib
 --localstatedir=3D/var/lib --infodir=3D/usr/share/info
 --mandir=3D/usr/share/man --enable-libsystemd --with-pop=3Dyes
 --enable-locallisppath=3D/etc/emacs:/usr/local/share/emacs/26.1/site-
lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/26.1/site-lisp:/
usr/share/emacs/site-lisp
 --with-sound=3Dalsa --without-gconf --with-mailutils --build
 x86_64-linux-gnu --prefix=3D/usr --sharedstatedir=3D/var/lib
 --libexecdir=3D/usr/lib --localstatedir=3D/var/lib
 --infodir=3D/usr/share/info --mandir=3D/usr/share/man --enable-libsystemd
 --with-pop=3Dyes
 --enable-locallisppath=3D/etc/emacs:/usr/local/share/emacs/26.1/site-
lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/26.1/site-lisp:/
usr/share/emacs/site-lisp
 --with-sound=3Dalsa --without-gconf --with-mailutils --with-x=3Dyes
 --with-x-toolkit=3Dgtk3 --with-toolkit-scroll-bars 'CFLAGS=3D-g -O2
 -fdebug-prefix-map=3D/build/emacs-3ThesY/emacs-26.1+1=3D. -fstack-
protector-strong
 -Wformat -Werror=3Dformat-security -Wall' 'CPPFLAGS=3D-Wdate-time
 -D_FORTIFY_SOURCE=3D2' LDFLAGS=3D-Wl,-z,relro'

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS NOTIFY
ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11 THREADS LIBSYSTEMD LCMS2

Important settings:
  value of $LANG: hu_HU.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

=46eatures:
(shadow sort mail-extr emacsbug message rmc puny seq byte-opt gv
bytecomp byte-compile cconv cl-loaddefs cl-lib dired dired-loaddefs
format-spec rfc822 mml easymenu mml-sec password-cache epa derived epg
epg-config gnus-util rmail rmail-loaddefs mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils elec-pair time-date
mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel term/x-win x-win term/common-win x-dnd tool-bar
dnd fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode elisp-mode lisp-mode prog-mode register page menu-bar
rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core term/tty-colors frame cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting move-toolbar gtk
x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 95434 9148)
 (symbols 48 20367 1)
 (miscs 40 44 118)
 (strings 32 28319 1131)
 (string-bytes 1 742545)
 (vectors 16 14644)
 (vector-slots 8 496930 10762)
 (floats 8 49 118)
 (intervals 56 263 0)
 (buffers 992 11))







Acknowledgement sent to Braun Gábor <braungb88@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#34405; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sat, 9 Feb 2019 20:00:01 UTC

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