Subject: Re: bug#78520: 31.0.50; Performance issue in dired+isearch with dired-isearch-filenames

From: Juri Linkov <[email-masked]>
Date: Fri, 20 Jun 2025 09:58:23 +0300

>> Could you try to remove all isearch-related code from wdired.el
>> and see how it reuses dired setup?  I tried, but query-replace
>> proposes to replace matches outside of filenames.  This is because
>> query-replace uses isearch functions, but dired-isearch-filenames-setup
>> is not called.
>
> Are you sure?  Is it not because dired doesn't set
> `replace-search-function'?

Ok, could you try this patch.  Please note that the value 'dwim' of
'dired-isearch-filenames' is used only at the position where WDired
is activated, not at the position where query-replace is started.
diff --git a/lisp/wdired.el b/lisp/wdired.el
index c3773b358cc..31bc7463340 100644
--- a/lisp/wdired.el
+++ b/lisp/wdired.el
@@ -239,15 +239,10 @@ wdired-change-to-wdired-mode
   (setq-local wdired--old-point (point))
   (wdired--set-permission-bounds)
   (when wdired-search-replace-filenames
-    (add-function :around (local 'isearch-search-fun-function)
-                  #'dired-isearch-search-filenames
-                  '((isearch-message-prefix . "filename ")))
+    (dired-isearch-filenames-setup)
     (setq-local replace-search-function
                 (setq-local replace-re-search-function
-                            (funcall isearch-search-fun-function)))
-    ;; Original dired hook removes dired-isearch-search-filenames that
-    ;; is needed outside isearch for lazy-highlighting in query-replace.
-    (remove-hook 'isearch-mode-hook #'dired-isearch-filenames-setup t))
+                            (funcall isearch-search-fun-function))))
   (use-local-map wdired-mode-map)
   (force-mode-line-update)
   (setq buffer-read-only nil)
@@ -446,12 +441,9 @@ wdired-change-to-dired-mode
      (point-min) (point-max)
      '(front-sticky nil rear-nonsticky nil read-only nil keymap nil)))
   (when wdired-search-replace-filenames
-    (remove-function (local 'isearch-search-fun-function)
-                     #'dired-isearch-search-filenames)
     (kill-local-variable 'replace-search-function)
     (kill-local-variable 'replace-re-search-function)
-    ;; Restore dired hook
-    (add-hook 'isearch-mode-hook #'dired-isearch-filenames-setup nil t))
+    (dired-isearch-filenames-end))
   (use-local-map dired-mode-map)
   (force-mode-line-update)
   (setq buffer-read-only t)