franz inc logo  
  download techcorner franz inc franz inc store search franz inc          

products
services
support
about
success
resources

RSS Feeds

AllegroServe at opensource.franz.com

Using SLIME with Allegro Common Lisp

What is SLIME?

SLIME stands for the Superior Lisp Interaction Mode for Emacs. It is a development environment for writing Lisp applications that is compatible with most available Lisp implementations. It is favorable for developers writing code to multiple Lisp implementations as it provides a similar development experience regardless of the Lisp being used.

There is a SLIME home page as well as a SLIME CLiki if you want to read more about the interface and the features it provides.

Download SLIME

There are three easy ways in which to download and install SLIME. NOTE: the instructions below assume you are running Lisp and Emacs on the same machine. You should visit the SLIME websites referenced above if you wish to set up a different configuration.

  • Download an archive of the current release [tgz | zip]

    Slime does not have a "current release" link, so the above link will eventually become out of date. Go here for the latest version.

    Tar and gzip can be used on unix (or cygwin) systems to extract the contents of the downloaded archive into a local directory. On windows, winzip (available for free download at http://www.winzip.com) can also be used to extract tar'd and gzip'd files (extensions of .tar, .tar.gz, or .tgz).

    Extract the files to a directory of your choice on the local machine. You'll need to remember this directory for later configuration steps below.

  • CVS

    To checkout from CVS you must first login to the repository.

    (in bash)
    $ export CVSROOT=:pserver:anonymous@common-lisp.net:/project/slime/cvsroot
    (in csh)
    % setenv CVSROOT :pserver:anonymous@common-lisp.net:/project/slime/cvsroot
    
    then,
    
      cvs login 
    
    Enter anonymous when prompted for the password. You can then check out the latest version with: 
    
      cvs checkout slime
    

    This will create a directory containing the most recent version of slime. You'll need to remember this directory for later configuration steps below.

  • asdf-install:

    asdf-install is a great open-source package for downloading and installing Lisp modules from the net. If you aren't familiar with asdf-install, see the asdf-install homepage for help installing the module, as well as special configuration tips for windows vs. unix installs.

    It is very simple to download slime via asdf-install

    ;; load asdf-install if it isn't already.
    
    ;; but first load asdf. fill in the correct path to asdf-install where it says
    ;; "*** fill in path to asdf-install ***"
    (require :asdf)
    (push "*** fill in path to asdf-install ***" asdf:*central-registry*)
    (asdf:operate 'asdf:load-op 'asdf-install)
    
    ;; uncomment this line if you don't have gpg software installed.
    ;; (setq asdf-install::*verify-gpg-signatures* nil)
    
    ;; default location is c:/program files/cygwin/bin/bash.exe
    ;; uncomment this line and fill in correct path if your bash.exe location is different.
    ;;(setq *cygwin-bash-program* "bash.exe")
    
    ;; (asdf-install:install "slime") gets a 404 for me.
    ;; slime does not have a "current release" link, so this will eventually become out of date.
    ;; Go here to find the latest release: http://common-lisp.net/project/slime/
    (asdf-install:install "http://common-lisp.net/project/slime/slime-1.2.1.tar.gz")
    
    Choose the install location when prompted, and the rest should be automatic.
    You'll need to remember where you've installed SLIME for later configuration steps below.
    

Configuring SLIME

SLIME consists of two parts, a body of code which runs within Emacs (SLIME), and the SWANK server which runs in the Lisp. SLIME makes use of the inferior-lisp mode in emacs. On unix-like systems, this poses no problem for use with Allegro CL, but under windows, special configuration is required. This code will make SLIME available whenever you start up emacs. The call to slime-setup includes a number of contrib modules that you may find useful when using slime. slime-fancy actually causes a number of contrib modules to be loaded, and slime-banner makes a nice animation at startup. See the contrib/ subdirectory of your SLIME checkout to see what else is available.

Interfacing to Emacs on Unix

On Unix, add the following to your .emacs file.

The sample code below assumes SLIME is located in /usr/local/slime.

;; update this path to the correct location.
(add-to-list 'load-path "/usr/local/slime")
(require 'slime-autoloads)

(eval-after-load "slime"
  '(progn
    (add-to-list 'load-path "/usr/local/slime/contrib")
    (slime-setup '(slime-fancy slime-banner))
    (setq slime-complete-symbol*-fancy t)
    (setq slime-complete-symbol-function 'slime-fuzzy-complete-symbol)))

;; Optionally, specify the Lisp program you are using. Default is "lisp"
;; If the Allegro directory is not in your PATH environment variable
;; this should be a fully qualified path.
;; choose one of the below based on Express or non-Express usage
;; (setq inferior-lisp-program "alisp") 
(setq inferior-lisp-program "allegro-express") 

Interfacing to Emacs on Windows

Inferior-lisp mode on Windows expects a win32 console application, which Allegro is not. There is build.exe and buildi.exe, but these are not recommended for development use. As such, it is necessary to construct a different way of starting Lisp and instructing the SWANK server on which port to listen.

The sample code below assumes slime is installed in c:/cygwin/usr/local/slime.

First, we create a file that Lisp will load at startup. It will contain code to start the swank server at a port that will be specified by a command-line argument "-p". A good place to save this file is in your home directory.

For purposes of this example, we'll assume the segment below is saved to "c:/.slime.lisp"

(eval-when (:compile-toplevel :load-toplevel :execute)
  (require :asdf))

(push "c:/cygwin/usr/local/slime/" asdf:*central-registry*)

(asdf:oos 'asdf:load-op :swank)
(swank-loader::init)

(sys:with-command-line-arguments (("p" :short port :required)
				  ("ef" :long ef :required))
  (restvar)
  (swank::create-server :port (parse-integer port :junk-allowed nil)
		        :style :spawn
	                :dont-close t
			:coding-system (or ef "latin-1")))

Add to your .emacs file:

The code below defines the variables *slime-lisp* and *slime-port* which allows you to specify which Lisp to use and what port the swank server should listen on. They are easily changed, say, if you need to switch between mlisp and alisp, for example.

It refers to a file that can be put anywhere. For this example it is assumed to be saved to "c:/.slime.lisp"

(push "c:/cygwin/usr/local/slime/" load-path)
(require 'slime-autoloads)
(require 'slime)

(slime-setup '(slime-fancy slime-banner))
(global-set-key "\C-cs" 'slime-selector)
(setq slime-complete-symbol*-fancy t)
(setq slime-complete-symbol-function 'slime-fuzzy-complete-symbol)

(setq slime-multiprocessing t)
;; choose one of the below based on Express or non-Express usage
;; (setq *slime-lisp* "alisp.exe")
(setq *slime-lisp* "allegro-express.exe")
(setq *slime-port* 4006)

(defun slime ()
  (print "this is my slime")
  (interactive)
  (shell-command 
   (format "%s +B +cm -L c:/cygwin/home/patchmgr/.slime.lisp -- -p %s --ef %s &"
	   *slime-lisp* *slime-port*
	   slime-net-coding-system))
  (delete-other-windows)
  (while (not (ignore-errors (slime-connect "localhost" *slime-port*)))
    (sleep-for 0.2)))

The code above actually redefines the default command for starting slime. The prevalant method used by the various solutions found on the net define a new keybinding to start Lisp on windows. The example below binds F5 to the function used to start SLIME.

(global-set-key
 [(f5)]
 '(lambda ()
    (interactive)
    (shell-command 
     (format "%s +B +cm -L c:/cygwin/home/patchmgr/.slime.lisp -- -p %s --ef %s &"
	     *slime-lisp* *slime-port*
	     slime-net-coding-system))
    (delete-other-windows)
    (while (not (ignore-errors (slime-connect "localhost" *slime-port*)))
      (sleep-for 0.2))))

Use this instead if you don't want to redefine the default slime command.

Running SLIME

If your .emacs has been modified with the above code, then you are ready to go. Simply start emacs and SLIME is ready to be used. Make sure *slime-lisp* is bound to the Lisp you wish to use, and *slime-port* is set to the port you want to use, then simply enter 'M-x slime' (or other keybinding, such as F5) within emacs and you should be connected to Lisp.

For instructions on using SLIME, we recommend visiting the SLIME homepage as well as the SLIME CLiki. There are many great links on each.

Support

As we stated above, SLIME is not a product of Franz Inc. If you have problems you feel are specific only to Allegro CL, then feel free to contact us, otherwise you should contact the authors of SLIME.

[WinZip problems] If trouble is encountered directly opening tarballs using winzip, try saving the tarball to disk first, then opening the saved file using winzip.

[General] While this page makes reference to asdf, asdf-install, and slime, note that these are not Franz Products. Any problems installing or using these pieces of software should be directed to the appropriate community. Allegro specific errors related to these packages can be addressed via these entities.

 

© 2008 Franz Inc - Privacy Statement
[ Consulting Services | Packages/Pricing | Allegro NFS | Certification Program ]