Subject: Re: bug#21523: 25.0.50; Undo with active region adds extra text

From: Lars Ingebrigtsen <[email-masked]>
Date: Wed, 18 Aug 2021 15:31:36 +0200

Eli Zaretskii <[email-masked]> writes:

> Is signaling an error okay?

Yup.

> Because then it looks like an off-by-one
> error somewhere -- the following slightly modified recipe works as
> expected:
>
>   emacs -Q
>   C-u 23 M-g c ; go to "text"
>   M-c
>   C-f          ; the crucial difference!
>   C-SPC
>   C-e
>   C-/
>     => user-error: No further undo information for region
>
> So the problem seems to be that in the original recipe the region
> starts immediately after the end of the modified portion of text.

Yup; I'm seeing the same thing, so this does indeed look like a
off-by-one error.  And...  it's in `undo-elt-in-region', I think, called
by (basically) (undo-make-selective-list (mark) (point)).

There's basically no test cases for this function, I think?

Actually, the problem seems to be in undo-adjust-elt, which was
rewritten in 2014 to fix bug#17235.

I've now added a test case (commented out), but I don't quite understand
the logic in undo-adjust-elt...  anybody see something obviously wrong?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no