emacs client/server
Connecting to a remote Emacs server is a classic power-user move that bridges the gap between local performance and remote persistence. Since you already have the server running on Ubuntu, here is how to bridge the connection and what to expect from the workflow.
How to Connect from a Remote Client
To connect a remote client to a server, you typically use emacsclient. The most secure and common method is to tunnel the connection over SSH.
1. SSH Tunneling (Recommended)
By default, the Emacs server communicates via a local Unix socket. To access it remotely, you can use SSH to forward that socket or use TCP (though TCP is less secure).
On your remote client, run:
Bash
ssh -L 5000:localhost:5000 user@your-ubuntu-server
(Note: This assumes you have configured Emacs to use a TCP port rather than a Unix socket. If using a socket, you would tunnel the socket path specifically.)
2. Using the Client
Once the tunnel is established, you tell the local client to look for the server:
Bash
emacsclient -c -f ~/path/to/server-file
-c: Opens a new frame.-nw: Opens the client in the terminal instead of a GUI window.
Pros and Cons of This Setup
Pros
- Persistent State: Your buffers, undo history, and process buffers (like shells or compilation logs) stay alive even if your SSH connection drops or you shut down your local machine.
- Instant Startup: Emacs can be heavy with many packages. By connecting to a running server, the client opens instantly because the initialization has already happened.
- Resource Management: All the heavy lifting (LSP servers, grep, compilation) happens on the Ubuntu server, keeping your local client machine cool and saving battery.
- Shared Buffers: You can connect multiple clients to the same session, allowing you to switch from a desktop to a laptop while looking at the exact same line of code.
Cons
- Latency: Unlike editing over TRAMP (where the UI is local but the file is remote), an
emacsclient -cGUI frame sends X11 or Wayland commands over the wire. This can feel "floaty" or laggy on slower connections. - Network Dependency: If your internet cuts out, you lose the ability to interact with the editor immediately, whereas a local Emacs using TRAMP would let you keep typing in the buffer.
- Configuration Sync: You must ensure your Emacs configuration (
init.el) is managed on the server. If you make a change to a keybinding, you have to reload it on the server for all clients to see it. - Security Risk: If using TCP sockets without proper tunneling or firewalls, you could theoretically expose your Emacs session (and thus your filesystem) to the network.
A Note on the "TRAMP" Alternative
Many users find that running Emacs locally and using TRAMP (/ssh:user@server:/path/to/file) provides a snappier experience because the UI rendering is local, while only the file saves and shell commands happen on the Ubuntu server. However, TRAMP does not preserve your session if the local Emacs crashes.