Subject: bug#76457: 31.0.50; Cannot create bookmark to chained TRAMP connection

From: Michael Albinus <[email-masked]>
Date: Sat, 22 Feb 2025 16:33:13 +0100

Ship Mints <[email-masked]> writes:

> On Sat, Feb 22, 2025 at 7:12 AM Sean Whitton
> <[email-masked]> wrote:

Thank you both. Finally, I have made the following changes based on your
proposals (not pushed yet):

In "5.4 Declaring multiple hops in the file name "

--8<---------------cut here---------------start------------->8---
   TRAMP adds the ad-hoc definitions as an ephemeral record to
‘tramp-default-proxies-alist’, which are available for reuse during
that Emacs session.  Subsequent TRAMP connections to the same remote
host can then use the abbreviated form ‘/ssh:you@remotehost:/path’.

 -- User Option: tramp-show-ad-hoc-proxies
     If this user option is non-‘nil’, ad-hoc definitions are kept in
     remote file names instead of showing the abbreviations.  This is
     useful if the ad-hoc proxy definition shall be used in further
     Emacs sessions, kept in configuration files of recentf and other
     packages.

     A non-‘nil’ setting of this option has effect only if set before
     the connection is established.

          (customize-set-variable 'tramp-show-ad-hoc-proxies t)

   Ad-hoc definitions are removed from ‘tramp-default-proxies-alist’
via the command ‘M-x tramp-cleanup-all-connections <RET>’ (*note
Cleanup remote connections::).

 -- User Option: tramp-save-ad-hoc-proxies
     For ad-hoc definitions to be saved automatically in
     ‘tramp-default-proxies-alist’ for future Emacs sessions, set
     ‘tramp-save-ad-hoc-proxies’ to non-‘nil’.  The resulting user
     option ‘tramp-default-proxies-alist’ is saved in your ‘.emacs’
     file.

     If you use saved configuration files with abbreviated ad-hoc
     proxy definitions on another host, for example by distribution of
     the ‘recentf-save-file’, you must distribute your ‘.emacs’ file
     as well.

          (customize-set-variable 'tramp-save-ad-hoc-proxies t)
--8<---------------cut here---------------end--------------->8---

In "7 Frequently Asked Questions"

--8<---------------cut here---------------start------------->8---
   • Why don't saved ad-hoc multi-hop file names work in a new Emacs
     session?

     By default, ad-hoc multi-hop file names are abbreviated after
     completing the initial connection.  These abbreviated forms
     retain only the final hop, and so only the Emacs session that
     generated the abbreviated form can understand it.  *Note Ad-hoc
     multi-hops::.

     For example, after connecting to
     ‘/ssh:bird@bastion|ssh:[email-masked]:/opt/news/etc’, the
     file name becomes ‘/ssh:[email-masked]:/opt/news/etc’.  If
     the abbreviated form is saved in a bookmark, the recent files
     list, bbdb, or similar, a new Emacs session has no way to know
     that the connection must go through ‘bird@bastion’ first.

     There are two mechanisms to deal with this.  The first is to
     customize ‘tramp-show-ad-hoc-proxies’ to a non-‘nil’ value, which
     disables abbreviation.  Then the fully-qualified ad-hoc multi-hop
     file name is the one that will be both displayed and saved.
     *Note tramp-show-ad-hoc-proxies::.

     Alternatively, you can customize ‘tramp-save-ad-hoc-proxies’ to a
     non-‘nil’ value which means to save the information how an
     abbreviated multi-hop file name can be expanded.  *Note
     tramp-save-ad-hoc-proxies::.
--8<---------------cut here---------------end--------------->8---

WDYT?

> The Tramp UI could be improved so that fully-qualified names
> are always retained yet made convenient to use abbreviated file names.
>  That would solve for both persisting remote file names and
> interactive convenience.

No, there's a reason that ad-hoc multi-hop file names are
ad-hoc. Sometimes, it isn't desirable to save them persistently over
Emacs sessions.

> -Stephane

Best regards, Michael.