[Top][All Lists]

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

bug#17235: Undo in region adjusts past positions incorrectly

From: Barry OReilly
Subject: bug#17235: Undo in region adjusts past positions incorrectly
Date: Thu, 10 Apr 2014 10:00:06 -0400

I constructed a recipe using emacs -Q to demonstrate a flaw in
undo-make-selective-list. Each bullet should be a distinct change

* Insert 12345
* Delete the 4, buffer has: 1235
* Insert xxxx such that: xxxx1235
* Insert yy such that: xxxxyy1235
* Select "35", undo in region, expected 4 to come back, but nothing
* Select "1235", undo in region, the 4 returns to the wrong place,
  buffer has: xxxxyy14235

After these steps are executed in *scratch*, buffer-undo-list is:

 (199 . 200)
 (196 . 198)
 (192 . 196)
 (#("4" 0 1
    (fontified t))
  . -195)
 (192 . 197)
 (t . 0)
 (1 . 192)
 (t . 0))

Clearly the (196 . 198) ought to have caused the ("4" . -195) to
adjust by 2, but it didn't because its adjustment due to (192 . 196)
was not applied yet.

I think the algorithm would be simpler to make correct if adjustments
are applied forward chronologically rather than backwards. That is,
the algorithm keeps a list of undo-deltas that grows as the algorithm
iterates backwards through undo history. As it does so, the positions
are adjusted chronologically forward through the undo-deltas. This
approach is O(N**2), as the current algorithm also is, but the bright
side is the proposed algorithm lends itself to short circuiting better
than the current.

Let me know if you have other ideas and I'll prepare a patch.

reply via email to

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