]> git.eshelyaron.com Git - emacs.git/commitdiff
Tramp code cleanup
authorMichael Albinus <michael.albinus@gmx.de>
Thu, 9 May 2024 08:38:37 +0000 (10:38 +0200)
committerEshel Yaron <me@eshelyaron.com>
Fri, 10 May 2024 13:36:16 +0000 (15:36 +0200)
* lisp/net/tramp-compat.el (tramp-compat-seq-keep): New defalias.

* lisp/net/tramp.el (tramp-enable-method):
* lisp/net/tramp-adb.el (tramp-adb-parse-device-names):
* lisp/net/tramp-cache.el (tramp-list-connections):
* lisp/net/tramp-cmds.el (tramp-bug, tramp-append-tramp-buffers):
* lisp/net/tramp-container.el (tramp-container--completion-function)
(tramp-toolbox--completion-function)
(tramp-flatpak--completion-function)
(tramp-apptainer--completion-function):
* lisp/net/tramp-rclone.el (tramp-rclone-parse-device-names): Use it.

(cherry picked from commit 04363f9924c0f63d28f789ccdadd81a87e6f7417)

lisp/net/tramp-adb.el
lisp/net/tramp-cache.el
lisp/net/tramp-cmds.el
lisp/net/tramp-compat.el
lisp/net/tramp-container.el
lisp/net/tramp-rclone.el

