Subject: bug#77580: [PATCH] New command ediff-undo

From: "Paul D. Nelson" <[email-masked]>
Date: Tue, 08 Apr 2025 07:25:20 +0200

> Cool.  There is ediff-with-current-buffer so probably it should be named
> ediff-with-undo, like you already have diff-with-undo.

I appreciate this suggestion, but it's less clear to me for a few
reasons:

- ediff-with-current-buffer is an internal macro.

- the user-facing Ediff commands omit words like "with".

- I used "diff-with-undo" just because "diff-undo" was taken by a
  more-or-less internal helper function (undo inhibiting read-only).

As I see it, the advantages of "ediff-undo" are internal consistency
with user-facing ediff-* commands, and brevity (for the command name,
and buffer names like "*ediff-undo*").  The disadvantage is that it is
not quite parallel to "diff-with-undo".  On the other hand, the two sets
of commands are already not particularly consistent in their naming.

I still lean towards "ediff-undo" given its brevity and internal
consistency, but would be happy to discuss further.

>> In practice, I've just spammed C-u enough times.  I considered
>> allowing a negative argument to signal "undo everything", which would
>> be most useful with an active region; how does that sound?
>
> Wouldn't undoing everything just be the existing diff-buffer-with-file?
> That doesn't seem right.

The proposed operation of diff-with-undo with a negative argument C--
would differ from diff-buffer-with-file in some cases:

- With an active region, it would preview undo restricted to that
  region.

- If you've saved the file more than once in the current session, "undo
  everything" goes to the state at the beginning of the session rather
  than the last save.

Let me know if you think this feature seems worth including.  I lean
towards "no" out of a desire to keep the new commands consistent with
"undo" itself, which does not accept a negative argument.

>
>> I hadn't thought about automatic detection along the lines that you
>> suggest.  I think I'm happy to leave that for now, either to a
>> refinement of this command or a future one.
>
> To be honest, I don't like adding a command where the normal way to use
> it is to spam C-u.  The normal way to use it should be easy to access.
> So let's try to think of something better.

Agreed.

Thinking further, this scenario seems niche rather than normal.  The
original intent might be met more directly by some new command such as
revert-buffer-in-region, diff-buffer-with-file-in-region,
vc-diff-in-region, diff-backup-in-region, (...).

The situation resembles that of the undo command itself.  Typically, we
should either undo small amounts, or resort to one of the structural
undo-like commands tied to file or VC status.  Only rarely should we
need to do something like C-99 C-/ (possibly in a region), but that
option remains a useful fallback.