From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Braun =?UTF-8?Q?G=C3=A1bor?= Newsgroups: gmane.emacs.bugs Subject: bug#34405: 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="266820"; mail-complaints-to="usenet@blaine.gmane.org" To: 34405@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Feb 09 19:05:39 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gsX0U-0017FD-EY for geb-bug-gnu-emacs@m.gmane.org; Sat, 09 Feb 2019 19:05:38 +0100 Original-Received: from localhost ([127.0.0.1]:48377 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gsX0T-0008Ff-Dh for geb-bug-gnu-emacs@m.gmane.org; Sat, 09 Feb 2019 13:05:37 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:59747) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gsWz1-0007Ra-N9 for bug-gnu-emacs@gnu.org; Sat, 09 Feb 2019 13:04:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gsWyz-0003MM-N8 for bug-gnu-emacs@gnu.org; Sat, 09 Feb 2019 13:04:07 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42213) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gsWyy-0003Lg-Qj for bug-gnu-emacs@gnu.org; Sat, 09 Feb 2019 13:04:05 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gsWyy-0008A9-K6 for bug-gnu-emacs@gnu.org; Sat, 09 Feb 2019 13:04:04 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Braun =?UTF-8?Q?G=C3=A1bor?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 09 Feb 2019 18:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 34405 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.154973539131278 (code B ref -1); Sat, 09 Feb 2019 18:04:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 9 Feb 2019 18:03:11 +0000 Original-Received: from localhost ([127.0.0.1]:41490 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gsWy6-00088K-Ey for submit@debbugs.gnu.org; Sat, 09 Feb 2019 13:03:11 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:49973) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gsUsp-0004kr-PK for submit@debbugs.gnu.org; Sat, 09 Feb 2019 10:49:36 -0500 Original-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 ) id 1gsUsk-0001bk-HR for submit@debbugs.gnu.org; Sat, 09 Feb 2019 10:49:30 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:36121) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gsUsj-0005VB-4k for bug-gnu-emacs@gnu.org; Sat, 09 Feb 2019 10:49:30 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gsUsh-0001Yq-TG for bug-gnu-emacs@gnu.org; Sat, 09 Feb 2019 10:49:29 -0500 Original-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 ) id 1gsUsh-0001Xu-Ib for bug-gnu-emacs@gnu.org; Sat, 09 Feb 2019 10:49:27 -0500 Original-Received: by mail-wm1-x330.google.com with SMTP id r17so8840961wmh.5 for ; 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) Original-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 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Feb 2019 07:49:25 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Mailman-Approved-At: Sat, 09 Feb 2019 13:03:08 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:155325 Archived-At: 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))