index da23d062c2e7711c683c939d55e651ac21ecd602..b794d8b481a63b43ac7c155895c6400085cbce05 100644 (file)
@@ -222,15 +222,14 @@ arguments to pass to the OPERATION."
 ;;;###tramp-autoload
 (defun tramp-adb-parse-device-names (_ignore)
   "Return a list of (nil host) tuples allowed to access."
-  (delq nil
-       (mapcar
-        (lambda (line)
-          (when (string-match
-                 (rx bol (group (+ (not blank))) (+ blank) "device" eol) line)
-            ;; Replace ":" by "#".
-            `(nil ,(tramp-compat-string-replace
-                    ":" tramp-prefix-port-format (match-string 1 line)))))
-        (tramp-process-lines nil tramp-adb-program "devices"))))
+  (tramp-compat-seq-keep
+   (lambda (line)
+     (when (string-match
+           (rx bol (group (+ (not blank))) (+ blank) "device" eol) line)
+       ;; Replace ":" by "#".
+       `(nil ,(tramp-compat-string-replace
+              ":" tramp-prefix-port-format (match-string 1 line)))))
+   (tramp-process-lines nil tramp-adb-program "devices")))
 
 (defun tramp-adb-handle-file-system-info (filename)
   "Like `file-system-info' for Tramp files."
index 225a26ad1cdd4f2f478a949e6fb2963c3fc029b9..30c38d19fb74243a0ce956b1280401327b1f7ab1 100644 (file)
@@ -540,13 +540,13 @@ PROPERTIES is a list of file properties (strings)."
 (defun tramp-list-connections ()
   "Return all active `tramp-file-name' structs according to `tramp-cache-data'."
   (let ((tramp-verbose 0))
-    (delq nil (mapcar
-              (lambda (key)
-                (and (tramp-file-name-p key)
-                     (null (tramp-file-name-localname key))
-                     (tramp-connection-property-p key "process-buffer")
-                     key))
-              (hash-table-keys tramp-cache-data)))))
+    (tramp-compat-seq-keep
+     (lambda (key)
+       (and (tramp-file-name-p key)
+           (null (tramp-file-name-localname key))
+           (tramp-connection-property-p key "process-buffer")
+           key))
+     (hash-table-keys tramp-cache-data))))
 
 (defun tramp-dump-connection-properties ()
   "Write persistent connection properties into file \
index d3af7a009eccff4b94a31468488f7694cb8ae2d5..f381c2e9ff0b3d1403b3eae7ffdf211e072ea378 100644 (file)
@@ -691,25 +691,25 @@ This is needed if there are compatibility problems."
      (format "tramp (%s %s/%s)" ; package name and version
             tramp-version tramp-repository-branch tramp-repository-version)
      (sort
-      (delq nil (mapcar
-       (lambda (x)
-         (and x (boundp x) (not (get x 'tramp-suppress-trace))
-              (cons x 'tramp-reporter-dump-variable)))
-       (append
-        (mapcar #'intern (all-completions "tramp-" obarray #'boundp))
-        ;; Non-Tramp variables of interest.
-        '(shell-prompt-pattern
-          backup-by-copying
-          backup-by-copying-when-linked
-          backup-by-copying-when-mismatch
-          backup-by-copying-when-privileged-mismatch
-          backup-directory-alist
-          password-cache
-          password-cache-expiry
-          remote-file-name-inhibit-cache
-          connection-local-profile-alist
-          connection-local-criteria-alist
-          file-name-handler-alist))))
+      (tramp-compat-seq-keep
+       (lambda (x)
+        (and x (boundp x) (not (get x 'tramp-suppress-trace))
+             (cons x 'tramp-reporter-dump-variable)))
+       (append
+       (mapcar #'intern (all-completions "tramp-" obarray #'boundp))
+       ;; Non-Tramp variables of interest.
+       '(shell-prompt-pattern
+         backup-by-copying
+         backup-by-copying-when-linked
+         backup-by-copying-when-mismatch
+         backup-by-copying-when-privileged-mismatch
+         backup-directory-alist
+         password-cache
+         password-cache-expiry
+         remote-file-name-inhibit-cache
+         connection-local-profile-alist
+         connection-local-criteria-alist
+         file-name-handler-alist)))
       (lambda (x y) (string< (symbol-name (car x)) (symbol-name (car y)))))
 
      'tramp-load-report-modules        ; pre-hook
@@ -792,12 +792,10 @@ buffer in your bug report.
 
   ;; Dump buffer local variables.
   (insert "\nlocal variables:\n================")
-  (dolist (buffer
-          (delq nil
-                (mapcar
-                 (lambda (b)
-                    (when (string-match-p "\\*tramp/" (buffer-name b)) b))
-                 (buffer-list))))
+  (dolist (buffer (tramp-compat-seq-keep
+                  (lambda (b)
+                    (when (string-match-p "\\*tramp/" (buffer-name b)) b))
+                  (buffer-list)))
     (let ((reporter-eval-buffer buffer)
          (elbuf (get-buffer-create " *tmp-reporter-buffer*")))
       (with-current-buffer elbuf
index 98de0dba7ff56bee794ba5301322f9c4fafff742..d7492be63f28a66d8482b8aaadf08a0e1306d3b0 100644 (file)
@@ -294,6 +294,13 @@ Also see `ignore'."
       (autoload 'netrc-parse "netrc")
       (netrc-parse file))))
 
+;; Function `seq-keep' is new in Emacs 29.1.
+(defalias 'tramp-compat-seq-keep
+  (if (fboundp 'seq-keep)
+      #'seq-keep
+    (lambda (function sequence)
+      (delq nil (seq-map function sequence)))))
+
 ;; User option `password-colon-equivalents' is new in Emacs 30.1.
 (if (boundp 'password-colon-equivalents)
     (defvaralias
index 7559f958838b485a25090365d1b54385a6230342..902fc6a451babb386f38618b03b100e3a114f01d 100644 (file)
@@ -230,7 +230,7 @@ see its function help for a description of the format."
                 (concat program " ps --format '{{.ID}}\t{{.Names}}'")))
               (lines (split-string raw-list "\n" 'omit))
               (names
-               (mapcar
+               (tramp-compat-seq-keep
                 (lambda (line)
                   (when (string-match
                          (rx bol (group (1+ nonl))
@@ -238,7 +238,7 @@ see its function help for a description of the format."
                          line)
                     (or (match-string 2 line) (match-string 1 line))))
                 lines)))
-      (mapcar (lambda (name) (list nil name)) (delq nil names)))))
+      (mapcar (lambda (name) (list nil name)) names))))
 
 ;;;###tramp-autoload
 (defun tramp-kubernetes--completion-function (method)
@@ -360,7 +360,7 @@ see its function help for a description of the format."
     (when-let ((raw-list (shell-command-to-string (concat program " list -c")))
               ;; Ignore header line.
                (lines (cdr (split-string raw-list "\n" 'omit)))
-               (names (mapcar
+               (names (tramp-compat-seq-keep
                       (lambda (line)
                         (when (string-match
                                (rx bol (1+ (not space))
@@ -368,7 +368,7 @@ see its function help for a description of the format."
                                line)
                           (match-string 1 line)))
                        lines)))
-      (mapcar (lambda (name) (list nil name)) (delq nil names)))))
+      (mapcar (lambda (name) (list nil name)) names))))
 
 ;;;###tramp-autoload
 (defun tramp-flatpak--completion-function (method)
@@ -384,7 +384,7 @@ see its function help for a description of the format."
                 ;; Ignore header line.
                 (concat program " ps --columns=instance,application | cat -")))
                (lines (split-string raw-list "\n" 'omit))
-               (names (mapcar
+               (names (tramp-compat-seq-keep
                       (lambda (line)
                         (when (string-match
                                (rx bol (* space) (group (+ (not space)))
@@ -392,7 +392,7 @@ see its function help for a description of the format."
                                line)
                           (or (match-string 2 line) (match-string 1 line))))
                        lines)))
-      (mapcar (lambda (name) (list nil name)) (delq nil names)))))
+      (mapcar (lambda (name) (list nil name)) names))))
 
 ;;;###tramp-autoload
 (defun tramp-apptainer--completion-function (method)
@@ -405,7 +405,7 @@ see its function help for a description of the format."
                (shell-command-to-string (concat program " instance list")))
               ;; Ignore header line.
                (lines (cdr (split-string raw-list "\n" 'omit)))
-               (names (mapcar
+               (names (tramp-compat-seq-keep
                       (lambda (line)
                         (when (string-match
                                (rx bol (group (1+ (not space)))
@@ -414,7 +414,7 @@ see its function help for a description of the format."
                                line)
                           (match-string 1 line)))
                        lines)))
-      (mapcar (lambda (name) (list nil name)) (delq nil names)))))
+      (mapcar (lambda (name) (list nil name)) names))))
 
 ;;;###tramp-autoload
 (defvar tramp-default-remote-shell) ;; Silence byte compiler.
index ced3c1b5aa8ebe51e2a9e1e06bca230679d1c7f0..03b0dedbb709e7d45e9b5b5ab13e7f950b0f008e 100644 (file)
@@ -189,12 +189,11 @@ arguments to pass to the OPERATION."
 (defun tramp-rclone-parse-device-names (_ignore)
   "Return a list of (nil host) tuples allowed to access."
   (with-tramp-connection-property nil "rclone-device-names"
-    (delq nil
-         (mapcar
-          (lambda (line)
-            (when (string-match (rx bol (group (+ (not blank))) ":" eol) line)
-              `(nil ,(match-string 1 line))))
-          (tramp-process-lines nil tramp-rclone-program "listremotes")))))
+    (tramp-compat-seq-keep
+     (lambda (line)
+       (when (string-match (rx bol (group (+ (not blank))) ":" eol) line)
+        `(nil ,(match-string 1 line))))
+     (tramp-process-lines nil tramp-rclone-program "listremotes"))))
 
 \f
 ;; File name primitives.