From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Campbell Barton Newsgroups: gmane.emacs.devel Subject: Re: Support for undo-amalgamate in a version of the atomic-change-group macro (with patch) Date: Sun, 7 Nov 2021 19:45:54 +1100 Message-ID: References: <2d2efa59-cf88-5238-0db6-58d55e6c5c98@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="000000000000285df605d02ee810" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28581"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier To: Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Nov 07 09:47:15 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 1mjdpa-00077z-Ky for ged-emacs-devel@m.gmane-mx.org; Sun, 07 Nov 2021 09:47:14 +0100 Original-Received: from localhost ([::1]:34096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mjdpY-0006rM-UA for ged-emacs-devel@m.gmane-mx.org; Sun, 07 Nov 2021 03:47:12 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58356) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjdoX-0006Ae-O9 for emacs-devel@gnu.org; Sun, 07 Nov 2021 03:46:09 -0500 Original-Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:33667) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mjdoV-00065t-UB for emacs-devel@gnu.org; Sun, 07 Nov 2021 03:46:09 -0500 Original-Received: by mail-pj1-x1035.google.com with SMTP id w33-20020a17090a6ba400b001a722a06212so2628646pjj.0 for ; Sun, 07 Nov 2021 01:46:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=0sYrCUCeHGl1/1lbh9CTEfgzndr24gdYHdBcJCM7a/s=; b=cNZsQ7iTclPUp+qGfNXusWjJBLPemsdSgIJPBUnMxNCnbA9aDFH3QaZ6eJkQ+qOl4P 6el49bmzPoqoXu4iWStyMjtQH1JO724xpWBZCXNtMCqGR8tPbzribYmIESQ/d3vQ+McP NzmQWbOd2BTplWhBYOEVS1YNDzim8BwImqX56donN5eSY/xxSaRDCXBEZcPpJb/En558 /1KWMThjK1ZSz/akd+RoVd/JwXSC+dXoPHlwZpUtluqwIUc5K7CuYSas0sq4NzqVY2mG MHhrhgvs5XRKg5VeVgiKnIPBzrFLQBODVBff6yqHKbGty/PmEDCurr7gKspt7A+ZRmQ7 Uzjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=0sYrCUCeHGl1/1lbh9CTEfgzndr24gdYHdBcJCM7a/s=; b=OlG0ALJuqoYYO1X8TJ+e/RwUv7s6max+0YoO/bGy/MuWTmblif4P/4WfimpGGcXK9y wUtZ5fHEf7TVdhIe04er0foNsmHqTNn2jgB6E31ArEkrSfcp/IRw8376qysnvF6j1BBD qhJc/VxFjYDVgH0kKDzRu3twBpjQOHqCzl6BzBU3aP5JyOifFiGGm8vdWokC8WpeGsWN 61QvlcK/omqD945yqd1a5aeuVauGiWw8QQzzqBuC332zHkjh7cATHHj267ry+VH5n917 cCL2JV8SxVzT6Z2xOVqs6EpOXgWSfljjAOi6WXr+sqTZMOLuBGCd5kSBVSw7TdUQKFqF 5wkA== X-Gm-Message-State: AOAM5320Q9ZBDyH2hEaJj1E056Ej5o4jolC0nPDj52fG3v9F21n0wqYE P5WoY4+f7wX/w5CW/zso1QQGLqWGYqKlAEZRHep8G0NI X-Google-Smtp-Source: ABdhPJyFOVmIusxqi7E9jdCqRliR6uCvAFZZmPAoPwla0SJURsjkiZ7DxlMrsu0Nt5bPrlIiQaXc7IZ54St3lUV2AAw= X-Received: by 2002:a17:902:6b83:b0:141:6368:3562 with SMTP id p3-20020a1709026b8300b0014163683562mr61671104plk.42.1636274765554; Sun, 07 Nov 2021 01:46:05 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=ideasman42@gmail.com; helo=mail-pj1-x1035.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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_ENVFROM_END_DIGIT=0.25, 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.29 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:278923 Archived-At: --000000000000285df605d02ee810 Content-Type: text/plain; charset="UTF-8" On Tue, Nov 2, 2021 at 1:14 PM Campbell Barton wrote: > > On Tue, Nov 2, 2021 at 12:04 PM Campbell Barton wrote: > > > > On 11/2/21 04:43, Stefan Monnier wrote: > > >> Hi, there have been a handful of times I've needed to treat multiple > > >> actions as a single action, > > >> others too (see stackoverflow question [0]). > > >> > > >> While this is supported using change groups, the resulting macro ends > > >> up being nearly identical to the existing `atomic-change-group' macro. > > >> The only difference is a call to undo-amalgamate-change-group. > > > > > > The other difference would be the call to `cancel-change-group` (you > > > may want to not undo the changes in case of errors). > > > > Good point (updated my answer) > > > > >> Attached a patch to add `atomic-change-group-undo-amalgamate' so > > >> packages don't need to use a modified copy of this macro. > > > > > > I suspect that we'd be better off with a separate macro which only does > > > the amalgamation without the cancel-change-group-on-error. > > > > Agree, if the cancel group is removed it's no longer atomic and can be a > > separate macro. > > > > > But I wonder how often such a macro would be useful: undo boundaries are > > > normally added only by the command-loop (i.e. the loop which repeatedly > > > reads a key and calls the corresponding command), so unless your macro's > > > body calls `recursive-edit` it's very unlikely that you'll get any undo > > > entries that you would then want to remove. > > > > I'm not sure why most other people are running into this (the original > > question relates specifically voice commands), nevertheless the stats on > > the stackexchange question lead me to think it's not so unusual to spawn > > multiple commands that happen to be treated as separate undo steps. > > > > > (Re)reading your stackexchange question, it seems you want to amalgamate > > > undo entries from different commands. So do you run those commands > > > within a `recursive-edit`? If not, how do you manage to run those > > > commands from within your (new) macro? > > > > As far as I know I'm not using recursive edit (unless indirectly). > > > > In these situations collapsing undo data was necessary. > > > > - Calling kmacro-exec-ring-item (based on this answer [0]) > > - Calling some evil functions for e.g. > > > > (defun evil-paste-and-indent-after () > > (interactive) > > (with-undo-collapse > > (evil-paste-after 1) > > (evil-indent (evil-get-marker ?\[) > > (evil-get-marker ?\])))) > > > > [0]: https://emacs.stackexchange.com/questions/70 > > To follow up on my previous post, from checking packages on melpa, the > following use an undo-collapse macro: > > - recomplete (recomplete--with-undo-collapse) > - jupyter (jupyter-repl-with-single-undo) > - meow (meow--wrap-collapse-undo) > - symex (symex--with-undo-collapse) > > Candidates which could potentially use an undo collapse macro but mix > undo-amalgamate with other logic: > > - eglot (eglot--apply-text-edits) > - lsp-mode (lsp--apply-text-edits) > - parinfer-rust-mode (parinfer-rust--execute) Here is an updated patch with a separate macro to amalgamate undo barriers. -- - Campbell --000000000000285df605d02ee810 Content-Type: text/x-patch; charset="US-ASCII"; name="emacs-with-undo-amalgamate-change-group.diff" Content-Disposition: attachment; filename="emacs-with-undo-amalgamate-change-group.diff" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_kvozpjdh0 Y29tbWl0IDdjYWFhMDE3YWE0Y2ZjNTI0MzE3ODYxOGE4ODYzMzUyNWE4ZTE4YjMKQXV0aG9yOiBD YW1wYmVsbCBCYXJ0b24gPGlkZWFzbWFuNDJAZ21haWwuY29tPgpEYXRlOiAgIFN1biBOb3YgNyAx OTozOToyOSAyMDIxICsxMTAwCgogICAgQWRkICd3aXRoLXVuZG8tYW1hbGdhbWF0ZS1jaGFuZ2Ut Z3JvdXAnIG1hY3JvCiAgICAKICAgIFRoaXMgYWxsb3dzIGNvbW1hbmRzIHRvIGJlIG1hZGUgd2l0 aG91dCBhZGRpbmcgdW5kby1iYXJyaWVycywgZS5nLgogICAga21hY3JvLWV4ZWMtcmluZy1pdGVt LgoKZGlmZiAtLWdpdCBhL2xpc3Avc3Vici5lbCBiL2xpc3Avc3Vici5lbAppbmRleCBmNmRiZDAw NTMyLi45NDVhYWE4ZmVmIDEwMDY0NAotLS0gYS9saXNwL3N1YnIuZWwKKysrIGIvbGlzcC9zdWJy LmVsCkBAIC0zNTQyLDYgKzM1NDIsMjUgQEAgYXRvbWljLWNoYW5nZS1ncm91cAogCSAgICAgKGFj Y2VwdC1jaGFuZ2UtZ3JvdXAgLGhhbmRsZSkKIAkgICAoY2FuY2VsLWNoYW5nZS1ncm91cCAsaGFu ZGxlKSkpKSkpCiAKKyhkZWZtYWNybyB3aXRoLXVuZG8tYW1hbGdhbWF0ZS1jaGFuZ2UtZ3JvdXAg KCZyZXN0IGJvZHkpCisgICJMaWtlIGBwcm9nbicgYnV0IHBlcmZvcm0gQk9EWSB3aXRoIGFtYWxn YW1hdGVkIHVuZG8gYmFycmllcnMuCisKK1RoaXMgYWxsb3dzIG11bHRpcGxlIG9wZXJhdGlvbnMg dG8gYmUgdW5kb25lIGluIGEgc2luZ2xlIHN0ZXAuIgorICAoZGVjbGFyZSAoaW5kZW50IDApIChk ZWJ1ZyB0KSkKKyAgKGxldCAoKGhhbmRsZSAobWFrZS1zeW1ib2wgIi0tY2hhbmdlLWdyb3VwLWhh bmRsZS0tIikpKQorICAgIGAobGV0ICgoLGhhbmRsZSAocHJlcGFyZS1jaGFuZ2UtZ3JvdXApKQor ICAgICAgICAgICA7OyBEb24ndCB0cnVuY2F0ZSBhbnkgdW5kbyBkYXRhIGluIHRoZSBtaWRkbGUg b2YgdGhpcy4KKyAgICAgICAgICAgKHVuZG8tb3V0ZXItbGltaXQgbmlsKQorICAgICAgICAgICAo dW5kby1saW1pdCBtb3N0LXBvc2l0aXZlLWZpeG51bSkKKyAgICAgICAgICAgKHVuZG8tc3Ryb25n LWxpbWl0IG1vc3QtcG9zaXRpdmUtZml4bnVtKSkKKyAgICAgICAodW53aW5kLXByb3RlY3QKKyAg ICAgICAgICAgKHByb2duCisgICAgICAgICAgICAgKGFjdGl2YXRlLWNoYW5nZS1ncm91cCAsaGFu ZGxlKQorICAgICAgICAgICAgICxAYm9keSkKKyAgICAgICAgIChwcm9nbgorICAgICAgICAgICAo YWNjZXB0LWNoYW5nZS1ncm91cCAsaGFuZGxlKQorICAgICAgICAgICAodW5kby1hbWFsZ2FtYXRl LWNoYW5nZS1ncm91cCAsaGFuZGxlKSkpKSkpCisKIChkZWZ1biBwcmVwYXJlLWNoYW5nZS1ncm91 cCAoJm9wdGlvbmFsIGJ1ZmZlcikKICAgIlJldHVybiBhIGhhbmRsZSBmb3IgdGhlIGN1cnJlbnQg YnVmZmVyJ3Mgc3RhdGUsIGZvciBhIGNoYW5nZSBncm91cC4KIElmIHlvdSBzcGVjaWZ5IEJVRkZF UiwgbWFrZSBhIGhhbmRsZSBmb3IgQlVGRkVSJ3Mgc3RhdGUgaW5zdGVhZC4K --000000000000285df605d02ee810--