Occasionally I use TRAMP mode to edit remote files.

I want to detect if the file open is remote, and if so, get the hostname of the server it's on.

I can't find any buffer-local variable that holds this information, though. tramp-current-host holds the hostname, but isn't buffer local.

2 Answers 2


I ended up finding it out shortly after posting this question.

(file-remote-p default-directory 'host)

This works, returning nil if the file isn't remote, or the hostname if it is.


Yes, calling file-remote-p is the proper way. If you want to see the hostname in the modeline, I recommend you to install tramp-theme from GNU ELPA.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.