From: Michael Albinus Date: Thu, 9 May 2024 08:38:37 +0000 (+0200) Subject: Tramp code cleanup X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9efa6606681c893a0d419ac33eba21c76084b799;p=emacs.git Tramp code cleanup * 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) --- diff --git a/lisp/net/tramp-adb.el b/lisp/net/tramp-adb.el index da23d062c2e..b794d8b481a 100644 --- a/lisp/net/tramp-adb.el +++ b/lisp/net/tramp-adb.el @@ -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." diff --git a/lisp/net/tramp-cache.el b/lisp/net/tramp-cache.el index 225a26ad1cd..30c38d19fb7 100644 --- a/lisp/net/tramp-cache.el +++ b/lisp/net/tramp-cache.el @@ -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 \ diff --git a/lisp/net/tramp-cmds.el b/lisp/net/tramp-cmds.el index d3af7a009ec..f381c2e9ff0 100644 --- a/lisp/net/tramp-cmds.el +++ b/lisp/net/tramp-cmds.el @@ -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 diff --git a/lisp/net/tramp-compat.el b/lisp/net/tramp-compat.el index 98de0dba7ff..d7492be63f2 100644 --- a/lisp/net/tramp-compat.el +++ b/lisp/net/tramp-compat.el @@ -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 diff --git a/lisp/net/tramp-container.el b/lisp/net/tramp-container.el index 7559f958838..902fc6a451b 100644 --- a/lisp/net/tramp-container.el +++ b/lisp/net/tramp-container.el @@ -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. diff --git a/lisp/net/tramp-rclone.el b/lisp/net/tramp-rclone.el index ced3c1b5aa8..03b0dedbb70 100644 --- a/lisp/net/tramp-rclone.el +++ b/lisp/net/tramp-rclone.el @@ -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")))) ;; File name primitives.