From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Distinguish between regional undo and undo to the beginning in undo-equiv-table Date: Wed, 03 Mar 2021 11:50:00 -0500 Message-ID: References: <195AF8D0-1BFD-419D-88A1-69EA1FEED4D6@gmail.com> <60DCC8C7-CCA4-4113-88BE-B81A395C494D@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37609"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Mar 03 17:52:06 2021 Return-path: Envelope-to: ged-emacs-devel@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 1lHUjF-0009cJ-Bf for ged-emacs-devel@m.gmane-mx.org; Wed, 03 Mar 2021 17:52:05 +0100 Original-Received: from localhost ([::1]:43626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lHUjE-0008SK-E0 for ged-emacs-devel@m.gmane-mx.org; Wed, 03 Mar 2021 11:52:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56076) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lHUhL-00072w-AQ for emacs-devel@gnu.org; Wed, 03 Mar 2021 11:50:07 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:4957) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lHUhJ-0002wi-6O for emacs-devel@gnu.org; Wed, 03 Mar 2021 11:50:06 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 691BB80B6D; Wed, 3 Mar 2021 11:50:04 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 4DD5380438; Wed, 3 Mar 2021 11:50:02 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1614790202; bh=uqXCqyqUNkIotO404TbZPmju5N1HKkPWDZATLfnzS0c=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=CfPaA1CThFDEvE7ddnscgHRC4ieMLiGZxxVHgSiY6fKusxnCLH85YAmvnCvuT4S0F wEpXbxHHYI+V63g5aYI1d96GsjnEChixAKsVPZg6G7hTYLUOfjor24J9HDrb7VWo7Q 8qwMQNRufH6WpQJKCOyjaGsB1LuT1umYGLIZSCh47oWi7iOK2bw1SMcld2VG/bHDvv nD7JM9Pp6u1/50Fh3RiCzqc/C7qEsxEv0DGa1+oDO/ra5fV2Q8v5y9tzbylekvs77i IQw5zfofvyjpmWGQgTNYpuFah/Z+yoZXGYJk2SZ5BcZTTZk1HlNBl8KDzBYN/ytJDi iyqQaP6WRJuPQ== Original-Received: from alfajor (unknown [216.154.41.47]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 22219120208; Wed, 3 Mar 2021 11:50:02 -0500 (EST) In-Reply-To: <60DCC8C7-CCA4-4113-88BE-B81A395C494D@gmail.com> (Yuan Fu's message of "Wed, 3 Mar 2021 10:42:12 -0500") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:265896 Archived-At: > Here is a patch, I mapped undo-in-region records to 'undo-in-region. I also > fixed a bug in undo-make-selective-list: before this change, if you > undo-in-region, break the undo chain, then undo-in-region again with > undo-only, ulist would be set to t and it breaks at (setq undo-elt (car > ulist)). Thanks a lot (especially for improving the docstring ;-). In my experience, this part of the code is quite delicate and I wouldn't be surprised to find yet more bugs for other corner cases. So I think it's very important to document those corner cases with tests. Any chance you could add matching tests to test/lisp/simple-tests.el in your patch? Stefan > Yuan > > From 8c4d50409a7ad88eb85d51e79b04f3587cd36976 Mon Sep 17 00:00:00 2001 > From: Yuan Fu > Date: Wed, 3 Mar 2021 09:50:15 -0500 > Subject: [PATCH] Map redo records for undo-in-region to 'undo-in-region > > * lisp/simple.el (undo-equiv-table): Add explaination for > undo-in-region and undo to the beginning of undo list. > (undo): If equiv is 'undo-in-region or t, set to pending-undo-list to > t. If the redo is undo-in-region, map buffer-undo-list to > 'undo-in-region instead of t. > (undo-make-selective-list): Only continue when ulist is not t or > undo-in-region. > --- > lisp/simple.el | 20 +++++++++++--------- > 1 file changed, 11 insertions(+), 9 deletions(-) > > diff --git a/lisp/simple.el b/lisp/simple.el > index f8050091d5..05bf4b8784 100644 > --- a/lisp/simple.el > +++ b/lisp/simple.el > @@ -2824,8 +2824,9 @@ 'advertised-undo > > (defconst undo-equiv-table (make-hash-table :test 'eq :weakness t) > "Table mapping redo records to the corresponding undo one. > -A redo record for undo-in-region maps to t. > -A redo record for ordinary undo maps to the following (earlier) undo.") > +A redo record for undo-in-region maps to 'undo-in-region. > +A redo record for ordinary undo maps to the following (earlier) undo. > +An undo record that undoes to the beginning of the undo list maps to t.") > > (defvar undo-in-region nil > "Non-nil if `pending-undo-list' is not just a tail of `buffer-undo-list'.") > @@ -2901,7 +2902,7 @@ undo > ;; undo-redo-undo-redo-... so skip to the very last equiv. > (while (let ((next (gethash equiv undo-equiv-table))) > (if next (setq equiv next)))) > - (setq pending-undo-list equiv))) > + (setq pending-undo-list (if (consp equiv) equiv t)))) > (undo-more > (if (numberp arg) > (prefix-numeric-value arg) > @@ -2917,11 +2918,12 @@ undo > (while (eq (car list) nil) > (setq list (cdr list))) > (puthash list > - ;; Prevent identity mapping. This can happen if > - ;; consecutive nils are erroneously in undo list. > - (if (or undo-in-region (eq list pending-undo-list)) > - t > - pending-undo-list) > + (cond > + (undo-in-region 'undo-in-region) > + ;; Prevent identity mapping. This can happen if > + ;; consecutive nils are erroneously in undo list. > + ((eq list pending-undo-list) t) > + (t pending-undo-list)) > undo-equiv-table)) > ;; Don't specify a position in the undo record for the undo command. > ;; Instead, undoing this should move point to where the change is. > @@ -3234,7 +3236,7 @@ undo-make-selective-list > undo-elt) > (while ulist > (when undo-no-redo > - (while (gethash ulist undo-equiv-table) > + (while (consp (gethash ulist undo-equiv-table)) > (setq ulist (gethash ulist undo-equiv-table)))) > (setq undo-elt (car ulist)) > (cond