Subject: Re: bug#77942: 31.0.50; replace-region-contents gets stuck

From: Stefan Monnier <[email-masked]>
Date: Mon, 21 Apr 2025 16:31:45 -0400

Gerd Möllmann [2025-04-21 20:01:43] wrote:
> Stefan Monnier <[email-masked]> writes:
>>> This enters an (infinite?) loop
>>
>> AFAICT it's not infinite.  At least, it does end for me when the buffer
>> is smaller (100000) and it does take more time (but still end) with
>> a buffer of 500000, so I think it would end *eventually*.
>
> Just as an observation: I started with 1 run and that seemed reasonably
> fast, a few seconds, so I made it 100, which had this effect.

For the first round, how fast is it depends on your luck with the random
number generator since the time depends on the size of the region on
which you perform the replace.

Try just

    (require 'subr-x)
    
    (defun elb-replace-region-contents-entry ()
      (with-temp-buffer
        (let ((step (apply #'concat (make-list 2000 "🙂été👶🏿 "))))
          (dotimes (_ (/ 1000000 (length step)))
            (insert step)))
    
        (replace-region-contents 123 (- (point-max) 123)
                                 (lambda () "🙂été👶🏿 🙂été👶🏿 "))))

- Stefan