[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple isearch concerns

From: Juri Linkov
Subject: Re: Simple isearch concerns
Date: Fri, 07 May 2021 20:14:52 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

> The current design is not without flaws either: when multi-buffer
> isearch visits another buffer, it removes the isearch menu, because
> isearch-mode is already buffer-local.

This patch fixes the problem.  It disables isearch-mode in the previous
buffer, and enables in the next buffer.

Later for isearch-buffer-local, the same function could remove hooks
in the previous buffer, and add buffer-local hooks in the next buffer.

diff --git a/lisp/isearch.el b/lisp/isearch.el
index 5c71519054..095f8ba145 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -3549,9 +3552,8 @@ isearch-search-string
     (when pos1
       ;; When using multiple buffers isearch, switch to the new buffer here,
       ;; because `save-excursion' above doesn't allow doing it inside funcall.
-      (if (and multi-isearch-next-buffer-current-function
-              (buffer-live-p multi-isearch-current-buffer))
-         (switch-to-buffer multi-isearch-current-buffer))
+      (when multi-isearch-next-buffer-current-function
+        (multi-isearch-switch-buffer))
       (goto-char pos1)
diff --git a/lisp/misearch.el b/lisp/misearch.el
index 335efb9516..338880f25f 100644
--- a/lisp/misearch.el
+++ b/lisp/misearch.el
@@ -190,10 +190,10 @@ multi-isearch-wrap
   (if (or (null multi-isearch-pause)
          (and multi-isearch-pause multi-isearch-current-buffer))
-       (switch-to-buffer
-        (setq multi-isearch-current-buffer
-              (funcall multi-isearch-next-buffer-current-function
-                       (current-buffer) t)))
+       (setq multi-isearch-current-buffer
+             (funcall multi-isearch-next-buffer-current-function
+                      (current-buffer) t))
+       (multi-isearch-switch-buffer)
        (goto-char (if isearch-forward (point-min) (point-max))))
     (setq multi-isearch-current-buffer (current-buffer))
     (setq isearch-wrapped nil)))
@@ -208,8 +208,18 @@ multi-isearch-push-state
 (defun multi-isearch-pop-state (_cmd buffer)
   "Restore the multiple buffers search state in BUFFER.
 Switch to the buffer restored from the search status stack."
-  (unless (equal buffer (current-buffer))
-    (switch-to-buffer (setq multi-isearch-current-buffer buffer))))
+  (unless (eq buffer (current-buffer))
+    (setq multi-isearch-current-buffer buffer)
+    (multi-isearch-switch-buffer)))
+(defun multi-isearch-switch-buffer ()
+  "Switch to the next buffer in multi-buffer search."
+  (when (and (buffer-live-p multi-isearch-current-buffer)
+             (not (eq multi-isearch-current-buffer (current-buffer))))
+    (setq isearch-mode nil)
+    (switch-to-buffer multi-isearch-current-buffer)
+    (setq isearch-mode " M-Isearch")))
 ;;; Global multi-buffer search invocations

reply via email to

[Prev in Thread] Current Thread [Next in Thread]