Using a Local Emacs From a Remote Host

Michał Nazarewicz has a very interesting post on using Emacs to edit files on a remote system. Your first reaction is likely, “Meh, isn’t that just Tramp?” I know that was mine but Nazarewicz has a specific requirement: he wants to SSH into the remote system, do his work, and, when he wants to edit a file, use emacsclient to connect back to the Emacs server running on his local host. It is, in a sense, the reverse of what you with Tramp: instead of connecting to a remote file from the local Emacs server, you connect to the local server from the remote host.

The point of this, apparently, is to avoid changing to another shell session when you want to edit a (remote) file. Whether you think this is worth the effort probably depends on what you do on the remote host. If you just want to edit a file or two, Tramp is probably fine. If you’re performing lots of other tasks, Nazarewicz’s method may be useful.

The TL;DR is that when you SSH to the remote host, you arrange to forward the (remote) Emacs server port to the local Emacs server port. That way, when you invoke emacsclient on the remote host, it connects to the server on your local machine. It’s a cute trick but the details can be a little fussy. Read Nazarewicz’s post for the details.

Update [2021-02-04 Thu 16:10]: Added link to Nazarewicz’s post.

This entry was posted in General. Bookmark the permalink.