Installing SBCL, Emacs, and SLIME on Windows XP

May 30th, 2008 | by Peter |

My recent install guide for CLISP, Emacs, and SLIME on Windows XP was a big hit - it has had about 2000 hits and 5 sincere thanks in the comments (it even got praise from a troll!). In it I promised a similar guide for SBCL, and here it is.

The nice thing is that swapping out Common Lisp implementations within an Emacs/SLIME setup is easy, so maybe 3/4 of this guide is identical to the CLISP guide. I’ll put a disclaimer at the beginning of each section saying whether there’s anything new or whether you can skip it.

0. Files to Download [DIFF: The only difference is the link to the SBCL installer instead of the CLisp installer]

If you want to get started on downloading the setup files, here are the links:

1. Setup Directories [NO DIFF: skip if you've completed the CLisp guide]

Windows XP loves extremely long pathnames like C:\Documents and Settings\Username\Application Data. This is okay if for GUI-driven apps, but in Emacs, you’re not clicking, you’re typing, and you want short path names. Also, much (most?) of the open source Common Lisp tools are developed on *nix, so there’s less impedance mismatch when using stuff off the net if you have a *nix-ish folder structure.

Start with a root folder. In the pathnames in the rest of this guide, I’ll refer to it as [HOME]. I used C:\home\ to match the *nix convention of having user files be in /home/username/. You also need a username directory - I called mine peter and I’ll refer to it as [USR]. So in my case, [HOME]/[USR] would be C:\home\peter\.

Emacs NOTE #1: One important point about filenames in Emacs is that they CAN be entered with ‘/’, but if you prefer to use ‘\’, you have to escape it with another back slash, so in Emacs buffers and files, you would enter “C:/home/” or “C:\\home\\” but never “C:\home\”. The trailing slash is also important because it indicates that it’s a directory. Now that you have chosen your [ROOT] and [USR] values, these are the folders you should setup:

  • [HOME]\[USR]\
  • [HOME]\[USR]\site\
  • [HOME]\[USR]\docs\
  • [HOME]\[USR]\lisp\
  • [HOME]\[USR]\info\
  • [HOME]\bin\

2. Setup Emacs [NO DIFF: skip if you've completed the CLisp guide]

Emacs does not need to be “installed” like most Windows apps - it just runs from its directory. Extract it to [HOME]\bin\. I changed the folder name from emacs-22.2 to just emacs, so my path was c:\home\bin\emacs\. You run emacs by running the file [HOME]\bin\emacs\bin\runemacs.exe.

Emacs settings are stored in a configuration file called “.emacs”. On Windows, the default working folder and .emacs location is C:\Documents and Settings\Username\Application Data, but that’s too painful to type and it’s a hidden folder so it’s not even easy to get through with the GUI. To have Emacs work in a different folder, create a file called site-start.el in the emacs\site-lisp folder. In that folder, put the following line (but change the path to match yours):

(setenv “HOME” “[HOME]/[USR]/”)

(Thanks Nathaniel! This was probably the biggest annoyance of mine that made me put off finishing setup for so long.)

Emacs NOTE #2: Emacs has lots (and lots and lots) of keyboard shortcuts, many more than there are letters in the alphabet. Many of them require multiple keys or a sequence of keys called a “chord”. The two modifier keys used are Control and Alt (also called Meta). The common way to write chords is to use C- and M- for Control and Meta, so to run the command to close Emacs, you hold down Control and X, then let go, then hold down Control and C. This is written as C-x C-c. Sometimes a chord is followed by another letter or the name of a command. For instance, to undo, you hold Control and x, then let go and hit u. This is written as C-x u. Dashes mean press at the same time, space means let go. Easy! I made a cheat sheet for common commands in Emacs and SLIME.

Now it’s time to create your .emacs file. Run emacs and hit C-x C-f. This is the find command, which is used to create or open a file. At the prompt “Find file: “, type “~/.emacs” (without quotes). Right now just put a ; (that’s the comment marker in Emacs Lisp files) and save it by hitting C-x C-s. There’s a world of stuff you can put in a .emacs file, but that’s too much to bite off now.

3. Install SBCL [DIFF: This section is completely different]

Although the Windows port of SBCL is still experimental, there is a Windows installer (.msi) file for v1.0.13 (highest version as of now is v1.0.17). Just run the installer, and install it to the directory:

[HOME]\bin\sbcl-1013\

Then just finish the install wizard. But you’re not finished yet.

Robert Zubek wrote a post about 2 months ago about how to setup SBCL/Emacs/SLIME on Vista, but it doesn’t work exactly right on Windows XP. If you use the .emacs settings from his post, you get this error when you start SLIME (instead of using the .emacs settings in step 4):

fatal error encountered in SBCL pid XXXX:

can’t find core file at /user/local/lib/sbcl//sbcl.core

Process inferior-lisp exited abnormally with code 1

If you use the settings in step 4, you’ll get a different error message:

Searching for program: no such file or directory, sbcl

If you SBCL looks in the environment variable PATH to find the executable and core file. The default directories are *nixy, so it won’t find your sbcl directory on accident. But why should it look for the directory if you entered it into the install wizard?

Apparently Windows XP doesn’t update system environment variables until the system reboots. So right after you install SBCL, you have the user environment variables PATH and SBCL_Home but SBCL looks in the system variables. I couldn’t find out a way to fix that without rebooting, but the good news is that a reboot solves the problem.

So reboot your computer now.

4. Setup SLIME [DIFF: This section has some differences - links and .emacs setup]

Apparently the SLIME 2.0 is very old; several people recommend ignoring it and going straight to the CVS snapshot, so that’s what I linked to above.

Extract the SLIME folder to [HOME]\bin\emacs\site-lisp. (Here’s a tip about putting emacs code in site-lisp).

Now in Emacs, open your .emacs file (C-x C-f, ~/.emacs) and enter the following (general SLIME instructions, SBCL specific setup), changing your pathnames as usual. The good news is that because SBCL looks in the environment variables, you don’t need any of the command line parameters in the inferior-lisp-program variable:

(setq inferior-lisp-program “sbcl”)
(add-to-list ‘load-path “[HOME]/bin/emacs/site-lisp/slime/”)
(require ’slime)
(slime-setup)

Save the .emacs file (C-x C-s), then run the eval-buffer command (M-x eval-buffer). This will run the code that you just entered and tell Emacs how to run SLIME.

Now, you start slime with M-x slime and you’re ready to go!

NOTE: This is a basic SBCL setup - I’ve found some more advanced setup links that I’ll write guides for later:

Additional comments at comp.lang.lisp.

  1. 4 Responses to “Installing SBCL, Emacs, and SLIME on Windows XP”

  2. By Neil Haven on May 30, 2008 | Reply

    Does Emacs have problems parsing the spaces in Windows paths like XEmacs does? If so, this is a fly in the ointment that people should be aware of… See R. Zubek’s post referenced above.

  3. By Peter on May 30, 2008 | Reply

    Neil,
    Not sure about filenames with spaces. I tried a couple things at the minibuffer and there was no problem. I don’t want to change my install directories (because writing these thing is a pain enough) so if anyone wants to experiment with installing SBCL to a filename with spaces, please let me know how it goes!

    Thanks,
    Peter

  4. By eGlyph on May 31, 2008 | Reply

    Note that it’s not really necessary to add SBCL_Home to path.
    There is a weird limit on %PATH% length, so my approach was to create sbcl.cmd with full paths, like:

    d:\usr\local\sbcl\sbcl.exe –core d:\usr\local\sbcl.core

    and to supply this .cmd as inferior-lisp to emacs

  1. 1 Trackback(s)

  2. Jun 3, 2008: Hey Language Snobs: Don’t Pinch Pennies » What’s In Peter’s Head

Post a Comment