unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#17235: Undo in region adjusts past positions incorrectly
@ 2014-04-10 14:00 Barry OReilly
  2014-04-23  2:31 ` Stefan Monnier
  2014-05-02  0:49 ` bug#17235: Barry OReilly
  0 siblings, 2 replies; 6+ messages in thread
From: Barry OReilly @ 2014-04-10 14:00 UTC (permalink / raw)
  To: 17235

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

* 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
  changed
* 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:

(nil
 (199 . 200)
 nil
 (196 . 198)
 nil
 (192 . 196)
 nil
 (#("4" 0 1
    (fontified t))
  . -195)
 nil
 (192 . 197)
 (t . 0)
 nil
 (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.





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-05-02  0:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-10 14:00 bug#17235: Undo in region adjusts past positions incorrectly Barry OReilly
2014-04-23  2:31 ` Stefan Monnier
2014-04-23 16:20   ` Barry OReilly
2014-04-23 17:56     ` Stefan Monnier
2014-04-26 21:00       ` Barry OReilly
2014-05-02  0:49 ` bug#17235: Barry OReilly

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).