Clementson's Blog

Bits and pieces (mostly Lisp-related) that I collect from the ether.

December 2004
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Nov  Jan

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):
  1. 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)
  2. Add the following to your .emacs file:
    (defun start-lispworks ()
      (interactive)
        (shell-command "~/Library/Scripts/lw-start.app&"))
  3. 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
  4. 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)
To use (when Emacs is already running): To use (when Emacs isn't already running): Thanks again to Kevin Birch for his help in getting this working. Let me know if you have any problems with these instructions.

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:
  1. 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.
  2. 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.
  3. 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.

emacs Copyright © 2005 by Bill Clementson