From f564697a19c3f40c332abf2ef0b18fbb1950a4ea Mon Sep 17 00:00:00 2001 From: yurii-tov <45265225+yurii-tov@users.noreply.github.com> Date: Sun, 28 May 2023 12:02:29 +0300 Subject: [PATCH] Now we can use "wide find file" on remote directories At the moment, "wide find file" feature (M-f) doesn't work on remote directories (e.g. on /ssh:myserver:/some/directory it finds nothing in any case). This commit is intended to fix the problem: - We test if a directory are remote (file-remote-p), and if it is, we correct directory path (remove specific prefix), since the path should be passed to "find" program at remote server - We also explicitly set working directory since we should run the "find" command on remote server, and our current working directory may be local --- lisp/ido.el | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/lisp/ido.el b/lisp/ido.el index 00a2e57f7bad..ef2292f58116 100644 --- a/lisp/ido.el +++ b/lisp/ido.el @@ -3297,29 +3297,33 @@ instead removed from the current item list." (defun ido-wide-find-dirs-or-files (dir file &optional prefix finddir) ;; As ido-run-find-command, but returns a list of cons pairs ("file" . "dir") - (let ((filenames - (delq nil - (mapcar (lambda (name) - (unless (ido-ignore-item-p name ido-ignore-files t) - name)) - (split-string - (shell-command-to-string - (concat "find " - (shell-quote-argument dir) - (if ido-case-fold " -iname " " -name ") - (shell-quote-argument - (concat (if prefix "" "*") file "*")) - " -type " (if finddir "d" "f") " -print")))))) - filename d f - res) + (let* ((remote-prefix (file-remote-p dir)) + (default-directory dir) + (filenames + (delq nil + (mapcar (lambda (name) + (unless (ido-ignore-item-p name ido-ignore-files t) + name)) + (split-string + (shell-command-to-string + (concat "find " + (shell-quote-argument + (if remote-prefix + (string-remove-prefix remote-prefix dir) dir)) + (if ido-case-fold " -iname " " -name ") + (shell-quote-argument + (concat (if prefix "" "*") file "*")) + " -type " (if finddir "d" "f") " -print")))))) + filename d f + res) (while filenames - (setq filename (car filenames) - filenames (cdr filenames)) + (setq filename (format "%s%s" (or remote-prefix "") (car filenames)) + filenames (cdr filenames)) (if (and (file-name-absolute-p filename) - (file-exists-p filename)) - (setq d (file-name-directory filename) - f (file-name-nondirectory filename) - res (cons (cons (if finddir (ido-final-slash f t) f) d) res)))) + (file-exists-p filename)) + (setq d (file-name-directory filename) + f (file-name-nondirectory filename) + res (cons (cons (if finddir (ido-final-slash f t) f) d) res)))) res)) (defun ido-flatten-merged-list (items)