Subject: Re: bug#76108: Call `modify_text' only on the text being replaced in `subst-char-in-region'

From: Thuna <[email-masked]>
Date: Sat, 08 Feb 2025 19:42:37 +0100

>> Now, I am not entirely sure how I've managed to miss this, but
>> `subst-char-in-region' actually _also_ messes up the after calls.  I
>> have no idea how or why this is happening, but a buffer whose contents
>> are
>>
>>   "foo bar\nquux baz ban"
>>
>> with an overlay from 14 to 17 (that is, around the word "baz") with the
>> modification hook
>>
>>   (lambda (&rest args) (print args))
>>
>> reports being called with the arguments
>>
>>   (#<overlay from 17 to 17 in temp> nil 8 21)
>>   (#<overlay from 14 to 17 in temp> t 8 9 1)
>>
>> when I do
>>
>>   (subst-char-in-region (point-min) (point-max) ?\n ?\s)
>
> The `nil 8 21` and `t 8 9 1` are the values I'd expect, but the `17 to
> 17` seems very odd and the fact that the hook is called at all for the
> "after" case sounds like a bug, as you point out.

It doesn't change anything but I should make a correction: That first
case is also an overlay from 14 to 17.