[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to autoload Tramp methods
From: |
Eshel Yaron |
Subject: |
Re: How to autoload Tramp methods |
Date: |
Tue, 08 Oct 2024 12:44:46 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Hi,
Michael Albinus <michael.albinus@gmx.de> writes:
> sorry for the late reply, I was out of order last days.
No problem at all, I hope you're better.
>> Is it possible to autoload a Tramp method that some extension provides?
>>
>> My problem is as follows: package foo-tramp defines a Tramp method foo.
>> It also, for example, provides an autoloaded command foo-dired that
>> starts Dired in some remote foo directory. From that Dired buffer I use
>> C-x C-f to open some other remote file via the same foo method, now I
>> have a remote foo file name in my file name history. So far so good.
>> But then at some point I restart Emacs, and I want to find that remote
>> file again. The file name is in my history so I can dig it up with M-p
>> in the C-x C-f prompt. However, since I didn't invoke foo-dired or any
>> command from the foo-tramp package or otherwise loaded that package yet,
>> Tramp doesn't know about the foo method and I get an error:
>> "Method ‘foo’ is not known"
>>
>> Can package foo-tramp somehow arrange to be autoloaded when the foo
>> method is used?
>
> Tramp recognizes the "foo" method in remote file names if tramp-methods
> contains an entry for "foo". So you might autoload the settings for
> "foo" in your foo-tramp package. See the approach in tramp-container.el.
> However, you must replace the ;;;###tramp-autoload cookie by ;;;###autoload.
>
> Or see the ELPA packages lxc-tramp, lxd-tramp or incus-tramp.
Thank you. IIUC, in all of these cases the libraries are arranged to be
loaded as soon as Tramp is loaded, right? That's not too bad, but it
would be great to have a way to load foo-tramp just in time.
One option that comes to mind is something like:
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 8961b872a8a..a82a3e564d8 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -1794,7 +1794,12 @@ tramp-dissect-file-name
:port port :localname localname :hop hop))
;; The method must be known.
(unless (or nodefault non-essential
- (assoc method tramp-methods))
+ (assoc method tramp-methods)
+ (when-let ((enable-fun
+ (intern-soft
+ (format "tramp-enable-%s-method" method)))
+ ((functionp enable-fun)))
+ (funcall enable-fun)))
(tramp-user-error
v "Method `%s' is not known" method))
;; Only some methods from tramp-sh.el do support multi-hops.
Then in foo-tramp I could define tramp-enable-foo-method, have it return
non-nil, give it an autoload cookie, and that's it. How would you feel
about such an approach?
Best regards,
Eshel
- How to autoload Tramp methods, Eshel Yaron, 2024/10/05
- Re: How to autoload Tramp methods, Michael Albinus, 2024/10/08
- Re: How to autoload Tramp methods,
Eshel Yaron <=
- Re: How to autoload Tramp methods, Michael Albinus, 2024/10/08
- Re: How to autoload Tramp methods, Eshel Yaron, 2024/10/08
- Re: How to autoload Tramp methods, Michael Albinus, 2024/10/08
- Re: How to autoload Tramp methods, Eshel Yaron, 2024/10/08
- Re: How to autoload Tramp methods, Michael Albinus, 2024/10/08
- Re: How to autoload Tramp methods, Eshel Yaron, 2024/10/09
- Re: How to autoload Tramp methods, Michael Albinus, 2024/10/09