emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Undo complex command


From: Stefan Monnier
Subject: Re: Undo complex command
Date: Tue, 23 Mar 2021 09:55:42 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> I use repeat complex command often (BTW, why doesn't the built in
> version have completion? It's much better that way.) and

It's always better with completion, indeed.  The reason why there is
currently no completion for it is simple: you just forgot to include the
patch for it in your message.
But don't worry, it happens to the best of us.  Just include it in your
next message and all will be forgiven.

> Then if I want to revert a particular change, I could say
> M-x undo-complex-change, select a command from the undo
> list and then I'd get its diff in a buffer and then I
> could revert any hunk or the whole diff altogether. (Like
> with regular diffs the diff can be applied as long as the
> text did not change significantly since then.)
>
> What do you think? Could it be a useful feature?

Sounds like a great idea, and it could be used with all commands (tho
you'd probably want to weed out the trivial `self-insert-command`s and
`delete-char`s).  I don't think you need to store the diff, because you
can (re)create the diff from the current undo info.

Here's how I imagine you could implement it:
1- copy the current `buffer-string` along with the `buffer-undo-list` to
   a new buffer.
2- save that buffer's content to a temp file.
3- call undo in that temp buffer
4- run a diff between the temp file and the current content of the temp buffer
5- display it to the user
6- if the user hits M-p (or something like that) you go back to 2.
7- else you try to apply that diff to the main buffer's contents
   (e.g. using diff-apply-hunk).

In step 1 you'll probably want to filter out all the marker updates
from the `buffer-undo-list`.  And at step 6 you'll probably want to
allow M-n.

Results would be better if the undo log included some information you
could show to the user such as the command name, but currently that's
not available.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]