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. 12 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

  5. By shiri on Aug 25, 2008 | Reply

    Very, very useful… Saved a lot of time for me. Thx.

  6. By Elliott Slaughter on Sep 14, 2008 | Reply

    I have SBCL installed to the “C:\Program Files\Steel Bank Common Lisp\1.0.13\” folder, and haven’t had any problems with either SBCL or Emacs. Your mileage may vary.

  7. By Elliott Slaughter on Sep 14, 2008 | Reply

    Do you have any plans on adding instructions for ASDF configuration? Next to installing a CL and Emacs/Slime, this was probably the next hardest part when I was starting to learn CL.

    My personal advice would be to add

    (require ‘asdf)

    ;; Add any directories in asdf to the registry
    (dolist (dir (directory “/path/to/asdf-central-repository/*/”))
    (pushnew dir asdf:*central-registry* :test #’equal))

    to your .sbclrc, which should be placed in the directory specified by (user-homedir-pathname). That way, you can just extract (or darcs get) a library into that folder and not have to worry about adding links to the .asd files (which may not work on Windows anyways).

    There is also an alternative function at http://www.cliki.net/asdf under “Alternative Sysdef Search functionality” in case the wildcard in the argument to directory doesn’t have the desired effect (e.g. Allegro).

  8. By Elliott Slaughter on Sep 14, 2008 | Reply

    Also, your SLIME configuration works, but there are some new features in CVS which you haven’t used (see http://bc.tech.coop/blog/070927.html). For example, instead of

    (setq inferior-lisp-program “sbcl”)

    you could use

    (setq slime-lisp-implementations
    `((clisp (“clisp” “-K” “full”))
    (sbcl (“sbcl”))))

    which (assuming you have both CLISP and SBCL installed and in your PATH) runs CLISP by default when you type “M-x slime”, but also allows you to type “M-1-x slime sbcl” to run SBCL.

    Furthermore, you could define two functions

    (defun clisp ()
    (interactive)
    (slime ‘clisp))

    (defun sbcl ()
    (interactive)
    (slime ’sbcl))

    which would allow you to type “M-x clisp” and “M-x sbcl” to start CLISP and SBCL, respectively.

    And if you decided that you just didn’t like typing at all, you could

    (global-set-key [f5] ‘clisp)
    (global-set-key [f6] ’sbcl)

    so that just pressing “f5″ or “f6″ would start CLISP or SBCL.

    Enjoy :-)

  9. By Elliott Slaughter on Sep 14, 2008 | Reply

    Oh, and one more thing that you might want to try is Paredit (http://mumble.net/~campbell/emacs/paredit.el),which makes typing all those parens a LOT easier.

    Just download the file, and drop it in your /path/to/emacs/lisp/ directory. Then add the following to your .emacs

    (autoload ‘paredit-mode “paredit”
    “Minor mode for pseudo-structurally editing Lisp code.”
    t)
    (add-hook ‘lisp-mode-hook (lambda () (paredit-mode +1)))

    Then when you open a lisp file and type “(” you should get a “)” with no extra typing.

    See http://mumble.net/~campbell/emacs/paredit.html for a complete list of Paredit commands.

    Enjoy :-)

  10. By Nelson on Oct 3, 2008 | Reply

    Following the instructions, I am unable to get SBCL to run. When launching slime I get the following start up error:

    (progn (load “d:/home/bin/emacs/site-lisp/slime/swank-loader.lisp” :verbose t) (funcall (read-from-string “swank-loader:init”)) (funcall (read-from-string “swank:start-server”) “d:/DOCUME~1/e127778/LOCALS~1/Temp/slime.3684″ :coding-system “iso-latin-1-unix”))

    VirtualAlloc: 0×1e7.
    ensure_space: failed to validate 536870912 bytes at 0×09000000
    (hint: Try “ulimit -a”; maybe you should increase memory limits.)

    Process inferior-lisp exited abnormally with code 1

  11. By tonio2 on Oct 27, 2008 | Reply

    Thanks, a great useful site !

  12. By __Mario__ on Oct 27, 2008 | Reply

    Edit src/compiler/x86/parms.lisp, find the section for your OS and change one of the lines to read:

    (def!constant dynamic-space-end #x10000000)

    Hope that helps !

    – Mario

  1. 1 Trackback(s)

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

Post a Comment