unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Campbell Barton <ideasman42@gmail.com>
To: Emacs developers <emacs-devel@gnu.org>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>
Subject: Re: Support for undo-amalgamate in a version of the atomic-change-group macro (with patch)
Date: Tue, 2 Nov 2021 12:04:33 +1100	[thread overview]
Message-ID: <2d2efa59-cf88-5238-0db6-58d55e6c5c98@gmail.com> (raw)
In-Reply-To: <jwvzgqnss0m.fsf-monnier+emacs@gnu.org>

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

> 
> 
>          Stefan
> 




  reply	other threads:[~2021-11-02  1:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-29  1:48 Support for undo-amalgamate in a version of the atomic-change-group macro (with patch) Campbell Barton
2021-11-01 17:43 ` Stefan Monnier
2021-11-02  1:04   ` Campbell Barton [this message]
2021-11-02  2:14     ` Stefan Monnier
2021-11-02  2:14     ` Campbell Barton
2021-11-07  8:45       ` Campbell Barton
2021-11-07 13:21         ` Stefan Monnier
2021-11-07 23:09           ` Campbell Barton
2021-11-07 23:29             ` Campbell Barton
2021-11-08  4:39             ` Stefan Monnier
2021-11-08  4:46               ` Lars Ingebrigtsen
2021-11-08  5:41                 ` Campbell Barton
2021-11-08 13:40                   ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2d2efa59-cf88-5238-0db6-58d55e6c5c98@gmail.com \
    --to=ideasman42@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).