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

From: <[email-masked]>
Date: Thu, 29 Sep 2022 21:17:56 +0200

Eli Zaretskii <[email-masked]> writes:

>> Date: Thu, 29 Sep 2022 19:29:46 +0200
>> From: miha--- via "Bug reports for GNU Emacs,
>>  the Swiss army knife of text editors" <[email-masked]>
>> 
>> 1. 'C-h e' to display *Messages* in a new window
>> 2. 'C-SPC C-n' to mark an active region
>> 3. 'M-x window-swap-states'
>> 4. 'C-g C-n' to deactivate the mark
>> 
>> Notice how the region overlay stays there.
>
> "There" where?

In the *GNU Emacs* buffer, where we have originally marked a region in
step 2.

> What did you expect to happen in the above scenario, and why?

I expect the overlay to disappear after deactivating the mark with 'C-g'
in step 4.

>> window-state-put sets 'internal-region-overlay' window parameter to nil
>> without removing the actual region overlay
>
> Where in the code do you see that?  I see this:
>
>       (with-current-buffer (window-buffer window-1)
>         (dolist (overlay (overlays-in (point-min) (point-max)))
>           (let ((window (overlay-get overlay 'window)))
>             (cond
>              ((not window))
>              ((eq window window-1)
>               (overlay-put overlay 'window window-2))
>              ((eq window window-2)
>               (overlay-put overlay 'window window-1))))))
>
> AFAIU, this _swaps_ the 'window' property of the overlays, so that the
> overlay now belongs (and should be visible) in the other window.
> Which is what I should expect.

Indeed the overlay is shown in the correct window after step 3. The
problem is that it doesn't disappear after step 4
('redisplay--update-region-highlight' doesn't remove it).

> What am I missing?

Perhaps you forgot to deactivate the mark in step 4? If there is
anything unclear in the bug recipe, go ahead and ask.