SLIME Tips
This page is for collecting tips for avoiding problems with and making the best use of SLIME, the Emacs-based Lisp development environment

  • Connecting automatically: Making slime connect to your lisp automatically when you open a lisp file.

(defun cliki:start-slime ()
  (unless (slime-connected-p)
    (save-excursion (slime))))

(add-hook 'slime-mode-hook 'cliki:start-slime)

  • Multiple sessions: By using
  • C-u M-x slime you are given the option of starting additional Lisp processes and connecting to them, resulting in multiple REPL buffers. The lisp-mode buffers will use the most recently opened connection, unless you cycle to another with M-x slime-cycle-connection

  • CLISP: When using SLIME with CLISP, be sure to invoke the Lisp process (using
  • C-u M-x slime) as "clisp -K full" to include the full linking set. The default base linking set does not include the REGEXP module, upon which SLIME depends. Failure to use a linking set including the REGEXP module causes SLIME to complain about the missing REGEXP package.
    Alternatively, you can set inferior-lisp-program in your .emacs file to the correct executable and args:
    (setq inferior-lisp-program "clisp -K full")
    
  • FAIRLY-STABLE: Sometimes the current version of SLIME in CVS is broken. If your copy doesn't work, it's recommended that you update to the
  • FAIRLY-STABLE CVS tag. The CVS incantation is:
    cvs update -r FAIRLY-STABLE .
    
    Generally speaking the FAIRLY-STABLE tag is set immediately before some dangerous changes are being made. Thus during periods of general stability it may be quite out-of-date and less featureful than the current version.

  • Possible XEmacs error: If the current CVS version (true as of 31-Oct-2008) fails to compile on XEmacs with an error referring to arc-mode, do this:

    Edit slime.el to change:

  • (eval-when (compile)
      ...
      (require 'arc-mode)
    

    to

    (eval-when (compile)
      ...
      (autoload 'archive-extract "arc-mode" nil t)
    

    This is because arc-mode.el does not provide 'arc-mode, but 'archive-mode.

  • Cygwin: . Starting an inferior lisp in Windows NT Emacs and using Cygwin (e.g., starting the CLisp that comes with Cygwin) may produce errors of this sort:
  • ...A file with name /c/cygwin/usr/share/emacs/site-lisp/slime/swank-loader does not exist...
    
    One easy fix is to mount the Windows volume under the Cygwin root:
    mkdir /c
    touch /c/NOT_MOUNTED
    mount C:\\ /c
    

  • Indentation: If your emacs indents Common Lisp code in Emacs Lisp style (i.e. "if" has the then-form and else-form in different columns), add something like this to your ~/.emacs:

  • (add-hook 'lisp-mode-hook
              (defun my-lisp-mode-hook ()
                (set (make-local-variable 'lisp-indent-function)
                     'common-lisp-indent-function)))
    

    Alternatively, try adding the following in your ~/.emacs:

    (slime-setup)
    

  • Styled SLDB: If you're feeling artistic you can use
  • `M-x customize-group slime-debugger' to make the debugger pretty.

  • CL-SDL: If you are experiencing nasty freezes and errors with CL-SDL OpenGL programs and Nvidia proprietary binary linux opengl drivers with SLIME on CMUCL, place (defparameter swank:*communication-style* :spawn) in ~/.swank.lisp to switch away from the :SIGIO SWANK communication method to avoid hairy signal handling problems.

  • Unicode: If pain results when you try entering nice Unicode symbols, try something like the following your .emacs:

  • (set-language-environment "UTF-8")
    (setq slime-net-coding-system 'utf-8-unix)
    

    (This is taken from a blog entry, where he goes on to say: A Unicode aware Lisp implementation such as Clisp or SBCL and Emacs version 21.4 or greater. I won't go into setting those up here, but in Gentoo you'll need to be sure SBCL is emerged with the "unicode" USE flag, and Emacs with the "leim" use flag and some tweaking to the ebuild.)

  • Restoring clobbered user keybindings: In its default configuration, slime clobbers the keybinding C-c x which is supposed to be reserved for the user according to official guidelines. You can workaround this, by adding the following snippet to your .emacs file:
  • (defun slime-sanitize-bindings ()
      "Removes SLIME's keybinding on C-c x"
      (cond ((boundp 'slime-mode-map)
             (define-key slime-mode-map (kbd "C-c x") nil)
             (message "slime keybinding C-c x has been sanitized"))
            ('t (message "slime keybindings not sanitized"))))
    (add-hook 'slime-mode-hook 'slime-sanitize-bindings)
    

  • Tramp connection to another computer: You can use tramp to edit lisp files on a remote server. When you tell slime to compile-and-load or go to definition slime will automatically translate the filename between the workstation and the lisp server. This is setup with the slime-create-filename-translator function. For an example of all you can do with this, see http://paste.lisp.org/display/17592

  • Can anyone say whether it's possible to use SLIME in conjunction with attachtty? In particular, I'm wanting to connect to a Linux box running CMUCL/detachtty from my Mac running OS X. attachtty from the command line works fine, but that's not terribly useful. :-) Trying to use SLIME just specifying
    inferior-lisp-mode
    as the attachtty command line results in numerous errors which appear to be from SLIME trying to load its files (locally in /Users/me/whatever) on the Linux box (obviously they aren't there).

    Actually, you don't even need detachtty. But still I prefer to use it, so that I can attach back to it if something breaks even the swank server (e.g. entering the debugger). You have to add something like the following to your application:

    (swank:create-server)
    
    Then you can use SLIME's slime-connect command.

    • Workaround for
    M-x slime bug in Lisp in a Box for Windows running Allegro CL 6.2 Trial: Warning: Lisp newbie workaround! But it works. Advice welcome. Add this to the end of the 99init.el file located directly under the LispBox directory.

    Alternatively, setting inferior-lisp-program, such as (defvar inferior-lisp-program "lisp") with the correct executable and args instead of just "lisp", in this file would probably also fix the problem.

    ;; The following are a few workarounds for the following bug in
    ;; the Windows version of Lisp in a Box running the trial version
    ;; of Allegro CL 6.2.
    ;; Bug: "M-x slime" doesn't work in Emacs. Produces the error:
    ;;  "Searching for program: no such file or directory, lisp"
    
    ;; Set function key for re-starting Slime.
    ;; (lispbox-start-allegro-trial-6.2) defined in 50allegrotrial62.el.
    (global-set-key
     [(f5)]
     '(lambda ()
       (interactive)
       (lispbox-start-allegro-trial-6.2)))
    
    ;; Likewise, this one-liner also starts Slime w/ Allegro CL, assuming
    ;; Allegro's all you've got set up to work w/ Slime.
    ;; lispbox-pick-lisp defined in 00base.el.
    ;; (global-set-key [(f5)] 'lispbox-pick-lisp)
    
    ;; Workaround for "M-x slime". Replaces slime function in slime\slime.el.
    ;; 'allegro-trial-6.2 set in 50allegrotrial62.el.
    (defun slime ()
      (interactive)
      (lispbox-pick-lisp 'allegro-trial-6.2))
    

    Patch for using the asdf output path for all your fasls.

    Index: swank-allegro.lisp
    ===================================================================
    RCS file: /project/slime/cvsroot/slime/swank-allegro.lisp,v
    retrieving revision 1.119
    diff -u -p -r1.119 swank-allegro.lisp
    --- swank-allegro.lisp	21 Oct 2008 20:38:05 -0000	1.119
    +++ swank-allegro.lisp	5 Jan 2009 04:39:08 -0000
    @@ -290,6 +290,7 @@
         (let ((*buffer-name* nil)
               (*compile-filename* filename))
           (compile-file *compile-filename* :load-after-compile load-p
    +                    :output-file (swank::swank-compile-output-file filename)
                         :external-format external-format))))
     
     (defun call-with-temp-file (fn)
    Index: swank-clisp.lisp
    ===================================================================
    RCS file: /project/slime/cvsroot/slime/swank-clisp.lisp,v
    retrieving revision 1.84
    diff -u -p -r1.84 swank-clisp.lisp
    --- swank-clisp.lisp	19 Oct 2008 20:03:34 -0000	1.84
    +++ swank-clisp.lisp	5 Jan 2009 04:39:08 -0000
    @@ -628,7 +628,7 @@ Execute BODY with NAME's function slot s
       (with-compilation-hooks ()
         (with-compilation-unit ()
           (multiple-value-bind (fasl-file warningsp failurep)
    -          (compile-file filename :external-format external-format)
    +          (compile-file filename :output-file (swank::swank-compile-output-file filename) :external-format external-format)
             (values fasl-file warningsp
                     (or failurep 
                         (and load-p 
    Index: swank-lispworks.lisp
    ===================================================================
    RCS file: /project/slime/cvsroot/slime/swank-lispworks.lisp,v
    retrieving revision 1.123
    diff -u -p -r1.123 swank-lispworks.lisp
    --- swank-lispworks.lisp	31 Oct 2008 14:13:19 -0000	1.123
    +++ swank-lispworks.lisp	5 Jan 2009 04:39:08 -0000
    @@ -421,6 +421,7 @@ Return NIL if the symbol is unbound."
     (defimplementation swank-compile-file (filename load-p external-format)
       (with-swank-compilation-unit (filename)
         (compile-file filename :load load-p 
    +                  :output-file (swank::swank-compile-output-file filename)
                       :external-format external-format)))
     
     (defvar *within-call-with-compilation-hooks* nil
    Index: swank-openmcl.lisp
    ===================================================================
    RCS file: /project/slime/cvsroot/slime/swank-openmcl.lisp,v
    retrieving revision 1.144
    diff -u -p -r1.144 swank-openmcl.lisp
    --- swank-openmcl.lisp	19 Oct 2008 20:03:34 -0000	1.144
    +++ swank-openmcl.lisp	5 Jan 2009 04:39:08 -0000
    @@ -266,7 +266,8 @@ condition."
       (with-compilation-hooks ()
         (let ((*buffer-name* nil)
               (*buffer-offset* nil))
    -      (compile-file filename :load load-p))))
    +      (compile-file filename :load load-p
    +                  :output-file (swank-compile-output-file filename)))))
     
     (defimplementation frame-var-value (frame var)
       (block frame-var-value
    Index: swank-sbcl.lisp
    ===================================================================
    RCS file: /project/slime/cvsroot/slime/swank-sbcl.lisp,v
    retrieving revision 1.227
    diff -u -p -r1.227 swank-sbcl.lisp
    --- swank-sbcl.lisp	30 Oct 2008 09:28:51 -0000	1.227
    +++ swank-sbcl.lisp	5 Jan 2009 04:39:09 -0000
    @@ -478,7 +478,7 @@ compiler state."
       (handler-case
           (multiple-value-bind (output-file warnings-p failure-p)
               (with-compilation-hooks ()
    -            (compile-file pathname :external-format external-format))
    +            (compile-file pathname :output-file (swank::swank-compile-output-file pathname)  :external-format external-format))
             (values output-file warnings-p
                     (or failure-p
                         (when load-p
    Index: swank.lisp
    ===================================================================
    RCS file: /project/slime/cvsroot/slime/swank.lisp,v
    retrieving revision 1.610
    diff -u -p -r1.610 swank.lisp
    --- swank.lisp	22 Nov 2008 15:14:51 -0000	1.610
    +++ swank.lisp	5 Jan 2009 04:39:09 -0000
    @@ -3474,4 +3474,10 @@ Collisions are caused because package in
     (defun init ()
       (run-hook *after-init-hook*))
     
    +(defun swank-compile-output-file (pathname)
    +  (values-list (asdf:output-files (make-instance 'asdf:compile-op) 
    +                            (make-instance 'asdf:cl-source-file :name (pathname-name pathname)
    +                                           :parent (make-instance 'asdf:module :pathname nil :name "")
    +                                           :pathname nil))))
    +
     ;;; swank.lisp ends here
    \ No newline at end of file
    cvs diff: Diffing contrib
    cvs diff: Diffing doc
    fremlin@wheeler:~/.emacs.d/packages/slime$ cvs diff -u -p
    cvs diff: Diffing .
    Index: swank-allegro.lisp
    ===================================================================
    RCS file: /project/slime/cvsroot/slime/swank-allegro.lisp,v
    retrieving revision 1.119
    diff -u -p -r1.119 swank-allegro.lisp
    --- swank-allegro.lisp	21 Oct 2008 20:38:05 -0000	1.119
    +++ swank-allegro.lisp	5 Jan 2009 04:39:31 -0000
    @@ -290,6 +290,7 @@
         (let ((*buffer-name* nil)
               (*compile-filename* filename))
           (compile-file *compile-filename* :load-after-compile load-p
    +                    :output-file (swank-compile-output-file filename)
                         :external-format external-format))))
     
     (defun call-with-temp-file (fn)
    Index: swank-backend.lisp
    ===================================================================
    RCS file: /project/slime/cvsroot/slime/swank-backend.lisp,v
    retrieving revision 1.163
    diff -u -p -r1.163 swank-backend.lisp
    --- swank-backend.lisp	2 Nov 2008 12:05:13 -0000	1.163
    +++ swank-backend.lisp	5 Jan 2009 04:39:31 -0000
    @@ -1163,5 +1163,10 @@ SPEC can be:
       "Save a heap image to the file FILENAME.
     RESTART-FUNCTION, if non-nil, should be called when the image is loaded.")
     
    +(defun swank-compile-output-file (pathname)
    +  (values-list (asdf:output-files (make-instance 'asdf:compile-op) 
    +                            (make-instance 'asdf:cl-source-file :name (pathname-name pathname)
    +                                           :parent (make-instance 'asdf:module :pathname nil :name "")
    +                                           :pathname nil))))
     
       
    \ No newline at end of file
    Index: swank-clisp.lisp
    ===================================================================
    RCS file: /project/slime/cvsroot/slime/swank-clisp.lisp,v
    retrieving revision 1.84
    diff -u -p -r1.84 swank-clisp.lisp
    --- swank-clisp.lisp	19 Oct 2008 20:03:34 -0000	1.84
    +++ swank-clisp.lisp	5 Jan 2009 04:39:31 -0000
    @@ -628,7 +628,7 @@ Execute BODY with NAME's function slot s
       (with-compilation-hooks ()
         (with-compilation-unit ()
           (multiple-value-bind (fasl-file warningsp failurep)
    -          (compile-file filename :external-format external-format)
    +          (compile-file filename :output-file (swank-compile-output-file filename) :external-format external-format)
             (values fasl-file warningsp
                     (or failurep 
                         (and load-p 
    Index: swank-lispworks.lisp
    ===================================================================
    RCS file: /project/slime/cvsroot/slime/swank-lispworks.lisp,v
    retrieving revision 1.123
    diff -u -p -r1.123 swank-lispworks.lisp
    --- swank-lispworks.lisp	31 Oct 2008 14:13:19 -0000	1.123
    +++ swank-lispworks.lisp	5 Jan 2009 04:39:31 -0000
    @@ -421,6 +421,7 @@ Return NIL if the symbol is unbound."
     (defimplementation swank-compile-file (filename load-p external-format)
       (with-swank-compilation-unit (filename)
         (compile-file filename :load load-p 
    +                  :output-file (swank-compile-output-file filename)
                       :external-format external-format)))
     
     (defvar *within-call-with-compilation-hooks* nil
    Index: swank-openmcl.lisp
    ===================================================================
    RCS file: /project/slime/cvsroot/slime/swank-openmcl.lisp,v
    retrieving revision 1.144
    diff -u -p -r1.144 swank-openmcl.lisp
    --- swank-openmcl.lisp	19 Oct 2008 20:03:34 -0000	1.144
    +++ swank-openmcl.lisp	5 Jan 2009 04:39:31 -0000
    @@ -266,7 +266,8 @@ condition."
       (with-compilation-hooks ()
         (let ((*buffer-name* nil)
               (*buffer-offset* nil))
    -      (compile-file filename :load load-p))))
    +      (compile-file filename :load load-p
    +                  :output-file (swank-compile-output-file filename)))))
     
     (defimplementation frame-var-value (frame var)
       (block frame-var-value
    Index: swank-sbcl.lisp
    ===================================================================
    RCS file: /project/slime/cvsroot/slime/swank-sbcl.lisp,v
    retrieving revision 1.227
    diff -u -p -r1.227 swank-sbcl.lisp
    --- swank-sbcl.lisp	30 Oct 2008 09:28:51 -0000	1.227
    +++ swank-sbcl.lisp	5 Jan 2009 04:39:32 -0000
    @@ -478,7 +478,7 @@ compiler state."
       (handler-case
           (multiple-value-bind (output-file warnings-p failure-p)
               (with-compilation-hooks ()
    -            (compile-file pathname :external-format external-format))
    +            (compile-file pathname :output-file (swank-compile-output-file pathname)  :external-format external-format))
             (values output-file warnings-p
                     (or failure-p
                         (when load-p