From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#39680: 27.0.60; electric-pair-mode broken by undo Date: Mon, 09 Mar 2020 14:26:21 -0400 Message-ID: References: <87pneaifya.fsf@gmail.com> <20200225193451.GA5896@ACM> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="114156"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 39680@debbugs.gnu.org, =?UTF-8?Q?K=C3=A9vin?= Le Gouguec To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Mar 09 19:27:12 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jBN7Q-000TYj-Kn for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 09 Mar 2020 19:27:12 +0100 Original-Received: from localhost ([::1]:47794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBN7P-0006Z1-DC for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 09 Mar 2020 14:27:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40597) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jBN7H-0006Yh-G9 for bug-gnu-emacs@gnu.org; Mon, 09 Mar 2020 14:27:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jBN7G-0005ux-FY for bug-gnu-emacs@gnu.org; Mon, 09 Mar 2020 14:27:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:45484) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jBN7G-0005uo-9r for bug-gnu-emacs@gnu.org; Mon, 09 Mar 2020 14:27:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jBN7G-0004av-74 for bug-gnu-emacs@gnu.org; Mon, 09 Mar 2020 14:27:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 09 Mar 2020 18:27:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 39680 X-GNU-PR-Package: emacs Original-Received: via spool by 39680-submit@debbugs.gnu.org id=B39680.158377839117623 (code B ref 39680); Mon, 09 Mar 2020 18:27:02 +0000 Original-Received: (at 39680) by debbugs.gnu.org; 9 Mar 2020 18:26:31 +0000 Original-Received: from localhost ([127.0.0.1]:51457 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jBN6l-0004aA-10 for submit@debbugs.gnu.org; Mon, 09 Mar 2020 14:26:31 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:42091) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jBN6k-0004Zx-3e for 39680@debbugs.gnu.org; Mon, 09 Mar 2020 14:26:30 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id F1AF181234; Mon, 9 Mar 2020 14:26:23 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 1C3D9810A0; Mon, 9 Mar 2020 14:26:22 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1583778382; bh=Rqg1+sUNGh+Z4j6c3dWCKu9KxFEPr8VA0waeNcT4e5M=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=h7klIznnh9NNBdxyqLneoJmgwdIUbPyXaKitZs6vZcriibVsgYJ+NwZLvML1UJCWz Y1WfS/79CBB09WkK6pR5i+RagQ3H9pCA8RviehTDIn5g19ekNNF+Y1U/5v1/tIifRG 1IDY3NJjZVxixBXPBHdbR3wTJMNEb75hM2kHTecsK+4A0+RNHm5nIojxi2i4x+ddeu uhShPvhGd8ySjsAOxqaVFa/9aQF/JB8+N8FaZ5y9kQXoIgZgFFcJ9byVO/O5ZZtQUC 4hBFxdqyk/bj3l0F7XrN1Pb2wopz/JgtorKg+ZmNPg+jtV77RE7Zk0YwZ41OGoickz M3qZbgDdAidIA== Original-Received: from alfajor (modemcable157.163-203-24.mc.videotron.ca [24.203.163.157]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id EFD6F1202FC; Mon, 9 Mar 2020 14:26:21 -0400 (EDT) In-Reply-To: <20200225193451.GA5896@ACM> (Alan Mackenzie's message of "Tue, 25 Feb 2020 19:34:51 +0000") 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:177103 Archived-At: > The cause of this bug is a bug in cancel-change-group, Indeed. Thanks Alan for the nice analysis (and sorry I didn't get to it earlier). > (unless (eq last-command 'undo) (undo-start)) <======= > ;; Make sure there's no confusion. > ============> (when (and (consp elt) (not (eq elt (last pending-undo-list)))) > . At the first indicated spot above, last-command is indeed 'undo, so > undo-start is not invoked. I think there's a bug right here: the fact that the previous command was `undo` shouldn't really matter. Worse, we've made changes to the buffer since that last `undo` so it's plain wrong to pass that old `pending-undo-list` to `undo-more`. > Stefan, what is your view on this attempted patch? Is it sound? I think we need something like the patch below (not really tested yet). WDYT? >> Thank you for your time. > Thank you for a good bug report, conveniently reduced to a minimum test > case. Indeed. This is pretty delicate code, so a concise and easy to reproduce test case is very welcome. Stefan diff --git a/lisp/subr.el b/lisp/subr.el index 13515ca7da..ebc8e320dc 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2972,13 +2972,14 @@ cancel-change-group ;; the body of `atomic-change-group' all changes can be undone. (widen) (let ((old-car (car-safe elt)) - (old-cdr (cdr-safe elt))) + (old-cdr (cdr-safe elt)) + (start-pul pending-undo-list)) (unwind-protect (progn ;; Temporarily truncate the undo log at ELT. (when (consp elt) (setcar elt nil) (setcdr elt nil)) - (unless (eq last-command 'undo) (undo-start)) + (setq pending-undo-list buffer-undo-list) ;; Make sure there's no confusion. (when (and (consp elt) (not (eq elt (last pending-undo-list)))) (error "Undoing to some unrelated state")) @@ -2991,7 +2992,13 @@ cancel-change-group ;; Reset the modified cons cell ELT to its original content. (when (consp elt) (setcar elt old-car) - (setcdr elt old-cdr)))))))) + (setcdr elt old-cdr))) + ;; Let's not break a sequence of undos just because we + ;; tried to make a change and then undid it: preserve + ;; the original `pending-undo-list' if it's still valid. + (if (eq (undo--last-change-was-undo-p buffer-undo-list) + start-pul) + (setq pending-undo-list start-pul))))))) ;;;; Display-related functions.