Up and running with Emacs, sbcl, and SLIME
August 14, 2008
While I normally program in Python, a part of me wants to quickly hack some lisp code every now and then. Especially during those long minutes when my automated tests are running.
I realized that long neglect had left me without a working lisp setup. Here is how I got it up and running again.
Step 1: Get rid of system lisp and slime
The version of sbcl and SLIME in my Ubuntu system is not recent enough for my liking. So I get rid of them:
$ sudo apt-get -y remove sbcl slime common-lisp-controller $ sudo apt-get -y autoremove # get rid of packages we don't need anymore $ sudo rm -rf /var/cache/common-lisp-controller
Step 2: Install common requirements
cd ~/ sudo apt-get update sudo apt-get -y install emacs22 sudo apt-get -y install cvs sudo apt-get -y install git-core sudo apt-get -y install darcs sudo apt-get -y install subversion sudo apt-get -y install build-essential sudo apt-get -y install autoconf sudo apt-get -y install curl sudo apt-get -y install sbcl sudo apt-get -y install texinfo sudo apt-get -y install tetex-bin sudo apt-get -y install xloadimage
Step 3: Get clbuild
$ mkdir lisp $ cd lisp # for fresh install of clbuild $ darcs get http://common-lisp.net/project/clbuild/clbuild $ cd clbuild # Or, to update existing clbuild $ cd clbuild $ darcs pull
Step 4: Get latest SBCL
$ ./clbuild update sbcl $ cd source/sbcl $ sh make.sh $ cd doc/manual $ make $ cd ../.. $ echo > ~/.sbclrc (require :asdf) (push "/home/parijat/lisp/clbuild/systems/" asdf:*central-registry*) ^D $
Step 5: Setup SLIME
$ ./clbuild update slime
Now, we need to add this slime configuration to our .emacs file:
(push "/home/parijat/lisp/clbuild/source/slime" load-path)
;; Common Lisp Mode
(setq inferior-lisp-program "/usr/local/bin/sbcl")
(add-to-list 'auto-mode-alist '("\\.lisp$" . lisp-mode))
(add-to-list 'auto-mode-alist '("\\.cl$" . lisp-mode))
(add-to-list 'auto-mode-alist '("\\.asd$" . lisp-mode))
(require 'slime)
(slime-setup)
(eval-after-load "slime"
'(progn
(setq slime-complete-symbol*-fancy t
slime-complete-symbol-function 'slime-fuzzy-complete-symbol
slime-when-complete-filename-expand t
slime-truncate-lines nil
slime-autodoc-use-multiline-p t)
(slime-setup '(slime-fancy slime-asdf))
(define-key slime-repl-mode-map (kbd "C-c ;")
'slime-insert-balanced-comments)
(define-key slime-repl-mode-map (kbd "C-c M-;")
'slime-remove-balanced-comments)
(define-key slime-mode-map (kbd "C-c ;")
'slime-insert-balanced-comments)
(define-key slime-mode-map (kbd "C-c M-;")
'slime-remove-balanced-comments)
(define-key slime-mode-map (kbd "RET") 'newline-and-indent)
(define-key slime-mode-map (kbd "C-j") 'newline)))
(add-hook 'lisp-mode-hook (lambda ()
(cond ((not (featurep 'slime))
(require 'slime)
(normal-mode)))
(indent-tabs-mode nil)
(pair-mode t)))
Note: pair-mode is a nice package for inserting balanced parentheses, quotes, braces and square-brackets, etc., which I installed earlier by hand.
Now we can launch emacs, and start slime with “M-x slime”.
Caveat
For some reason, after doing the above, slime would still not start. Doing a “M-x slime” would throw me into the sbcl debugger with the error message that sbcl could not find “/usr/share/common-lisp/systems/slime/swank-loader.lisp”, or something like that (I could be wrong about the exact path). After much head-scratching (and grepping my ~/lisp directory), I figured out I had to change the emacs customization variable slime-backend. This can be done by doing “M-x customize-group RET slime-lisp RET” and changing the value of “Slime Backend” to simply “swank-loader.lisp” (the file should be in the same directory as “slime.el”). We can also give an absolute path to the file. I found that the value of this variable was set wrongly (an artifact of using apt-get installed slime, I guess) and hence sbcl was not able to load the correct file.
November 14, 2008 at 4:56 pm
Useful, thanks. I’ve recently decided to move closer to the head, so to speak and was looking for this info.
By-the-way, your step 1 removes sbcl but step 2 adds it back again. Therefore you don’t really need to do step 1!! It turns out that you can’t build SBCL without already having a lisp installed so perhaps step 1 should be step 6?
November 18, 2008 at 6:11 pm
I get the following when i run sh make.sh…
//building cross-compiler, and doing first genesis
make-host-1.sh: 31: sbcl: not found
Command exited with non-zero status 1
November 18, 2008 at 7:07 pm
For some reason SBCL dit not install with apt-get -y install…it downloaded the packages but the actual install seemed not to have happened..i re ran apt-get install sbcl and it just unpacked and installed ok. Then I used “clbuild compile-implementation sbcl” instead of make. According to the guys at lisp.irc its the better way.
Thought I would just share it with you.
January 5, 2009 at 5:49 am
[...] public links >> texinfo Up and running with Emacs, sbcl, and SLIME Saved by olaparent on Sun 21-12-2008 New GNU stuff April 2008 Saved by jorgejiro on Sat [...]
March 16, 2009 at 2:40 pm
Thanks for this! I had the exact same problem with an incorrect path to swank-loader.lisp in emacs… After much head-scratching and googling, you saved the day.