Remote compiling in Emacs

I wanted to get remote compiles going in Emacs because I wanted to work in Aquamacs on my Mac. In terminal mode, a lot of keys don’t work like in particular Control + the arrow keys and in X11, I lose my Emacs session every time I disconnect and take my laptop home (unless I use something like VNC (slow) or figure out how to get FreeNX to suspend & resume properly).

Here’s how I did it. The basic approach is to use rcompile.el which seems geared for doing remote compiles over rsh, but it can be cajoled into working over ssh:

  1. Set the Emacs variable remote-compile-host to -p 8000. The -p 8000 was only necessary for me because I am sshing to a particular FreeBSD jail that has the build environment i need for the particular project I’m working on.
  2. Set the Emacs variable remote-shell-program to /sw/bin/ssh. This path is a little unusual because I’m using a version of OpenSSH that I installed on my PowerBook using Fink. I’m choosing this over the stock OS X ssh because OpenSSH 4.0 and up support the ControlMaster feature which speeds up repeated connections to the same remote host.
  3. Instead of the Emacs compile command, use remote-compile (defined in rcompile.el).

At this point, Emacs was still crapping out because it was confused by the remote file pathname from TRAMP and didn’t know how to change directories on the remote host:

bash: line 0: cd: / 
No such file or directory

In order to solve this I got tricky and did this:

sudo ln -s / /

This is very hacky though and not everyone may have root access to the remote host they’re using, so I came up with a patch for rcompile.el which works for me.

Let me know if it works for you…

Writing GNU Emacs Extensions: Editor Customizations and Creations with Lisp (O\'Reilly Nutshell)

5 thoughts on “Remote compiling in Emacs

  1. I never really could get into emacs. I used to use it, then fell into VI for my sysadmin duties. But I guess that is where the differences are. Sounds like you are a hard core coder and I am a SA dork.

  2. Pingback: Interesting Emacs Links - 2009 Week 11 « A Curious Programmer

  3. ‘M-x compile’ works out of the box when you edit remote files or directories with Tramp:

    C-x C-f /remotehost: RET
    M-x compile RET

    I think it’s a lot easier to compile on remote hosts.

Leave a Reply

Your email address will not be published.