From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Re: Distinguish between regional undo and undo to the beginning in undo-equiv-table Date: Wed, 3 Mar 2021 15:33:13 -0500 Message-ID: <4890CDDF-E0DD-464B-9268-AD404015129D@gmail.com> References: <195AF8D0-1BFD-419D-88A1-69EA1FEED4D6@gmail.com> <60DCC8C7-CCA4-4113-88BE-B81A395C494D@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_528A1F04-7BF8-49F3-B2FF-1B7F2BA70762" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33199"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Mar 03 21:34:45 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 1lHYCj-0008Vu-If for ged-emacs-devel@m.gmane-mx.org; Wed, 03 Mar 2021 21:34:45 +0100 Original-Received: from localhost ([::1]:55486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lHYCi-00006c-LR for ged-emacs-devel@m.gmane-mx.org; Wed, 03 Mar 2021 15:34:44 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lHYBM-0007D4-Mq for emacs-devel@gnu.org; Wed, 03 Mar 2021 15:33:21 -0500 Original-Received: from mail-qv1-xf2c.google.com ([2607:f8b0:4864:20::f2c]:38187) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lHYBJ-00060t-BE for emacs-devel@gnu.org; Wed, 03 Mar 2021 15:33:20 -0500 Original-Received: by mail-qv1-xf2c.google.com with SMTP id bh3so5591156qvb.5 for ; Wed, 03 Mar 2021 12:33:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=FOnx+SUNqPwjBtbth0pHWjFfBjCEhR5P2TJ43WfX82U=; b=T155dCVOx9s4m4Uveeiefy/bydknhe4h4FQ+oze3YsuIrG2ZgqYoOhvtMEFyCJp8Z+ AivTJDg+j/6rXymddz9gH3sgbUWpReNUr735MhDdWDo89HvjPy2c0IoOnLikIrp7W4gm v+Tl6KUg3KNN91rL/KWKereQVHuzvZdyb4sSvGRn4p88qTd7T7qdR562swk1/OV6+Pjd L3Bu+1237oZcRxEPexew971Yxg5vR7DE28dFbTn6QxACbBtkeww+lAA1N37sM5PDrTUw l3tl8yg2QjdgbOuXaJRXd7KzitEfHP5k3ggE6WHPeAKAKCWIwKyXO691weEk/rJCQ7tS 6CVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=FOnx+SUNqPwjBtbth0pHWjFfBjCEhR5P2TJ43WfX82U=; b=pUirm/Khh/PhkyLfY0zqLCHy551hyPugOlydKQ4iBRh8f9YmuGMaGO2CZtOi05Rns3 cTU8cvPmkKpB9+ewglKTfIDLgVdBCaQvwuHQDxuXEjvHZbF7xecA3qAH9BJ1RIRVnn3G ikXH6r4JXAslFGL7VluPQxPxdmnWAlfIaKmcp15f45QqoRiCGOFWHV59tSvyZco40BF/ Q3Ue0tqWKcYFSMMba5/sdqqvk83xPIhv/qkHWupVbs2i2uEZtFhXCp64/OeOFoaqMMWe 4JLYcc+LsByxc4xo9d1ftprSfkXNBTycQv2LRNyDpNo2VeC5eklFZmQIYfQGqrArNm25 nerg== X-Gm-Message-State: AOAM531GL1Eru2oi503jth97FeqPSpw5c6MzYsDUWvp05ef7cVvpGF7t SYbhZS2wwBPHIJberos2RBA= X-Google-Smtp-Source: ABdhPJzIDa8t5Ay0WggSH0Zz8fJV94Qp0U9Cm7Y0hqFndSgmJhMimzP/kWtFhToZJA3ZxT68E8sQDA== X-Received: by 2002:ad4:5d46:: with SMTP id jk6mr724404qvb.22.1614803594806; Wed, 03 Mar 2021 12:33:14 -0800 (PST) Original-Received: from ?IPv6:2601:98a:4102:3d80:20f7:9d29:1f01:15b8? ([2601:98a:4102:3d80:20f7:9d29:1f01:15b8]) by smtp.gmail.com with ESMTPSA id q11sm16174424qtr.31.2021.03.03.12.33.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Mar 2021 12:33:14 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3654.60.0.2.21) Received-SPF: pass client-ip=2607:f8b0:4864:20::f2c; envelope-from=casouri@gmail.com; helo=mail-qv1-xf2c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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:265912 Archived-At: --Apple-Mail=_528A1F04-7BF8-49F3-B2FF-1B7F2BA70762 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 >=20 > 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? >=20 This patch applies on top of the first one. I added more docstrings = since you seem to appreciate it. I came up with some simple test cases = for ordinary mapping, t and =E2=80=98undo-in-region in the table. Do you = have other corner cases in mind? I also added some simple test cases for = undo in region. I couldn=E2=80=99t wrap my head around the original = tests so I started a new one below. Yuan --Apple-Mail=_528A1F04-7BF8-49F3-B2FF-1B7F2BA70762 Content-Disposition: attachment; filename=undo-in-region-2.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="undo-in-region-2.patch" Content-Transfer-Encoding: quoted-printable =46rom=2072bbfd0e0d4c8a4175e44ccee49323323c018834=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20Yuan=20Fu=20=0ADate:=20Wed,=20= 3=20Mar=202021=2015:07:00=20-0500=0ASubject:=20[PATCH]=20checkpoint=0A=0A= ---=0A=20lisp/simple.el=20=20=20=20=20=20=20=20=20=20=20=20|=2017=20= ++++++++-=0A=20test/lisp/simple-tests.el=20|=2075=20= ++++++++++++++++++++++++++++++++++++++-=0A=202=20files=20changed,=2090=20= insertions(+),=202=20deletions(-)=0A=0Adiff=20--git=20a/lisp/simple.el=20= b/lisp/simple.el=0Aindex=2005bf4b8784..8265639305=20100644=0A---=20= a/lisp/simple.el=0A+++=20b/lisp/simple.el=0A@@=20-2826,7=20+2826,22=20@@=20= undo-equiv-table=0A=20=20=20"Table=20mapping=20redo=20records=20to=20the=20= corresponding=20undo=20one.=0A=20A=20redo=20record=20for=20= undo-in-region=20maps=20to=20'undo-in-region.=0A=20A=20redo=20record=20= for=20ordinary=20undo=20maps=20to=20the=20following=20(earlier)=20undo.=0A= -An=20undo=20record=20that=20undoes=20to=20the=20beginning=20of=20the=20= undo=20list=20maps=20to=20t.")=0A+An=20undo=20record=20that=20undoes=20= to=20the=20beginning=20of=20the=20undo=20list=20maps=20to=20t.=0A+=0A= +When=20you=20undo,=20the=20`pending-undo-list'=20shrinks=20and=0A= +`buffer-undo-list'=20grows,=20and=20Emacs=20maps=20the=20tip=20of=0A= +`buffer-undo-list'=20to=20the=20tip=20of=20`pending-undo-list'=20in=20= this=0A+table.=0A+=0A+For=20example,=20consider=20this=20undo=20list=20= where=20each=20node=20represents=20an=0A+undo=20record,=20if=20we=20undo=20= from=204,=20`pending-undo-list'=20will=20be=20at=203,=0A= +`buffer-undo-list'=20at=205,=20and=205=20will=20map=20to=203.=0A+=0A+=20= =20=20=20|=0A+=20=20=20=203=20=205=0A+=20=20=20=20|=20/=0A+=20=20=20=20= |/=0A+=20=20=20=204")=0A=20=0A=20(defvar=20undo-in-region=20nil=0A=20=20=20= "Non-nil=20if=20`pending-undo-list'=20is=20not=20just=20a=20tail=20of=20= `buffer-undo-list'.")=0Adiff=20--git=20a/test/lisp/simple-tests.el=20= b/test/lisp/simple-tests.el=0Aindex=20f2ddc2e3fb..a4816951ce=20100644=0A= ---=20a/test/lisp/simple-tests.el=0A+++=20b/test/lisp/simple-tests.el=0A= @@=20-465,8=20+465,81=20@@=20simple-tests--undo=0A=20=20=20=20=20= (simple-tests--exec=20'(backward-char=20undo-redo=20undo-redo))=0A=20=20=20= =20=20(should=20(equal=20(buffer-string)=20"abc"))=0A=20=20=20=20=20= (simple-tests--exec=20'(backward-char=20undo-redo=20undo-redo))=0A+=20=20= =20=20(should=20(equal=20(buffer-string)=20"abcde")))=0A+=20=20;;=20Test=20= undo/redo=20in=20region.=0A+=20=20(with-temp-buffer=0A+=20=20=20=20= (buffer-enable-undo)=0A+=20=20=20=20(dolist=20(x=20'("a"=20"b"=20"c"=20= "d"=20"e"))=0A+=20=20=20=20=20=20(insert=20x)=0A+=20=20=20=20=20=20= (undo-boundary))=0A=20=20=20=20=20(should=20(equal=20(buffer-string)=20= "abcde"))=0A-=20=20=20=20))=0A+=20=20=20=20(simple-tests--exec=20= '(move-beginning-of-line=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20push-mark-command=0A+=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20forward-char=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20forward-char=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20undo))=0A+=20=20=20=20(should=20(equal=20= (buffer-string)=20"acde"))=0A+=20=20=20=20(simple-tests--exec=20= '(undo-only))=0A+=20=20=20=20(should=20(equal=20(buffer-string)=20= "cde"))=0A+=20=20=20=20(simple-tests--exec=20'(undo-redo))=0A+=20=20=20=20= (should=20(equal=20(buffer-string)=20"acde"))=0A+=20=20=20=20= (simple-tests--exec=20'(undo-redo))=0A+=20=20=20=20(should=20(equal=20= (buffer-string)=20"abcde"))))=0A+=0A+(defun=20= simple-tests--sans-leading-nil=20(lst)=0A+=20=20"Return=20LST=20sans=20= the=20leading=20nils."=0A+=20=20(while=20(and=20(consp=20lst)=20(null=20= (car=20lst)))=0A+=20=20=20=20(setq=20lst=20(cdr=20lst)))=0A+=20=20lst)=0A= +=0A+(ert-deftest=20simple-tests--undo-equiv-table=20()=0A+=20=20= (with-temp-buffer=0A+=20=20=20=20(buffer-enable-undo)=0A+=20=20=20=20= (let=20((ul-hash-table=20(make-hash-table=20:test=20#'equal)))=0A+=20=20=20= =20=20=20(dolist=20(x=20'("a"=20"b"=20"c"))=0A+=20=20=20=20=20=20=20=20= (insert=20x)=0A+=20=20=20=20=20=20=20=20(puthash=20x=20= (simple-tests--sans-leading-nil=20buffer-undo-list)=0A+=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20ul-hash-table)=0A+=20=20=20=20=20=20=20=20= (undo-boundary))=0A+=20=20=20=20=20=20(should=20(equal=20(buffer-string)=20= "abc"))=0A+=0A+=20=20=20=20=20=20;;=20Tests=20mappings=20in=20= `undo-equiv-table'.=0A+=20=20=20=20=20=20(simple-tests--exec=20'(undo))=0A= +=20=20=20=20=20=20(should=20(equal=20(buffer-string)=20"ab"))=0A+=20=20=20= =20=20=20(should=20(eq=20(gethash=20(simple-tests--sans-leading-nil=0A+=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20buffer-undo-list)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20undo-equiv-table)=0A+=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20(gethash=20"b"=20ul-hash-table)))=0A+=0A= +=20=20=20=20=20=20(simple-tests--exec=20'(backward-char=20undo))=0A+=20=20= =20=20=20=20(should=20(equal=20(buffer-string)=20"abc"))=0A+=20=20=20=20=20= =20(should=20(eq=20(gethash=20(simple-tests--sans-leading-nil=0A+=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= buffer-undo-list)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20undo-equiv-table)=0A+=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20(gethash=20"c"=20ul-hash-table)))=0A+=0A+=20=20= =20=20=20=20;;=20Undo=20in=20region=20should=20map=20to=20= 'undo-in-region.=0A+=20=20=20=20=20=20(simple-tests--exec=20= '(backward-char=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20push-mark-command=0A+=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= move-end-of-line=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20undo))=0A+=20=20=20=20=20=20(should=20= (equal=20(buffer-string)=20"ab"))=0A+=20=20=20=20=20=20(should=20(eq=20= (gethash=20(simple-tests--sans-leading-nil=0A+=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= buffer-undo-list)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20undo-equiv-table)=0A+=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20'undo-in-region))=0A+=0A+=20=20=20=20=20=20;;=20= The=20undo=20that=20undoes=20to=20the=20beginning=20should=20map=20to=20= t.=0A+=20=20=20=20=20=20(deactivate-mark=20'force)=0A+=20=20=20=20=20=20= (simple-tests--exec=20'(backward-char=0A+=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20undo=20undo=20undo=0A= +=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20undo=20undo=20undo))=0A+=20=20=20=20=20=20(should=20(equal=20= (buffer-string)=20""))=0A+=20=20=20=20=20=20(should=20(eq=20(gethash=20= (simple-tests--sans-leading-nil=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20buffer-undo-list)=0A+=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= undo-equiv-table)=0A+=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= t))=0A+=20=20=20=20=20=20)))=0A=20=0A=20;;;=20undo=20auto-boundary=20= tests=0A=20(ert-deftest=20undo-auto-boundary-timer=20()=0A--=20=0A2.24.3=20= (Apple=20Git-128)=0A=0A= --Apple-Mail=_528A1F04-7BF8-49F3-B2FF-1B7F2BA70762--