How to check if connected to remote server?

elisp, emacs, tramp

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.

Problem

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 ```

Original source

Related problems