Working with Emacs on a remote connection can be annoying due to the lack of a GUI, and the fact you have to replicate your settings on the server-side copy of Emacs to have access to them. Luckily you can use X11 forwarding to connect your local Emacs to a remote connection. While this is super simple on Linux, it requires a little more effort on a Mac. First off, download and install XQuartz to enable the X Window System on OS X. Download the Emacs source code from the Emacs website and extract the archive. Navigate to the Emacs directory and run the configure file with the --with-ns=no --with-x flags to compile without support for the OS X NS windows system, and with support for the X window system.

./configure --with-ns=no --with-x

Now we can compile our X11 compatible Emacs. However, compiling Emacs without support for NS results in an application that looks decidedly less…Mac-y. For one thing, it doesn’t support Retina displays, and while it has a GUI that the default Emacs on OS X lacks, it looks jarring on a Mac screen. For this reason, I like to compile X11 compatible Emacs with a different name so that I can still use the GUI-less default Emacs when I’m working locally (XQuartz also takes a couple seconds to start up, which can be annoying if you’re just making a quick change to a file). To do this, open up the Makefile generated by configure, and replace the EMACS_NAME variable definition with your preferred name.

EMACS_NAME = `echo emacs | sed '$(TRANSFORM)'`

I like to call this application emacsx, and you can see this modified line below:

EMACS_NAME = `echo emacsx | sed '$(TRANSFORM)'`

Now you can just compile and install Emacs like normal

make -j4
sudo make install

Finally, you have to modify the /etc/ssh/sshd_config file to actually enable X11 forwarding. The line below will do so on modern OS X installations and preserve the original file as /etc/ssh/sshd_config~orig.

sudo sed -i ~orig 's/#X11Forwarding\ no/X11Forwarding\ yes/' /etc/ssh/sshd_config

Now connect to your remote using ssh -Y and when you launch Emacs, the X11 compatible Emacs will launch.

ssh -Y <username>@<hostname>

Note that if you want to invoke the X11 compatible Emacs directly on your system you will have to use the different name that you gave it above e.g.