I'd like to be able to run emacs on one computer:
server $ emacs --daemon
And then connect to it from another:
local $ emacsclient -c server
Is this possible? If so, how?
You cannot use emacsclient to connect to an Emacs instance running on a remote computer. This client-server concept is related to (local) processes, not network nodes. However, you can use various network technologies to log in to the remote computer, attach to an emacs server running there and display the emacsclient's screen locally. Depending on the operating system that is used the networking could be done via SSH (terminal/X-Forwarding), VNC, RDP etc.
As some people pointed out, emacsclient actually does have an option to connect to the server via TCP. However, emacsclient was never meant to be used remotely, the TCP socket option is required for compatibility with non-UNIX systems (i.e. operating systems where UNIX domain sockets are not available, like Windows).
This may be not what you want but just in case see if it can help you some way.
I usually work inside a virtual machine bootstrapped with Vagrant, I have my
~/.emacs.d directory synced between my machine (local) and the virtual machine (remote) putting the following in the
config.vm.synced_folder "~/.emacs.d", "/home/vagrant/.emacs.d"
Also, my Emacs config automatically starts a server on startup:
(require 'server) (setq server-use-tcp t server-socket-dir "~/.emacs.d/server") (unless (server-running-p) (server-start))
So when I launch an Emacs server inside the virtual machine, I can connect to it with the following:
ssh -Y -i ~/.vagrant.d/insecure_private_key "<virtual machine hostname>" 'emacsclient -c -f ~/.emacs.d/server/server'
virtual machine hostname is the hostname of the virtual machine I have configured in my ~/.ssh/config:
Host <virtual machine hostname> HostName 127.0.0.1 User vagrant Port 2222 UserKnownHostsFile /dev/null StrictHostKeyChecking no PasswordAuthentication no IdentityFile /home/anler/.vagrant.d/insecure_private_key IdentitiesOnly yes LogLevel FATAL ForwardAgent yes
Note: Before launching the Emacs server inside the virtual machine I check that the
~/.emacs.d/server/server file is not present (if it is I just remove it) because otherwise it won't work.