Subject: 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 21:51:38 +0000

>
> Thanks for the reminder; I had seen Zhiwei Chen's message, but not this 
> bug. I'll have a look.
>

This bug is rather strange.  When an input method is used, 
isearch-post-command-hook is executed twice, once in the current isearch 
buffer and once in the minibuffer.

When enable-recursive-minibuffers is unset, the execution of isearch-exit 
fails with "Command attempted to use minibuffer while in minibuffer", so 
the error is not visible (except in *Messages*).

When enable-recursive-minibuffers is set, the execution of isearch-exit 
does not fail, which triggers the current bug.

The immediate fix is attached, but I wonder if the cause is not elswhere, 
that is, if it is indeed intended that isearch-post-command-hook is 
executed in the minibuffer in such a case.

From 32456fad0d683db7a154220b1b4a57946c84b410 Mon Sep 17 00:00:00 2001
From: Gregory Heytings <[email-masked]>
Date: Tue, 20 Apr 2021 21:42:32 +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 case when an input method is
used and enable-recursive-minibuffers is set (Bug#47894).
---
 lisp/isearch.el | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lisp/isearch.el b/lisp/isearch.el
index 69fdc9df6d..8123da90c9 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 (current-buffer))
+      (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