Subject: bug#16411: undo-only bugs

From: Stefan Monnier <[email-masked]>
Date: Wed, 14 May 2014 15:55:47 -0400

> Having undo elements reference what they undid would help solve
> several issues:

>    1: undo-only in region doesn't work.
>    2: Normal undo-only after an undo in region doesn't work. I've
>       previously outlined how the solution would use the
>       undo-redo-table.
>    3: Undo in region has counter intuitive behavior as described in
>       the FIXME of simple.el describing undo in region.
>    4: Deleting X bytes, then doing Y iterations of undo and redo
>       causes undo history to grow about X*Y. To grow proportional to Y
>       should be achievable: set undo-in-progress to the in progress
>       element, and the C level undo recording to use it and
>       undo-redo-table to find the eq Lisp_String.
>    5: Undo Tree should more tightly integrate with the builtin undo
>       system. To do so, it needs sufficient information to visualize
>       the buffer-undo-list as a tree. Undo Tree has a means to
>       visualize undo in regions, so undo-equiv-table is inadequate.

IIUC this undo-redo-table business is only necessary because of
undo-in-region.  So I think we should strive to minimize the changes to
the way undo works in the absence of undo-in-region.  I understand that
the change can't be all localized in undo-in-region (because of the need
to skip "redo-in-region" during normal undo-only, basically), but we
still should try to aim in that direction.

> There are variations on how elements could reference what they undid,
> but fundamentally I think it is essential. I wish to know how you like
> the direction the patch is going as I proceed to solve some problems
> building upon it.

I think we should try to keep the "one entry per undo boundary" rather
than go for "one entry per undo element".

> The reason undo-redo-table maps at the element level, as opposed to
> the change group level, is because in the case of undo in region with
> a prefix arg, the newly created change group needs to reference
> subsets of potentially many prior change groups.

IIUC the crux of the matter is how to record the redo data for an
undo-in-region.  The way I see it, for such a "redo-in-region" group, we
indeed need to remember which elements it undid (and which ones it
skipped instead), but we could store that info as a single entry in
an undo-redo/equiv-table.

        Stefan