Subject: Re: bug#66403: [PATCH] Use delete-all-overlays in clean-mode

From: Joseph Turner <[email-masked]>
Date: Sun, 08 Oct 2023 14:21:13 -0700

Eli Zaretskii <[email-masked]> writes:

>> Date: Sun, 08 Oct 2023 02:57:25 -0700
>> From:  Joseph Turner via "Bug reports for GNU Emacs,
>>  the Swiss army knife of text editors" <[email-masked]>
>>
>> Is there a reason to use dolist instead of delete-all-overlays?
>
> Can the buffer be narrowed?

Ah, good catch. The following snippet only deletes ov1, whereas if you
replace the dolist with delete-all-overlays, both are deleted.

(with-current-buffer (generate-new-buffer "test-overlay-deletion")
  (insert "hello\n\nworld")
  (let ((ov1 (make-overlay 0 6))
        (ov2 (make-overlay 8 13)))
    (overlay-put ov1 'display "aaaaa")
    (overlay-put ov2 'display "bbbbb"))
  (narrow-to-region 1 6)
  ;; (delete-all-overlays)
  (dolist (overlay (overlays-in (point-min) (point-max)))
    (delete-overlay overlay))
  (widen)
  (pop-to-buffer (current-buffer)))

Joseph