diff options
| author | shipmints | 2025-02-25 11:34:49 +0100 |
|---|---|---|
| committer | Michael Albinus | 2025-02-25 11:34:49 +0100 |
| commit | bea00a07990ebfbe420636363f8d3514571ae79d (patch) | |
| tree | 21b3e3491e2454d122db3bca6a5bd430e18aac3d | |
| parent | cc8e8b2595ff2ad0c4e4d5805fed1657a5ad504a (diff) | |
| download | emacs-bea00a07990ebfbe420636363f8d3514571ae79d.tar.gz emacs-bea00a07990ebfbe420636363f8d3514571ae79d.zip | |
Add tramp-cleanup-bufferless-connections (bug#76417)
* doc/misc/tramp.texi (Cleanup remote connections): Add
'tramp-cleanup-bufferless-connections'.
* etc/NEWS: Announce 'tramp-cleanup-bufferless-connections'.
* lisp/net/tramp-cmds.el:
(tramp-list-remote-buffer-connections): New function.
(tramp-cleanup-bufferless-connections): New command.
(tramp-list-remote-buffers): Account for 'buffer-file-name'.
| -rw-r--r-- | doc/misc/tramp.texi | 17 | ||||
| -rw-r--r-- | etc/NEWS | 8 | ||||
| -rw-r--r-- | lisp/net/tramp-cmds.el | 45 |
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 |
| 4785 | Just as for @code{tramp-cleanup-all-connections}, all remote | 4785 | Just as for @code{tramp-cleanup-all-connections}, all remote |
| 4786 | connections and ad-hoc proxy definition are cleaned up in addition to | 4786 | connections and ad-hoc proxy definitions are cleaned up in addition to |
| 4787 | killing all buffers related to remote connections. | 4787 | killing 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 |
| 4791 | Similar to @code{tramp-cleanup-all-buffers}, where all remote | 4791 | Similar to @code{tramp-cleanup-all-buffers}, where all remote |
| 4792 | connections and ad-hoc proxy definition are cleaned up. However, | 4792 | connections and ad-hoc proxy definitions are cleaned up. However, |
| 4793 | additional buffers are killed only if one of the functions in | 4793 | additional 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} | |||
| 4801 | buffers, and buffers related to a remote process are cleaned up. | 4801 | buffers, 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 | |||
| 4806 | Similar to @code{tramp-cleanup-all-connections}, remote connections and | ||
| 4807 | ad-hoc proxy definitions are flushed, but limited to those connections | ||
| 4808 | for which no associated buffers exist (except for Tramp internal | ||
| 4809 | buffers). | ||
| 4810 | |||
| 4811 | This command is helpful to prune connections after you close remote-file | ||
| 4812 | buffers 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 |
| @@ -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'. | ||
| 955 | Connection-related objects for which no associated buffers exist, except | ||
| 956 | for Tramp internal buffers, are flushed. This is helpful to prune | ||
| 957 | connections after you close remote-file buffers without having to either | ||
| 958 | cherry 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. |
| 955 | The host name for Kubernetes connections can be of kind | 963 | The 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. |
| 105 | A buffer is considered remote if either its `default-directory' or its | ||
| 106 | buffer 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. | ||
| 118 | A buffer is considered remote if either its `default-directory' or the | ||
| 119 | function `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. | ||
| 350 | A bufferless connection is one for which no live buffer's | ||
| 351 | `buffer-file-name' or `default-directory' is associated with that | ||
| 352 | connection, except for Tramp internal buffers. | ||
| 353 | Display 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 |