Tutorial :Does tramp offer any API for interrogating information from the buffer-file-name



Question:

I'm currently doing a lot of work on remote machines with tramp. However the project logic gets confused when building make command lines as it will attempt to cd to some /ssh:blah.... path.

Does tramp provide any API functions to test if a buffer or a buffer filename is actually managed by tramp and therefor on a remote machine? Can it provide additional information about the type of connection (for example ssh user/host details)?


Solution:1

As to your first question about checking if a filename is managed by tramp, see the function tramp-tramp-file-p, which will return t if filename is a tramp file.


Solution:2

The variable tramp-file-name-regexp is used to match Tramp-like filenames. (edit: see erikriverson's answer below for a more convenient way to match against this.)

This is added to file-name-handler-alist (which determines the handler for all filenames), and associated with tramp-file-name-handler, so you could alternatively test the return value of the find-file-name-handler function to see whether it matches. This seems like a slightly more robust method (although in practice it probably makes no difference).

(eq (find-file-name-handler filename nil) 'tramp-file-name-handler)

(tramp-dissect-file-name filename) will then return the individual connection components (also see the tramp-file-name-structure variable).


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »