Subject: 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 19:29:46 +0200

emacs -q:

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.

To make this easier to debug, instrument 'window-swap-states' by
applying the following diff

diff --git a/lisp/window.el b/lisp/window.el
index 905803b19e..daddd18b74 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -6518,8 +6518,14 @@ window-swap-states
            (height-2 (and height (window-text-height window-2 t)))
            old preserved)
       ;; Swap basic states.
+      (message "Before %S \n %S"
+               (window-parameter window-1 'internal-region-overlay)
+               (window-parameter window-2 'internal-region-overlay))
       (window-state-put state-1 window-2 t)
       (window-state-put state-2 window-1 t)
+      (message "After: %S \n %S"
+               (window-parameter window-1 'internal-region-overlay)
+               (window-parameter window-2 'internal-region-overlay))
       ;; Swap overlays with `window' property.
       (with-current-buffer (window-buffer window-1)
         (dolist (overlay (overlays-in (point-min) (point-max)))

Follow the bug recipe and notice the following messages:

Before: #<overlay from 77 to 123 in *GNU Emacs*> 
 nil
After: nil 
 nil

window-state-put sets 'internal-region-overlay' window parameter to nil
without removing the actual region overlay, so it remains there in the
buffer. I'm not sure how to fix this. Perhaps we should add
'internal-region-overlay' to 'window-persistent-parameters'? Are other
commands that use window-state-get + window-state-put affected by this
bug as well?

In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.34, cairo version 1.17.6) of 2022-09-29 built on miha-pc
Repository revision: 0edd7770e0ce70cac59f239134962d10f48dec79
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101004
System Description: Arch Linux

Configured using:
 'configure -C --prefix=/usr --without-libsystemd
 --enable-checking=yes,glyphs --enable-check-lisp-object-type
 'CFLAGS=-O0 -g3''

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBXML2 M17N_FLT MODULES NOTIFY INOTIFY PDUMPER PNG
RSVG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS WEBP X11
XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings:
  value of $LANG: en_US.utf8
  locale-coding-system: utf-8-unix

Major mode: Shell

Minor modes in effect:
  shell-dirtrack-mode: t
  comint-fl-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util text-property-search mm-decode mm-bodies mm-encode
mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047
rfc2045 ietf-drums mm-util mail-prsvr mail-utils sh-script smie
executable files-x shell pcomplete comint osc ansi-color ring tabify
thingatpt help-fns radix-tree help-mode cus-edit pp cus-start cus-load
icons wid-edit time-date subr-x cl-loaddefs cl-lib rmc iso-transl
tooltip eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/x-win x-win term/common-win x-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock
font-lock syntax font-core term/tty-colors frame minibuffer nadvice seq
simple cl-generic indonesian philippine cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite emoji-zwj charscript charprop case-table
epa-hook jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button
loaddefs faces cus-face macroexp files window text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting cairo
move-toolbar gtk x-toolkit xinput2 x multi-tty make-network-process
emacs)

Memory information:
((conses 16 77394 9282)
 (symbols 48 8002 0)
 (strings 32 23223 1949)
 (string-bytes 1 634193)
 (vectors 16 13518)
 (vector-slots 8 208026 15295)
 (floats 8 46 42)
 (intervals 56 1050 0)
 (buffers 1000 16))