Subject: Re: bug#47894: 28.0.50; isearch does not work if enable-recursive-minibuffers is on and some input method is set.

From: Gregory Heytings <[email-masked]>
Date: Tue, 20 Apr 2021 22:35:47 +0000

>
> Additionally, on emacs-devel Zhiwei Chen said this:
>
>  It failed to work when buffer is auto selected via
>  `display-buffer-alist’.  When the point moves to the *Occur* buffer,
>  typing “n”, “p” still sends “n”, “p” to isearch.
>
>  (defun display-buffer-select (buffer alist)
>    (let ((window (display-buffer-below-selected buffer alist)))
>      (when (window-live-p window)
>        (select-window window))))
>
>  (setq display-buffer-alist '(("\\*Occur\\*" (display-buffer-select))))
> 
> Maybe this could be handled as well?
>

And this one is strange, too, for two reasons:

- display-buffer-select is not a documented action, and does not even 
appear in the sources (even Google does not find it!), yet it works;

- After this action, point has moved, but (current-buffer) does not return 
the buffer where point is; (window-buffer (selected-window)) does.  It 
seems to me that at the top-level these two should always be equal; 
apparently they are not.

Again it's not clear to me whether the bug is here or elsewhere, but the 
attached patch fixes the original problem and the two bugs.

Cc'ing Martin, who may have some insights on the above two points.

From fc1399ffbbc1385536ce03237813092c6a804adc Mon Sep 17 00:00:00 2001
From: Gregory Heytings <[email-masked]>
Date: Tue, 20 Apr 2021 22:13:27 +0000
Subject: [PATCH] Terminate isearch when point has moved to another buffer

* lisp/isearch.el (isearch-post-command-hook): Terminate isearch
when the command just executed has moved point to another buffer.
https://lists.gnu.org/archive/html/emacs-devel/2021-04/msg00309.html

This improves commit ff796823e5 for the cases when an input method is
used and enable-recursive-minibuffers is set (Bug#47894), and when a
buffer is automatically selected with a display-buffer-select in
display-buffer-alist (see
https://lists.gnu.org/archive/html/emacs-devel/2021-04/msg00458.html )
---
 lisp/isearch.el | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lisp/isearch.el b/lisp/isearch.el
index 69fdc9df6d..d4763f21f9 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -3057,9 +3057,10 @@ isearch-post-command-hook
          (isearch-search-and-update)))
      (setq isearch-pre-move-point nil))
   ;; Terminate the search if point has moved to another buffer.
-  (unless (eq isearch--current-buffer (current-buffer))
-    (when (buffer-live-p isearch--current-buffer)
-      (with-current-buffer isearch--current-buffer (isearch-exit))))
+  (unless (minibufferp (current-buffer))
+    (unless (eq isearch--current-buffer (window-buffer (selected-window)))
+      (when (buffer-live-p isearch--current-buffer)
+        (with-current-buffer isearch--current-buffer (isearch-exit)))))
   (force-mode-line-update))
 
 (defun isearch-quote-char (&optional count)
-- 
2.30.2