Friday, April 25, 2008

Remote lisp hacking

The problem

You have several machines from which you would like to hack on a lisp project but do not wish to run seperate instances of /emacs/slime/sbcl/ on each machine. You'd like to use the single running emacs instance and view it remotely from any of those machines. How to best achieve this?

Possible Solutions

  • Use swank and tramp to access your lisp image and source files respectively. Probably the best way to do it if you know what you are doing but if that's too much work then skip this solution. 
  • Use remote desktop tools like VNC -- We would rather not use vnc unless there is no other option. 
  • Under screen start emacs with -nw. Now you can detach and attach from a remote site. This is a fine option if you like text-mode emacs. If aesthetics drive you away from text-mode and toward a nicer looking emacs with pretty fonts and colours then this is sadly not an acceptable solution.
  •  Use standard tools like ssh configured with X forwarding to view the remote emacs. 

The solution 

We suppose you have a working GNU/Emacs installed. 

Create a shell script called remote-emacs with the following contents:

#!/bin/bash
emacsclient -e "(make-frame-on-display \"$DISPLAY\")" 

put it somewhere handy in your path so you can easily run it. For example if you put it in your ~/bin/ add an entry to your bash_profile:

PATH=$PATH:~/bin

EXPORT PATH

Next open up your .emacs file and enter the following:

(add-hook 'server-done-hook 'delete-frame)

(add-hook 'server-done-hook (lambda nil (kill-buffer nil)))

(server-start)

Add the last line only if you want emacs to start the server automatically without your needing to start it manually.

On the server machine, fire up emacs and slime as usual, load all the required libraries and code into your lisp image and if necessary manually instruct emacs to start the server using:

M-x server-start

It's time to test out our script and see if it works. On the remote machine, ssh into the server using the -X flag : 

ssh -X username@server

remote-emacs

And we are done! Enjoy the remote lisp hacking -- all your changes will persist and you can always pick up and start hacking where you last left off without always initialising your environment each time.  

2 comments:

namin said...

Which version of emacsclient are you using? With version 21.4, I don't have an -e switch option, so I can't run the remote-emacs script. Also, is the tmp path relevant?

lispy shrek said...

Hey Namin,

I am using emacsclient 22.1 which is the current version for Ubuntu 8.04. The tmp path is not relevant, thanks for pointing it out. All the best.