diff options
author | Michael Albinus <michael.albinus@gmx.de> | 2025-03-12 20:56:24 +0100 |
---|---|---|
committer | Michael Albinus <michael.albinus@gmx.de> | 2025-03-12 20:56:24 +0100 |
commit | 13a043fec95f9f6b9721b3c6ff0a3248b14d40cc (patch) | |
tree | ae07a6c34da88218c6ccf01417497356ef5f1713 /lisp/net/tramp-cache.el | |
parent | 85c00405b9e349eeabbdb305e5f8da41600d0b89 (diff) | |
download | emacs-13a043fec95f9f6b9721b3c6ff0a3248b14d40cc.tar.gz emacs-13a043fec95f9f6b9721b3c6ff0a3248b14d40cc.tar.bz2 emacs-13a043fec95f9f6b9721b3c6ff0a3248b14d40cc.zip |
Tramp: Don't offer non-existing containers in completion
* doc/misc/tramp.texi (File name completion):
Explain "completion-use-cache" property.
* lisp/net/tramp-cache.el (tramp-get-method-parameter): Declare.
(tramp-get-hash-table): Mark connection properties.
(tramp-dump-connection-properties): Remove empty lists.
(tramp-parse-connection-properties): Take connection property
"completion-use-cache" into account. (Bug#76950)
* lisp/net/tramp-container.el (tramp-methods) <docker, dockercp, podman>
<podmancp, kubernetes, toolbox, distrobox, flatpak, apptainer, nspawn>:
Add `tramp-completion-use-cache' argument.
Diffstat (limited to 'lisp/net/tramp-cache.el')
-rw-r--r-- | lisp/net/tramp-cache.el | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/lisp/net/tramp-cache.el b/lisp/net/tramp-cache.el index 2694b8f490a..4ff7d649b42 100644 --- a/lisp/net/tramp-cache.el +++ b/lisp/net/tramp-cache.el @@ -73,6 +73,9 @@ ;; `tramp-persistency-file-name', although being connection ;; properties related to a `tramp-file-name' structure. ;; +;; - Properties retrieved from `tramp-connection-properties' are not +;; saved in the file `tramp-persistency-file-name'. +;; ;; - Reusable properties, which should not be saved, are kept in the ;; process key retrieved by `tramp-get-process' (the main connection ;; process). Other processes could reuse these properties, avoiding @@ -86,6 +89,8 @@ (require 'tramp-compat) (require 'time-stamp) +(declare-function tramp-get-method-parameter "tramp") + ;;; -- Cache -- ;;;###tramp-autoload @@ -136,17 +141,20 @@ If it doesn't exist yet, it is created and initialized with matching entries of `tramp-connection-properties'. If KEY is `tramp-cache-undefined', don't create anything, and return nil." ;; (declare (tramp-suppress-trace t)) - (unless (eq key tramp-cache-undefined) - (or (gethash key tramp-cache-data) - (let ((hash - (puthash key (make-hash-table :test #'equal) tramp-cache-data))) - (when (tramp-file-name-p key) - (dolist (elt tramp-connection-properties) - (when (string-match-p - (or (nth 0 elt) "") - (tramp-make-tramp-file-name key 'noloc)) - (tramp-set-connection-property key (nth 1 elt) (nth 2 elt))))) - hash)))) + (let ((tramp-verbose 0)) + (unless (eq key tramp-cache-undefined) + (or (gethash key tramp-cache-data) + (let ((hash + (puthash key (make-hash-table :test #'equal) tramp-cache-data))) + (when (tramp-file-name-p key) + (dolist (elt tramp-connection-properties) + (when (string-match-p + (or (nth 0 elt) "") + (tramp-make-tramp-file-name key 'noloc)) + ;; Mark it as taken from `tramp-connection-properties'. + (tramp-set-connection-property + key (propertize (nth 1 elt) 'tramp-default t) (nth 2 elt))))) + hash))))) ;; We cannot use the `declare' form for `tramp-suppress-trace' in ;; autoloaded functions, because the tramp-loaddefs.el generation @@ -596,9 +604,14 @@ PROPERTIES is a list of file properties (strings)." (not (tramp-file-name-localname key)) (not (gethash "login-as" value)) (not (gethash "started" value))) - (dolist (k (hash-table-keys value)) - (when (string-prefix-p " " k) - (remhash k value))) + (progn + (dolist (k (hash-table-keys value)) + ;; Suppress ephemeral properties. + (when (or (string-prefix-p " " k) + (get-text-property 0 'tramp-default k)) + (remhash k value))) + (unless (hash-table-keys value) + (remhash key cache))) (remhash key cache))) cache) ;; Dump it. @@ -635,15 +648,17 @@ your laptop to different networks frequently." "Return a list of (user host) tuples allowed to access for METHOD. This function is added always in `tramp-get-completion-function' for all methods. Resulting data are derived from connection history." - (and tramp-completion-use-cache - (mapcar - (lambda (key) - (and (tramp-file-name-p key) - (string-equal method (tramp-file-name-method key)) - (not (tramp-file-name-localname key)) - (list (tramp-file-name-user key) - (tramp-file-name-host key)))) - (hash-table-keys tramp-cache-data)))) + (mapcar + (lambda (key) + (let ((tramp-verbose 0)) + (and (tramp-file-name-p key) + (string-equal method (tramp-file-name-method key)) + (not (tramp-file-name-localname key)) + (tramp-get-method-parameter + key 'tramp-completion-use-cache tramp-completion-use-cache) + (list (tramp-file-name-user key) + (tramp-file-name-host key))))) + (hash-table-keys tramp-cache-data))) ;; When "emacs -Q" has been called, both variables are nil. We do not ;; load the persistency file then, in order to have a clean test environment. |