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

From: Michael Albinus <[email-masked]>
Date: Sun, 23 Feb 2025 13:18:52 +0100

Ship Mints <[email-masked]> writes:

> Hi, Michael, take a look at this version of the patch. -Stephane

Done. Finally, you're right. It is worth an own command. What I do miss
is its documentation in tramp.texi, node "Cleanup remote connections".

Some further remarks:

> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -888,6 +888,14 @@ we invite Flyspell users to enable this new option and report issues.
>
>  ** Tramp
>
> ++++
> +*** New command tramp-cleanup-bufferless-connections.

'tramp-cleanup-bufferless-connections'

> +Connection-related objects for which no associated buffers exist are

... for which no associated buffers except Tramp internal ones exist ...

> --- a/lisp/net/tramp-cmds.el
> +++ b/lisp/net/tramp-cmds.el
> +(defsubst tramp-get-buffer-file-name (buffer)
> +  "Return `buffer-file-name' for BUFFER."
> +  (buffer-local-value 'buffer-file-name buffer))

I've proposed this. But thinking about, there is already the exact same
function 'buffer-file-name'. We shall use it instead.

> +(defsubst tramp-get-buffer-default-directory (buffer)
> +  "Return `default-directory' for BUFFER."
> +  (buffer-local-value 'default-directory buffer))

Not needed here. This is defined in tramp.el.

> +A buffer is considered remote if either its `default-directory' or its
> +buffer file name is considered remote by the function
> +`tramp-tramp-file-p'."

... "is a remote file name."

>    (tramp-compat-seq-keep
> -   (lambda (x)
> -     (when (tramp-tramp-file-p (tramp-get-default-directory x)) x))
> +   (lambda (buffer)
> +     (when (or
> +            (tramp-tramp-file-p (tramp-get-buffer-file-name buffer))
> +            (tramp-tramp-file-p (tramp-get-buffer-default-directory buffer)))
> +       buffer))

Simplify as

--8<---------------cut here---------------start------------->8---
(when (tramp-tramp-file-p
        (or (buffer-file-name buffer)
        (tramp-get-buffer-default-directory buffer)))
   buffer)
--8<---------------cut here---------------end--------------->8---

> +(defun tramp-list-remote-buffer-connections ()
> +  "Return a list of all remote buffer connections.
> +A buffer is considered remote if either its `default-directory' or the
> +function `buffer-file-name' is considered remote by
> +`tramp-tramp-file-p'."

... "is a remote file name."

Best regards, Michael.