Search code examples
emacselisptramp

How to check if connected to remote server?


I use tramp to connect to my company's servers. I would like to customize my functions to work differently if I am accessing local files vs remote ones.

Is there a variable I could check if the buffer I am accessing is on a remote server or my local machine?

Something like:

if(TRAMP_CONNECTED)
 Do this
else
 Do that

Solution

  • The most robust check is likely default-directory. This variable is always set buffer local. If (file-remote-p default-directory) returns non-nil, your buffer is under Tramp control.