Subject: Re: bug#58175: 29.0.50; M-x window-swap-states during an active mark leaves behind a region overlay

From: Stefan Monnier <[email-masked]>
Date: Tue, 04 Oct 2022 17:25:13 -0400

>> IOW, I suspect the bug is in `redisplay-(un)highlight-region-function`
>> and adding `internal-region-overlay` to `window-persistent-parameters`
>> would likely just cover it for that use-case but it could
>> reoccur elsewhere.
> Hmm... then again not.  Still thinking about it.

I guess it boils down to whether it's OK for a function like
`window--state-put-2` to "unilaterally" set window parameters to nil as
it does in:

      ;; Reset window's parameters and assign saved ones (we might want
      ;; a `remove-window-parameters' function here).
      (dolist (parameter (window-parameters window))
	(set-window-parameter window (car parameter) nil))

I don't think it's right to add `internal-region-overlay` to
`window-persistent-parameters` since we don't want/need to store those
overlays in window-state objects.

We could change the above code so it only sets to nil those
parameters that are listed in `window-persistent-parameters`, but I'm
not sure if that's the right choice.  It might be, tho: it seems odd to
just zap properties owned by arbitrary packages without giving them
a chance to "say goodbye".

Or we could add some kind of hook (similar to a `change-major-mode-hook`
but for window state changes rather than major mode changes) so code
like the region-highlight code can register itself there to throw away
its overlays before a new window-state is installed.

Or we need to change the `redisplay--(un)highlight-overlay-function`s so
as to keep their overlays (and similar info) elsewhere, probably in
a variable rather than a window-parameter since window-parameters can
disappear without warning.

        Stefan