4

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)?

stsquad
  • 5,712
  • 3
  • 36
  • 54

2 Answers2

5

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.

Erik Iverson
  • 892
  • 4
  • 15
  • `tramp-tramp-file-p` does *not* return `t` for a Tramp file, it actually returns `0`, which happens to be the index returned by `string-match` which is used to check Tramp filename syntax. I am inclined to say that this is a bug, either in `tramp-tramp-file-p`'s docstring or in its implementation. I would recommend using `file-remote-p` for testing if a file is remote, because it is more generic (it should be able to handle other remote access handlers besides Tramp). – ack Jul 10 '17 at 22:58
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).

phils
  • 71,335
  • 11
  • 153
  • 198