emacs-diffs
[Top][All Lists]
Advanced

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

master f5f13495f5d: Make Tramp file name completion more quiet for all b


From: Michael Albinus
Subject: master f5f13495f5d: Make Tramp file name completion more quiet for all backends
Date: Sun, 12 Mar 2023 12:22:10 -0400 (EDT)

branch: master
commit f5f13495f5dac4148c1da8b0ba18c22daf77bb04
Author: Michael Albinus <michael.albinus@gmx.de>
Commit: Michael Albinus <michael.albinus@gmx.de>

    Make Tramp file name completion more quiet for all backends
    
    * lisp/net/tramp-adb.el (tramp-adb-handle-file-name-all-completions):
    * lisp/net/tramp-archive.el
    (tramp-archive-handle-file-name-all-completions):
    * lisp/net/tramp-crypt.el (tramp-crypt-handle-file-name-all-completions):
    * lisp/net/tramp-fuse.el (tramp-fuse-handle-file-name-all-completions):
    * lisp/net/tramp-gvfs.el (tramp-gvfs-handle-file-name-all-completions):
    * lisp/net/tramp-sh.el (tramp-sh-handle-file-name-all-completions):
    * lisp/net/tramp-smb.el (tramp-smb-handle-file-name-all-completions):
    * lisp/net/tramp-sudoedit.el
    (tramp-sudoedit-handle-file-name-all-completions):
    Return nil when DIRECTORY is missing.  (Bug#61890)
---
 lisp/net/tramp-adb.el      | 51 ++++++++++++++++----------------
 lisp/net/tramp-archive.el  |  4 ++-
 lisp/net/tramp-crypt.el    | 25 ++++++++--------
 lisp/net/tramp-fuse.el     | 29 ++++++++++---------
 lisp/net/tramp-gvfs.el     | 23 ++++++++-------
 lisp/net/tramp-sh.el       | 72 ++++++++++++++++++++++++----------------------
 lisp/net/tramp-smb.el      | 26 +++++++++--------
 lisp/net/tramp-sudoedit.el | 39 +++++++++++++------------
 8 files changed, 141 insertions(+), 128 deletions(-)

diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el
index f8c38859477..64f45e7958d 100644
--- a/lisp/net/tramp-adb.el
+++ b/lisp/net/tramp-adb.el
@@ -432,31 +432,32 @@ Emacs dired can't find files."
 
 (defun tramp-adb-handle-file-name-all-completions (filename directory)
   "Like `file-name-all-completions' for Tramp files."
-  (all-completions
-   filename
-   (with-parsed-tramp-file-name (expand-file-name directory) nil
-     (with-tramp-file-property v localname "file-name-all-completions"
-       (tramp-adb-send-command
-       v (format "%s -a %s | cat"
-                 (tramp-adb-get-ls-command v)
-                 (tramp-shell-quote-argument localname)))
-       (mapcar
-       (lambda (f)
-         (if (file-directory-p (expand-file-name f directory))
-             (file-name-as-directory f)
-           f))
-       (with-current-buffer (tramp-get-buffer v)
-         (delete-dups
-          (append
-           ;; On some file systems like "sdcard", "." and ".." are
-           ;; not included.  We fix this by `delete-dups'.
-           '("." "..")
-           (delq
-            nil
-            (mapcar
-             (lambda (l)
-               (and (not (string-match-p (rx bol (* blank) eol) l)) l))
-             (split-string (buffer-string) "\n")))))))))))
+  (ignore-error file-missing
+    (all-completions
+     filename
+     (with-parsed-tramp-file-name (expand-file-name directory) nil
+       (with-tramp-file-property v localname "file-name-all-completions"
+        (tramp-adb-send-command
+         v (format "%s -a %s | cat"
+                   (tramp-adb-get-ls-command v)
+                   (tramp-shell-quote-argument localname)))
+        (mapcar
+         (lambda (f)
+           (if (file-directory-p (expand-file-name f directory))
+               (file-name-as-directory f)
+             f))
+         (with-current-buffer (tramp-get-buffer v)
+           (delete-dups
+            (append
+             ;; On some file systems like "sdcard", "." and ".." are
+             ;; not included.  We fix this by `delete-dups'.
+             '("." "..")
+             (delq
+              nil
+              (mapcar
+               (lambda (l)
+                 (and (not (string-match-p (rx bol (* blank) eol) l)) l))
+               (split-string (buffer-string) "\n"))))))))))))
 
 (defun tramp-adb-handle-file-local-copy (filename)
   "Like `file-local-copy' for Tramp files."
diff --git a/lisp/net/tramp-archive.el b/lisp/net/tramp-archive.el
index 97adb36c4af..c2175612fa8 100644
--- a/lisp/net/tramp-archive.el
+++ b/lisp/net/tramp-archive.el
@@ -650,7 +650,9 @@ offered."
 
 (defun tramp-archive-handle-file-name-all-completions (filename directory)
   "Like `file-name-all-completions' for file archives."
-  (file-name-all-completions filename (tramp-archive-gvfs-file-name 
directory)))
+  (ignore-error file-missing
+    (file-name-all-completions
+     filename (tramp-archive-gvfs-file-name directory))))
 
 (defun tramp-archive-handle-file-readable-p (filename)
   "Like `file-readable-p' for file archives."
diff --git a/lisp/net/tramp-crypt.el b/lisp/net/tramp-crypt.el
index afd3166d161..d0f1f1b8184 100644
--- a/lisp/net/tramp-crypt.el
+++ b/lisp/net/tramp-crypt.el
@@ -730,18 +730,19 @@ absolute file names."
 
 (defun tramp-crypt-handle-file-name-all-completions (filename directory)
   "Like `file-name-all-completions' for Tramp files."
-  (all-completions
-   filename
-   (let* (completion-regexp-list
-         tramp-crypt-enabled
-         (directory (file-name-as-directory directory))
-         (enc-dir (tramp-crypt-encrypt-file-name directory)))
-     (mapcar
-      (lambda (x)
-       (substring
-        (tramp-crypt-decrypt-file-name (concat enc-dir x))
-        (length directory)))
-      (file-name-all-completions "" enc-dir)))))
+  (ignore-error file-missing
+    (all-completions
+     filename
+     (let* (completion-regexp-list
+           tramp-crypt-enabled
+           (directory (file-name-as-directory directory))
+           (enc-dir (tramp-crypt-encrypt-file-name directory)))
+       (mapcar
+       (lambda (x)
+         (substring
+          (tramp-crypt-decrypt-file-name (concat enc-dir x))
+          (length directory)))
+       (file-name-all-completions "" enc-dir))))))
 
 (defun tramp-crypt-handle-file-readable-p (filename)
   "Like `file-readable-p' for Tramp files."
diff --git a/lisp/net/tramp-fuse.el b/lisp/net/tramp-fuse.el
index b846caadc18..8112e564a2c 100644
--- a/lisp/net/tramp-fuse.el
+++ b/lisp/net/tramp-fuse.el
@@ -98,20 +98,21 @@
 (defun tramp-fuse-handle-file-name-all-completions (filename directory)
   "Like `file-name-all-completions' for Tramp files."
   (tramp-fuse-remove-hidden-files
-   (all-completions
-    filename
-    (delete-dups
-     (append
-      (file-name-all-completions
-       filename (tramp-fuse-local-file-name directory))
-      ;; Some storage systems do not return "." and "..".
-      (let (result)
-       (dolist (item '(".." ".") result)
-         (when (string-prefix-p filename item)
-           (catch 'match
-             (dolist (elt completion-regexp-list)
-               (unless (string-match-p elt item) (throw 'match nil)))
-             (setq result (cons (concat item "/") result)))))))))))
+   (ignore-error file-missing
+     (all-completions
+      filename
+      (delete-dups
+       (append
+       (file-name-all-completions
+        filename (tramp-fuse-local-file-name directory))
+       ;; Some storage systems do not return "." and "..".
+       (let (result)
+         (dolist (item '(".." ".") result)
+           (when (string-prefix-p filename item)
+             (catch 'match
+               (dolist (elt completion-regexp-list)
+                 (unless (string-match-p elt item) (throw 'match nil)))
+               (setq result (cons (concat item "/") result))))))))))))
 
 ;; This function isn't used.
 (defun tramp-fuse-handle-insert-directory
diff --git a/lisp/net/tramp-gvfs.el b/lisp/net/tramp-gvfs.el
index b9639c1e7f7..266724c587f 100644
--- a/lisp/net/tramp-gvfs.el
+++ b/lisp/net/tramp-gvfs.el
@@ -1418,16 +1418,19 @@ If FILE-SYSTEM is non-nil, return file system 
attributes."
 (defun tramp-gvfs-handle-file-name-all-completions (filename directory)
   "Like `file-name-all-completions' for Tramp files."
   (unless (tramp-compat-string-search "/" filename)
-    (all-completions
-     filename
-     (with-parsed-tramp-file-name (expand-file-name directory) nil
-       (with-tramp-file-property v localname "file-name-all-completions"
-         (let ((result '("./" "../")))
-           ;; Get a list of directories and files.
-          (dolist (item (tramp-gvfs-get-directory-attributes directory) result)
-            (if (string-equal (cdr (assoc "type" item)) "directory")
-                (push (file-name-as-directory (car item)) result)
-              (push (car item) result)))))))))
+    (ignore-error file-missing
+      (all-completions
+       filename
+       (with-parsed-tramp-file-name (expand-file-name directory) nil
+        (with-tramp-file-property v localname "file-name-all-completions"
+           (let ((result '("./" "../")))
+             ;; Get a list of directories and files.
+            (dolist (item
+                     (tramp-gvfs-get-directory-attributes directory)
+                     result)
+              (if (string-equal (cdr (assoc "type" item)) "directory")
+                  (push (file-name-as-directory (car item)) result)
+                (push (car item) result))))))))))
 
 (defun tramp-gvfs-handle-file-notify-add-watch (file-name flags _callback)
   "Like `file-notify-add-watch' for Tramp files."
diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el
index 3ae5208154a..a854ff42b0d 100644
--- a/lisp/net/tramp-sh.el
+++ b/lisp/net/tramp-sh.el
@@ -1767,41 +1767,43 @@ ID-FORMAT valid values are `string' and `integer'."
   (with-parsed-tramp-file-name (expand-file-name directory) nil
     (when (and (not (tramp-compat-string-search "/" filename))
               (tramp-connectable-p v))
-      (all-completions
-       filename
-       (with-tramp-file-property v localname "file-name-all-completions"
-        (let (result)
-          ;; Get a list of directories and files, including reliably
-          ;; tagging the directories with a trailing "/".  Because I
-          ;; rock.  --daniel@danann.net
-          (when (tramp-send-command-and-check
-                 v
-                 (if (tramp-get-remote-perl v)
-                     (progn
-                       (tramp-maybe-send-script
-                        v tramp-perl-file-name-all-completions
-                        "tramp_perl_file_name_all_completions")
-                       (format "tramp_perl_file_name_all_completions %s"
-                               (tramp-shell-quote-argument localname)))
-
-                   (format (concat
-                            "cd %s 2>&1 && %s -a 2>%s"
-                            " | while IFS= read f; do"
-                            " if %s -d \"$f\" 2>%s;"
-                            " then \\echo \"$f/\"; else \\echo \"$f\"; fi;"
-                            " done")
-                           (tramp-shell-quote-argument localname)
-                           (tramp-get-ls-command v)
-                           (tramp-get-remote-null-device v)
-                           (tramp-get-test-command v)
-                           (tramp-get-remote-null-device v))))
-
-            ;; Now grab the output.
-            (with-current-buffer (tramp-get-buffer v)
-              (goto-char (point-max))
-              (while (zerop (forward-line -1))
-                (push (buffer-substring (point) (line-end-position)) result)))
-            result)))))))
+    (unless (tramp-compat-string-search "/" filename)
+      (ignore-error file-missing
+       (all-completions
+        filename
+        (with-tramp-file-property v localname "file-name-all-completions"
+          (let (result)
+            ;; Get a list of directories and files, including
+            ;; reliably tagging the directories with a trailing "/".
+            ;; Because I rock.  --daniel@danann.net
+            (when (tramp-send-command-and-check
+                   v
+                   (if (tramp-get-remote-perl v)
+                       (progn
+                         (tramp-maybe-send-script
+                          v tramp-perl-file-name-all-completions
+                          "tramp_perl_file_name_all_completions")
+                         (format "tramp_perl_file_name_all_completions %s"
+                                 (tramp-shell-quote-argument localname)))
+
+                     (format (concat
+                              "cd %s 2>&1 && %s -a 2>%s"
+                              " | while IFS= read f; do"
+                              " if %s -d \"$f\" 2>%s;"
+                              " then \\echo \"$f/\"; else \\echo \"$f\"; fi;"
+                              " done")
+                             (tramp-shell-quote-argument localname)
+                             (tramp-get-ls-command v)
+                             (tramp-get-remote-null-device v)
+                             (tramp-get-test-command v)
+                             (tramp-get-remote-null-device v))))
+
+              ;; Now grab the output.
+              (with-current-buffer (tramp-get-buffer v)
+                (goto-char (point-max))
+                (while (zerop (forward-line -1))
+                  (push (buffer-substring (point) (line-end-position)) 
result)))
+              result)))))))))
 
 ;; cp, mv and ln
 
diff --git a/lisp/net/tramp-smb.el b/lisp/net/tramp-smb.el
index 2a69465224f..1aa4520eeb6 100644
--- a/lisp/net/tramp-smb.el
+++ b/lisp/net/tramp-smb.el
@@ -976,18 +976,20 @@ PRESERVE-UID-GID and PRESERVE-EXTENDED-ATTRIBUTES are 
completely ignored."
 ;; files.
 (defun tramp-smb-handle-file-name-all-completions (filename directory)
   "Like `file-name-all-completions' for Tramp files."
-  (all-completions
-   filename
-   (with-parsed-tramp-file-name (expand-file-name directory) nil
-     (with-tramp-file-property v localname "file-name-all-completions"
-       (delete-dups
-       (mapcar
-        (lambda (x)
-          (list
-           (if (tramp-compat-string-search "d" (nth 1 x))
-               (file-name-as-directory (nth 0 x))
-             (nth 0 x))))
-        (tramp-smb-get-file-entries directory)))))))
+  (ignore-error file-missing
+    (all-completions
+     filename
+     (when (file-directory-p directory)
+       (with-parsed-tramp-file-name (expand-file-name directory) nil
+        (with-tramp-file-property v localname "file-name-all-completions"
+          (delete-dups
+           (mapcar
+            (lambda (x)
+              (list
+               (if (tramp-compat-string-search "d" (nth 1 x))
+                   (file-name-as-directory (nth 0 x))
+                 (nth 0 x))))
+            (tramp-smb-get-file-entries directory)))))))))
 
 (defun tramp-smb-handle-file-system-info (filename)
   "Like `file-system-info' for Tramp files."
diff --git a/lisp/net/tramp-sudoedit.el b/lisp/net/tramp-sudoedit.el
index fa1689d6851..abb9afc570b 100644
--- a/lisp/net/tramp-sudoedit.el
+++ b/lisp/net/tramp-sudoedit.el
@@ -460,26 +460,27 @@ the result will be a local, non-Tramp, file name."
 
 (defun tramp-sudoedit-handle-file-name-all-completions (filename directory)
   "Like `file-name-all-completions' for Tramp files."
-  (all-completions
-   filename
-   (with-parsed-tramp-file-name (expand-file-name directory) nil
-     (with-tramp-file-property v localname "file-name-all-completions"
-       (tramp-sudoedit-send-command
-       v "ls" "-a1" "--quoting-style=literal" "--show-control-chars"
-       (if (tramp-string-empty-or-nil-p localname)
-           "" (file-name-unquote localname)))
-       (mapcar
-       (lambda (f)
-         (if (ignore-errors (file-directory-p (expand-file-name f directory)))
-             (file-name-as-directory f)
-           f))
-       (delq
-        nil
+  (ignore-error file-missing
+    (all-completions
+     filename
+     (with-parsed-tramp-file-name (expand-file-name directory) nil
+       (with-tramp-file-property v localname "file-name-all-completions"
+        (tramp-sudoedit-send-command
+         v "ls" "-a1" "--quoting-style=literal" "--show-control-chars"
+         (if (tramp-string-empty-or-nil-p localname)
+             "" (file-name-unquote localname)))
         (mapcar
-         (lambda (l) (and (not (string-match-p (rx bol (* blank) eol) l)) l))
-         (split-string
-          (tramp-get-buffer-string (tramp-get-connection-buffer v))
-          "\n" 'omit))))))))
+         (lambda (f)
+           (if (ignore-errors (file-directory-p (expand-file-name f 
directory)))
+               (file-name-as-directory f)
+             f))
+         (delq
+          nil
+          (mapcar
+           (lambda (l) (and (not (string-match-p (rx bol (* blank) eol) l)) l))
+           (split-string
+            (tramp-get-buffer-string (tramp-get-connection-buffer v))
+            "\n" 'omit)))))))))
 
 (defun tramp-sudoedit-handle-file-readable-p (filename)
   "Like `file-readable-p' for Tramp files."



reply via email to

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