aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/misc/tramp.texi17
-rw-r--r--etc/NEWS8
-rw-r--r--lisp/net/tramp-cmds.el45
3 files changed, 65 insertions, 5 deletions
diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi
index 1eed1acd964..7c1f0007dfb 100644
--- a/doc/misc/tramp.texi
+++ b/doc/misc/tramp.texi
@@ -4783,13 +4783,13 @@ proxy definitions (@pxref{Ad-hoc multi-hops}).
4783 4783
4784@deffn Command tramp-cleanup-all-buffers 4784@deffn Command tramp-cleanup-all-buffers
4785Just as for @code{tramp-cleanup-all-connections}, all remote 4785Just as for @code{tramp-cleanup-all-connections}, all remote
4786connections and ad-hoc proxy definition are cleaned up in addition to 4786connections and ad-hoc proxy definitions are cleaned up in addition to
4787killing all buffers related to remote connections. 4787killing all buffers related to remote connections.
4788@end deffn 4788@end deffn
4789 4789
4790@deffn Command tramp-cleanup-some-buffers 4790@deffn Command tramp-cleanup-some-buffers
4791Similar to @code{tramp-cleanup-all-buffers}, where all remote 4791Similar to @code{tramp-cleanup-all-buffers}, where all remote
4792connections and ad-hoc proxy definition are cleaned up. However, 4792connections and ad-hoc proxy definitions are cleaned up. However,
4793additional buffers are killed only if one of the functions in 4793additional buffers are killed only if one of the functions in
4794@code{tramp-cleanup-some-buffers-hook} returns @code{t}. 4794@code{tramp-cleanup-some-buffers-hook} returns @code{t}.
4795@end deffn 4795@end deffn
@@ -4801,6 +4801,19 @@ remote buffers which are linked to a remote file, remote @code{dired}
4801buffers, and buffers related to a remote process are cleaned up. 4801buffers, and buffers related to a remote process are cleaned up.
4802@end defopt 4802@end defopt
4803 4803
4804@deffn Command tramp-cleanup-bufferless-connections
4805
4806Similar to @code{tramp-cleanup-all-connections}, remote connections and
4807ad-hoc proxy definitions are flushed, but limited to those connections
4808for which no associated buffers exist (except for Tramp internal
4809buffers).
4810
4811This command is helpful to prune connections after you close remote-file
4812buffers without having to either cherry pick via
4813@code{tramp-cleanup-connection} or clear them all via
4814@code{tramp-cleanup-all-connections}.
4815@end deffn
4816
4804 4817
4805@node Renaming remote files 4818@node Renaming remote files
4806@section Renaming remote files 4819@section Renaming remote files
diff --git a/etc/NEWS b/etc/NEWS
index a86c2ca2409..7a5b96b5eae 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -951,6 +951,14 @@ we invite Flyspell users to enable this new option and report issues.
951** Tramp 951** Tramp
952 952
953+++ 953+++
954*** New command 'tramp-cleanup-bufferless-connections'.
955Connection-related objects for which no associated buffers exist, except
956for Tramp internal buffers, are flushed. This is helpful to prune
957connections after you close remote-file buffers without having to either
958cherry pick via 'tramp-cleanup-connection' or clear them all via
959'tramp-cleanup-all-connections'.
960
961+++
954*** Connection method "kubernetes" supports now optional namespace. 962*** Connection method "kubernetes" supports now optional namespace.
955The host name for Kubernetes connections can be of kind 963The host name for Kubernetes connections can be of kind
956[CONTAINER.]POD[%NAMESPACE], in order to specify the namespace to be 964[CONTAINER.]POD[%NAMESPACE], in order to specify the namespace to be
diff --git a/lisp/net/tramp-cmds.el b/lisp/net/tramp-cmds.el
index 71829e81093..5e7bface07b 100644
--- a/lisp/net/tramp-cmds.el
+++ b/lisp/net/tramp-cmds.el
@@ -101,12 +101,35 @@ SYNTAX can be one of the symbols `default' (default),
101;; Use `match-buffers' starting with Emacs 29.1. 101;; Use `match-buffers' starting with Emacs 29.1.
102;;;###tramp-autoload 102;;;###tramp-autoload
103(defun tramp-list-remote-buffers () 103(defun tramp-list-remote-buffers ()
104 "Return a list of all buffers with remote `default-directory'." 104 "Return a list of remote buffers, excluding internal tramp buffers.
105A buffer is considered remote if either its `default-directory' or its
106buffer file name is a remote file name."
105 (tramp-compat-seq-keep 107 (tramp-compat-seq-keep
106 (lambda (x) 108 (lambda (buffer)
107 (when (tramp-tramp-file-p (tramp-get-default-directory x)) x)) 109 (when (tramp-tramp-file-p
110 (or (buffer-file-name buffer)
111 (tramp-get-default-directory buffer)))
112 buffer))
108 (buffer-list))) 113 (buffer-list)))
109 114
115;;;###tramp-autoload
116(defun tramp-list-remote-buffer-connections ()
117 "Return a list of all remote buffer connections.
118A buffer is considered remote if either its `default-directory' or the
119function `buffer-file-name' is a remote file name."
120 (seq-uniq
121 (mapcar (lambda (buffer)
122 (or
123 (when (buffer-file-name buffer)
124 (file-remote-p (buffer-file-name buffer)))
125 (when (tramp-get-default-directory buffer)
126 (file-remote-p (tramp-get-default-directory buffer)))))
127 ;; Eliminate false positives from internal tramp buffers
128 (seq-remove
129 (lambda (buffer)
130 (member (buffer-name buffer) (tramp-list-tramp-buffers)))
131 (tramp-list-remote-buffers)))))
132
110;;; Cleanup 133;;; Cleanup
111 134
112;;;###tramp-autoload 135;;;###tramp-autoload
@@ -321,6 +344,22 @@ non-nil."
321 (let ((tramp-cleanup-some-buffers-hook '(always))) 344 (let ((tramp-cleanup-some-buffers-hook '(always)))
322 (tramp-cleanup-some-buffers))) 345 (tramp-cleanup-some-buffers)))
323 346
347;;;###tramp-autoload
348(defun tramp-cleanup-bufferless-connections ()
349 "Flush connection-related objects for which no buffer exists.
350A bufferless connection is one for which no live buffer's
351`buffer-file-name' or `default-directory' is associated with that
352connection, except for Tramp internal buffers.
353Display a message of cleaned-up connections."
354 (interactive)
355 (when-let* ((bufferless-connections
356 (seq-difference
357 (mapcar #'tramp-make-tramp-file-name (tramp-list-connections))
358 (tramp-list-remote-buffer-connections))))
359 (message "Cleaning up %s" (mapconcat #'identity bufferless-connections ", "))
360 (dolist (connection bufferless-connections)
361 (tramp-cleanup-connection (tramp-dissect-file-name connection 'noexpand)))))
362
324;;; Rename 363;;; Rename
325 364
326(defcustom tramp-default-rename-alist nil 365(defcustom tramp-default-rename-alist nil