Subject: bug#76417: [PATCH] Add tramp-cleanup-bufferless-connections

From: Michael Albinus <[email-masked]>
Date: Thu, 20 Feb 2025 13:07:36 +0100

Ship Mints <[email-masked]> writes:

Hi,

> 'tramp-cleanup-bufferless-connections' cleans up connection-related
> objects for which no associated buffers exist.  This is helpful to
> prune connections after you close remote-file buffers without having
> to either cherry pick via 'tramp-cleanup-connection' or clear them all
> via 'tramp-cleanup-all-connections'.

Thanks for this. However, I feel we have already too many
Tramp-cleanup-* commands; I fear another one would bring more
confusion. Nobody but the author would remember :-)

> I looked for an equivalent but didn't see one so I've been using this
> command, and I think it's ready for contribution.

For this, we have tramp-cleanup-some-buffers. Would it be possible to
implement your feature by adding a proper hook function in
tramp-cleanup-some-buffers-hook?

As a first change, I propose to extend tramp-list-remote-buffers like

--8<---------------cut here---------------start------------->8---
(defsubst tramp-get-buffer-file-name (buffer)
  "Return `buffer-file-name' of BUFFER."
  (buffer-local-value 'buffer-file-name buffer))

(defun tramp-list-remote-buffers ()
  "Return a list of all buffers with remote `default-directory'."
  (tramp-compat-seq-keep
   (lambda (x)
     (when (or (tramp-tramp-file-p (tramp-get-default-directory x))
	       (tramp-tramp-file-p (tramp-get-buffer-file-name x)))
       x))
   (buffer-list)))
--8<---------------cut here---------------end--------------->8---

Could you work on such a patch?

> -Stephane

Best regards, Michael.