Using LispWorks Personal with Emacs/SLIME on Mac OS X
Sunday, December 19, 2004
When I posted about OS X being my new Lisp platform, I mentioned that I hadn't yet gotten the LispWorks Personal Version to work on Mac OS X with Emacs and SLIME. I said
"With LispWorks (at least for the time being), I'm using the LispWorks IDE since I'm using the LispWorks Personal version (which does not support the creation of console versions of LispWorks which are needed for inferior-lisp usage in Emacs). When I learn a bit more about AppleScript, I'll create a startup script similar to my Win32 script so that I can use LispWorks Personal in OS X with Emacs/SLIME in the same manner as I'm doing on Win32."Well, Kevin Birch (who has a blog too) was kind enough to replicate what I'd done on Win32 with an AppleScript script (he also pointed me to a good explanation of GUI scripting with AppleScript). So, now I can use the LispWorks IDE alongside Emacs with SLIME, thus having both the (IMHO) superior Lisp development environment of Emacs/SLIME and the extra tools that come with the LispWorks IDE. The following will work for LispWorks Personal on Mac OS X 10.3 but will only need minor "tweaking" for other LispWorks versions. Here are the necessary steps (I'll assume you've already got SLIME installed and setup in your .emacs file):
- Create a
".slime.lisp" startup file with the following contents:
(load "~/site/slime/swank-loader.lisp") #+lispworks (mp:initialize-multiprocessing) (swank:create-swank-server 4005)
- Add the following to your .emacs file:
(defun start-lispworks () (interactive) (shell-command "~/Library/Scripts/lw-start.app&")) - Create (and save as an App) the following AppleScript script and put it in your
"~/Library/Scripts" directory (you might need to create this
directory) as "lw-start.app":
tell application "LispWorks Personal" activate tell application "System Events" tell process "lispworks-4-3-0-personal-darwin" repeat until get frontmost end repeat keystroke return tell window "Listener 1" if exists sheet 1 then click button "Close" of sheet 1 end if keystroke "(load \"~/.slime.lisp\")" keystroke return end tell end tell end tell end tell
delay 2
tell application "Emacs" activate tell application "System Events" tell process "Emacs" tell window 1 key code 53 keystroke "x" keystroke "slime-connect" keystroke return keystroke return keystroke return end tell end tell end tell end tell - There is a modification needed to the "swank-lispworks.lisp" file
so that LispWorks Personal can work properly. I've submitted a
patch to the SLIME developers for this (so you might not need to do
anything if you're reading this sometime in the future) but, if you're using a
version of SLIME without this patch, you may need to make the
necessary changes yourself. The first few lines of "create-socket"
need to be changed as follows:
(defimplementation create-socket (host port) (multiple-value-bind (socket where errno) #-(or lispworks4.1 (and macosx lispworks4.3)) (comm::create-tcp-socket-for-service port :address host) #+(or lispworks4.1 (and macosx lispworks4.3)) (comm::create-tcp-socket-for-service port)
- Start LispWorks first with "M-x start-lispworks" from Emacs - it will start up LispWorks and then connect with SLIME.
- Evoke the "lw-start" AppleScript script - it will start up LispWorks and then start up Emacs and SLIME. For convenience, you might want to put this script in your Dock or enable the AppleScript menu. Incidentally, this approach will work when Emacs is already running too.
Update-2004-12-20: Martin Simmons from Xanalys posted on the SLIME developers list a different version of the "swank-lispworks.lisp" mod that I had previously posted above. Since his was better than mine and will probably be in SLIME CVS shortly, I've replaced my version with his in this post.
Update-2004-12-29: John Wiseman noted a number of problems with the original AppleScript:
- I had forgotten to double-escape the quotes on the "load" statements, so they didn't show up in the HTML. I've fixed that now.
- Some machines may need a delay in between the load of LispWorks and the load of Emacs. I originally didn't have any delay in the script - I've put in a delay of 2 seconds; however, depending on your Mac, you may be able to remove (or change) this delay amount.
- If you have the variable "mac-command-key-is-meta" set to nil, the original script wouldn't work since the original script assumed that the Mac command key would be meta. John's alternative of using the "Esc" key (key code 53) in the script works with whatever setting "mac-command-key-is-meta" is set to; therefore, I've changed the script to use John's approach.

