Subject: Re: bug#16411: undo-only bugs

From: Barry OReilly <[email-masked]>
Date: Fri, 14 Feb 2014 13:51:38 -0500

Here's another bug with recipe. Again, each "insert" should be a
change group.

  * ./src/emacs -Q
  * In *scratch* at least twice:
    * Insert "aaa"
    * Undo
  * Select the entire buffer
  * Undo in region with prefix-arg 4
  * Observe the wrongful deletion of the string: "fer." in the Lisp
    comment.

undo-elt-in-region has a discrepency between whether (TEXT . POSITION)
and (BEGIN . END) are in the region:

  ;; (BEGIN . END)
  (and (>= (car undo-elt) start)
       (<= (cdr undo-elt) end))
        ^^

  ;; (TEXT . POSITION)
  (and (>= (abs (cdr undo-elt)) start)
       (< (abs (cdr undo-elt)) end))
        ^

One is compared to the end by <= and the other by <. Consequently,
(192 . 195) is deemed in the region, (aaa . 192) outside the region.
With (aaa . 192) outside the region, all subsequent positions of
undo-list-copy are decremented by three, including the next (192 .
195) which becomes (189 . 192). (189 . 192) is deemed in the region,
but that's not valid given the restoration of "aaa" was just excluded.
It's now pear shaped.

I'm collecting these bugs related to the undo system in one bug report
because that is the most organized way for me to address them.