From 2b9c7f9508e435625c27d7b261f5ce6414d207f3 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Wed, 3 Sep 2025 09:45:34 +0300 Subject: [PATCH] Make 'isearch-mode' more idempotent (bug#79368). * lisp/isearch.el (isearch-mode): Don't override 'isearch--saved-local-map' when 'overriding-terminal-local-map' was already set to 'isearch-mode-map' in a previous call. (with-isearch-suspended): Don't call the function 'isearch-mode' when the variable 'isearch-mode' is already non-nil. --- lisp/isearch.el | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lisp/isearch.el b/lisp/isearch.el index 5a79076c63d..28d24488e71 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -1322,7 +1322,10 @@ used to set the value of `isearch-regexp-function'." (setq isearch-mode " Isearch") ;; forward? regexp? (force-mode-line-update) - (setq isearch--saved-local-map overriding-terminal-local-map) + ;; Prevent successive calls overriding original map + ;; in `isearch-done'. (Bug#79368) + (unless (eq overriding-terminal-local-map isearch-mode-map) + (setq isearch--saved-local-map overriding-terminal-local-map)) (setq overriding-terminal-local-map isearch-mode-map) (run-hooks 'isearch-mode-hook) ;; Remember the initial map possibly modified @@ -1765,12 +1768,18 @@ You can update the global isearch variables by setting new values to (setq isearch-suspended nil) - ;; Always resume isearching by restarting it. - (isearch-mode isearch-forward - isearch-regexp - isearch-op-fun - nil - isearch-regexp-function) + ;; When aborting recursive minibuffers with a command attempted + ;; to use minibuffer while in minibuffer, this unwind form + ;; might be called consecutively more than once. So check if + ;; `isearch-mode' was already enabled in a previous call + ;; in the same unwind form (bug#79368). + (unless isearch-mode + ;; Always resume isearching by restarting it. + (isearch-mode isearch-forward + isearch-regexp + isearch-op-fun + nil + isearch-regexp-function)) ;; Copy new local values to isearch globals (setq isearch-string isearch-new-string