Subject: [PATCH] Fix minibuffer-nonselected-mode when using recursive minibuffers

From: Steven Allen <[email-masked]>
Date: Fri, 19 Sep 2025 11:07:22 -0700

Tags: patch

When recursive minibuffers are enabled and minibuffer window restoration
is disabled, minibuffer-nonselected-mode fails to "unhighlight" the
minibuffer prompt. The fix is to use window-state-change-functions
instead of window window-selection-change-functions.

To reproduce:

1. Run: emacs -Q --eval '(setopt enable-recursive-minibuffers t read-minibuffer-restore-windows nil)'
2. M-x
3. C-x o
4. M-x
5. C-g

At this point (once the "Quit" message disappears) you'll be left at a
focused M-x prompt that's highlighted as if it were unfocused.

In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, cairo version
 1.18.4) of 2025-09-11 built on Laptop
Repository revision: 819574e13e5dcefdff136033012d6d34f8940848
Repository branch: makepkg
Windowing system distributor 'The X.Org Foundation', version 11.0.12101018
System Description: Arch Linux

Configured using:
 'configure
 'CPPFLAGS=-I/run/user/1000/build/emacs-git/src/mps-git/build/include '
 'LDFLAGS=-L/run/user/1000/build/emacs-git/src/mps-git/build/lib -Wl,-O1
 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now
 -Wl,-z,pack-relative-relocs -flto=auto' --prefix=/usr --sysconfdir=/etc
 --libexecdir=/usr/lib --localstatedir=/var --mandir=/usr/share/man
 --with-gameuser=:games --with-modules --without-m17n-flt
 --without-selinux --without-pop --without-gconf --disable-gc-mark-trace
 --with-mps=yes --enable-autodepend --enable-link-time-optimization
 --with-native-compilation=yes --with-xinput2 --with-x-toolkit=no
 --without-toolkit-scroll-bars --without-xaw3d --without-gsettings
 --with-cairo-xcb --without-xft --with-sound=no --with-tree-sitter
 --without-gpm --without-compress-install
 '--program-transform-name=s/\([ec]tags\)/\1.emacs/'
 'CFLAGS=-march=native -mtune=native -O3 -pipe -fno-plt -fexceptions
 -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security
 -fstack-clash-protection -fcf-protection -fomit-frame-pointer
 -fno-math-errno -fno-trapping-math -Os -fno-math-errno
 -fno-trapping-math -Os -flto=auto''

>From 0485d70f58695a3d71c392af92861055ca03b4fa Mon Sep 17 00:00:00 2001
From: Steven Allen <[email-masked]>
Date: Fri, 19 Sep 2025 10:34:47 -0700
Subject: [PATCH] Fix minibuffer-nonselected-mode when using recursive
 minibuffers

* lisp/minibuffer.el (minibuffer-nonselected-setup): Use
window-state-change-functions instead of
window-selection-change-functions to detect changes from one recursive
minibuffer to another within the same minibuffer-window.
---
 lisp/minibuffer.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index ff1b68b49a4..5aa491fa4c4 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -5623,7 +5623,7 @@ minibuffer-nonselected-check
           (setq minibuffer-nonselected-overlay ov))))))
 
 (defun minibuffer-nonselected-setup ()
-  (add-hook 'window-selection-change-functions
+  (add-hook 'window-state-change-functions
             'minibuffer-nonselected-check nil t))
 
 (define-minor-mode minibuffer-nonselected-mode
-- 
2.51.0