diff options
| author | Michael Albinus | 2023-08-29 11:30:20 +0200 |
|---|---|---|
| committer | Michael Albinus | 2023-08-29 11:30:20 +0200 |
| commit | 88bb7cdf915be620bd6499c8ddb8679f3c0792b4 (patch) | |
| tree | f6dc25d99341e3d8105f7c612cdd3afaebbb9458 | |
| parent | e9b3381a1fccc32cbc84e6a5c1bb22cf9f584c36 (diff) | |
| download | emacs-88bb7cdf915be620bd6499c8ddb8679f3c0792b4.tar.gz emacs-88bb7cdf915be620bd6499c8ddb8679f3c0792b4.zip | |
Adapt some changes of last Tramp commit
* lisp/net/tramp-container.el (tramp-container--completion-function):
Use METHOD as argument, instead of PROGRAM. Determine program
from METHOD entry in `tramp-methods'. Bind `non-essential' to
nil. Use a file property as cache.
(tramp-container--completion-function): Use adapted arguments when
setting for "docker" and "podman".
* lisp/net/tramp.el (tramp--last-hop-directory): Adapt docstring.
Move down.
(tramp-set-completion-function): Revert default case to
`file-exists-p', the workaround isn't needed anymore.
(tramp-get-completion-methods): Rename argument to MULTI-HOP.
(tramp-completion-remote-containers): Add :version.
(tramp-multi-hop-p): Bind `tramp-verbose' to nil.
| -rw-r--r-- | lisp/net/tramp-container.el | 56 | ||||
| -rw-r--r-- | lisp/net/tramp.el | 37 |
2 files changed, 50 insertions, 43 deletions
diff --git a/lisp/net/tramp-container.el b/lisp/net/tramp-container.el index e5ad3a55e27..687092e7e95 100644 --- a/lisp/net/tramp-container.el +++ b/lisp/net/tramp-container.el | |||
| @@ -158,31 +158,39 @@ If it is nil, the default context will be used." | |||
| 158 | "Tramp method name to use to connect to Flatpak sandboxes.") | 158 | "Tramp method name to use to connect to Flatpak sandboxes.") |
| 159 | 159 | ||
| 160 | ;;;###tramp-autoload | 160 | ;;;###tramp-autoload |
| 161 | (defun tramp-container--completion-function (program) | 161 | (defun tramp-container--completion-function (method) |
| 162 | "List running containers available for connection. | 162 | "List running containers available for connection. |
| 163 | PROGRAM is the program to be run for \"ps\", either | 163 | METHOD is the Tramp method to be used for \"ps\", either |
| 164 | `tramp-docker-program' or `tramp-podman-program'. | 164 | `tramp-docker-method' or `tramp-podman-method'. |
| 165 | 165 | ||
| 166 | This function is used by `tramp-set-completion-function', please | 166 | This function is used by `tramp-set-completion-function', please |
| 167 | see its function help for a description of the format." | 167 | see its function help for a description of the format." |
| 168 | ;; Set the default-directory to the directory of the last hop | 168 | (let ((default-directory |
| 169 | ;; of a multi-hop path so that we can run the container program | 169 | (or (and tramp-completion-remote-containers tramp--last-hop-directory) |
| 170 | ;; from there. If this is not a multi-hop path, run from the local | 170 | tramp-compat-temporary-file-directory)) |
| 171 | ;; temp file directory. | 171 | (program (tramp-get-method-parameter |
| 172 | (when-let ((default-directory (or (and tramp-completion-remote-containers tramp--last-hop-directory) | 172 | (make-tramp-file-name :method method) 'tramp-login-program)) |
| 173 | tramp-compat-temporary-file-directory)) | 173 | non-essential) |
| 174 | (raw-list (shell-command-to-string | 174 | ;; We don't use connection properties, because this information |
| 175 | (concat program " ps --format '{{.ID}}\t{{.Names}}'"))) | 175 | ;; shouldn't be kept persistently. |
| 176 | (lines (split-string raw-list "\n" 'omit)) | 176 | (with-tramp-file-property |
| 177 | (names (mapcar | 177 | (when (tramp-tramp-file-p default-directory) |
| 178 | (lambda (line) | 178 | (tramp-dissect-file-name default-directory)) |
| 179 | (when (string-match | 179 | (concat "/" method ":") "user-host-completions" |
| 180 | (rx bol (group (1+ nonl)) | 180 | (when-let ((raw-list |
| 181 | "\t" (? (group (1+ nonl))) eol) | 181 | (shell-command-to-string |
| 182 | line) | 182 | (concat program " ps --format '{{.ID}}\t{{.Names}}'"))) |
| 183 | (or (match-string 2 line) (match-string 1 line)))) | 183 | (lines (split-string raw-list "\n" 'omit)) |
| 184 | lines))) | 184 | (names |
| 185 | (mapcar (lambda (name) (list nil name)) (delq nil names)))) | 185 | (mapcar |
| 186 | (lambda (line) | ||
| 187 | (when (string-match | ||
| 188 | (rx bol (group (1+ nonl)) | ||
| 189 | "\t" (? (group (1+ nonl))) eol) | ||
| 190 | line) | ||
| 191 | (or (match-string 2 line) (match-string 1 line)))) | ||
| 192 | lines))) | ||
| 193 | (mapcar (lambda (name) (list nil name)) (delq nil names)))))) | ||
| 186 | 194 | ||
| 187 | ;;;###tramp-autoload | 195 | ;;;###tramp-autoload |
| 188 | (defun tramp-kubernetes--completion-function (&rest _args) | 196 | (defun tramp-kubernetes--completion-function (&rest _args) |
| @@ -387,13 +395,11 @@ see its function help for a description of the format." | |||
| 387 | 395 | ||
| 388 | (tramp-set-completion-function | 396 | (tramp-set-completion-function |
| 389 | tramp-docker-method | 397 | tramp-docker-method |
| 390 | `((tramp-container--completion-function | 398 | `((tramp-container--completion-function ,tramp-docker-method))) |
| 391 | ,tramp-docker-program))) | ||
| 392 | 399 | ||
| 393 | (tramp-set-completion-function | 400 | (tramp-set-completion-function |
| 394 | tramp-podman-method | 401 | tramp-podman-method |
| 395 | `((tramp-container--completion-function | 402 | `((tramp-container--completion-function ,tramp-podman-method))) |
| 396 | ,tramp-podman-program))) | ||
| 397 | 403 | ||
| 398 | (tramp-set-completion-function | 404 | (tramp-set-completion-function |
| 399 | tramp-kubernetes-method | 405 | tramp-kubernetes-method |
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 01a83566975..9d555c5621b 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el | |||
| @@ -81,8 +81,6 @@ | |||
| 81 | (defvar tramp-file-name-regexp) | 81 | (defvar tramp-file-name-regexp) |
| 82 | (defvar tramp-completion-method-regexp) | 82 | (defvar tramp-completion-method-regexp) |
| 83 | (defvar tramp-completion-file-name-regexp) | 83 | (defvar tramp-completion-file-name-regexp) |
| 84 | (defvar tramp--last-hop-directory nil | ||
| 85 | "Tracks the directory from which to run container executable programs.") | ||
| 86 | 84 | ||
| 87 | ;; Reload `tramp-compat' when we reload `tramp-autoloads' of the GNU | 85 | ;; Reload `tramp-compat' when we reload `tramp-autoloads' of the GNU |
| 88 | ;; ELPA package. | 86 | ;; ELPA package. |
| @@ -2143,10 +2141,8 @@ Example: | |||
| 2143 | tramp-dns-sd-service-regexp (nth 1 (car v)))) | 2141 | tramp-dns-sd-service-regexp (nth 1 (car v)))) |
| 2144 | ;; Method. | 2142 | ;; Method. |
| 2145 | ((string-equal method (nth 1 (car v)))) | 2143 | ((string-equal method (nth 1 (car v)))) |
| 2146 | ;; FIXME: for now do not check local existence of file | 2144 | ;; Configuration file or empty string. |
| 2147 | ;; to allow allow arbitrary container program executable | 2145 | (t (file-exists-p (nth 1 (car v)))))) |
| 2148 | ;; name for container completion on remote systems. | ||
| 2149 | (t t))) | ||
| 2150 | (setq r (delete (car v) r))) | 2146 | (setq r (delete (car v) r))) |
| 2151 | (setq v (cdr v))) | 2147 | (setq v (cdr v))) |
| 2152 | 2148 | ||
| @@ -2724,6 +2720,9 @@ not in completion mode." | |||
| 2724 | 2720 | ||
| 2725 | (tramp-run-real-handler #'file-exists-p (list filename)))) | 2721 | (tramp-run-real-handler #'file-exists-p (list filename)))) |
| 2726 | 2722 | ||
| 2723 | (defvar tramp--last-hop-directory nil | ||
| 2724 | "Tracks the directory from which to run login programs.") | ||
| 2725 | |||
| 2727 | ;; Method, host name and user name completion. | 2726 | ;; Method, host name and user name completion. |
| 2728 | ;; `tramp-completion-dissect-file-name' returns a list of | 2727 | ;; `tramp-completion-dissect-file-name' returns a list of |
| 2729 | ;; `tramp-file-name' structures. For all of them we return possible | 2728 | ;; `tramp-file-name' structures. For all of them we return possible |
| @@ -2759,7 +2758,7 @@ not in completion mode." | |||
| 2759 | 2758 | ||
| 2760 | ;; Possible completion structures. | 2759 | ;; Possible completion structures. |
| 2761 | (dolist (elt (tramp-completion-dissect-file-name fullname)) | 2760 | (dolist (elt (tramp-completion-dissect-file-name fullname)) |
| 2762 | (let* ((method (tramp-file-name-method elt)) | 2761 | (let* ((method (tramp-file-name-method elt)) |
| 2763 | (user (tramp-file-name-user elt)) | 2762 | (user (tramp-file-name-user elt)) |
| 2764 | (host (tramp-file-name-host elt)) | 2763 | (host (tramp-file-name-host elt)) |
| 2765 | (localname (tramp-file-name-localname elt)) | 2764 | (localname (tramp-file-name-localname elt)) |
| @@ -2770,8 +2769,8 @@ not in completion mode." | |||
| 2770 | 2769 | ||
| 2771 | (if (or user host) | 2770 | (if (or user host) |
| 2772 | 2771 | ||
| 2773 | ;; Method dependent user / host combinations. | 2772 | ;; Method dependent user / host combinations. |
| 2774 | (progn | 2773 | (progn |
| 2775 | (mapc | 2774 | (mapc |
| 2776 | (lambda (x) | 2775 | (lambda (x) |
| 2777 | (setq all-user-hosts | 2776 | (setq all-user-hosts |
| @@ -2780,12 +2779,12 @@ not in completion mode." | |||
| 2780 | (tramp-get-completion-function m)) | 2779 | (tramp-get-completion-function m)) |
| 2781 | 2780 | ||
| 2782 | (setq result | 2781 | (setq result |
| 2783 | (append result | 2782 | (append result |
| 2784 | (mapcar | 2783 | (mapcar |
| 2785 | (lambda (x) | 2784 | (lambda (x) |
| 2786 | (tramp-get-completion-user-host | 2785 | (tramp-get-completion-user-host |
| 2787 | method user host (nth 0 x) (nth 1 x))) | 2786 | method user host (nth 0 x) (nth 1 x))) |
| 2788 | (delq nil all-user-hosts))))) | 2787 | (delq nil all-user-hosts))))) |
| 2789 | 2788 | ||
| 2790 | ;; Possible methods. | 2789 | ;; Possible methods. |
| 2791 | (setq result | 2790 | (setq result |
| @@ -2924,13 +2923,13 @@ remote host and localname (filename on remote host)." | |||
| 2924 | 2923 | ||
| 2925 | ;; This function returns all possible method completions, adding the | 2924 | ;; This function returns all possible method completions, adding the |
| 2926 | ;; trailing method delimiter. | 2925 | ;; trailing method delimiter. |
| 2927 | (defun tramp-get-completion-methods (partial-method hop) | 2926 | (defun tramp-get-completion-methods (partial-method multi-hop) |
| 2928 | "Return all method completions for PARTIAL-METHOD. | 2927 | "Return all method completions for PARTIAL-METHOD. |
| 2929 | If HOP is non-nil, return only multi-hop capable methods." | 2928 | If MULTI-HOP is non-nil, return only multi-hop capable methods." |
| 2930 | (mapcar | 2929 | (mapcar |
| 2931 | (lambda (method) | 2930 | (lambda (method) |
| 2932 | (and method (string-prefix-p (or partial-method "") method) | 2931 | (and method (string-prefix-p (or partial-method "") method) |
| 2933 | (or (not hop) | 2932 | (or (not multi-hop) |
| 2934 | (tramp-multi-hop-p (make-tramp-file-name :method method))) | 2933 | (tramp-multi-hop-p (make-tramp-file-name :method method))) |
| 2935 | (tramp-completion-make-tramp-file-name method nil nil nil))) | 2934 | (tramp-completion-make-tramp-file-name method nil nil nil))) |
| 2936 | (mapcar #'car tramp-methods))) | 2935 | (mapcar #'car tramp-methods))) |
| @@ -3012,6 +3011,7 @@ for all methods. Resulting data are derived from default settings." | |||
| 3012 | 3011 | ||
| 3013 | (defcustom tramp-completion-remote-containers nil | 3012 | (defcustom tramp-completion-remote-containers nil |
| 3014 | "Whether container hosts in multi-hop paths should be queried for completions." | 3013 | "Whether container hosts in multi-hop paths should be queried for completions." |
| 3014 | :version "30.1" | ||
| 3015 | :type 'boolean) | 3015 | :type 'boolean) |
| 3016 | 3016 | ||
| 3017 | (defcustom tramp-completion-use-auth-sources auth-source-do-cache | 3017 | (defcustom tramp-completion-use-auth-sources auth-source-do-cache |
| @@ -4585,8 +4585,9 @@ Do not set it manually, it is used buffer-local in `tramp-get-lock-pid'.") | |||
| 4585 | 4585 | ||
| 4586 | (defun tramp-multi-hop-p (vec) | 4586 | (defun tramp-multi-hop-p (vec) |
| 4587 | "Whether the method of VEC is capable of multi-hops." | 4587 | "Whether the method of VEC is capable of multi-hops." |
| 4588 | (and (tramp-sh-file-name-handler-p vec) | 4588 | (let ((tramp-verbose 0)) |
| 4589 | (not (tramp-get-method-parameter vec 'tramp-copy-program)))) | 4589 | (and (tramp-sh-file-name-handler-p vec) |
| 4590 | (not (tramp-get-method-parameter vec 'tramp-copy-program))))) | ||
| 4590 | 4591 | ||
| 4591 | (defun tramp-add-hops (vec) | 4592 | (defun tramp-add-hops (vec) |
| 4592 | "Add ad-hoc proxy definitions to `tramp-default-proxies-alist'." | 4593 | "Add ad-hoc proxy definitions to `tramp-default-proxies-alist'." |