Skip to content

Instantly share code, notes, and snippets.

@mpcjanssen
Forked from tshatrov/lisp-setup.md
Last active August 8, 2023 12:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpcjanssen/5c614fe79bf54662406b to your computer and use it in GitHub Desktop.
Save mpcjanssen/5c614fe79bf54662406b to your computer and use it in GitHub Desktop.
Setting up Common Lisp on Windows 7

1. Install a Common Lisp implementation, or several of them

2. Install Emacs. Official GNU Emacs Windows binaries should work: http://ftp.gnu.org/gnu/emacs/windows/

3. Create a directory where you will store your Lisp projects (you could use Quicklisp's default one but screw that, "c:/lisp" is better than "c:/users/<username>/quicklisp/local-projects")

4. Download Quicklisp from http://beta.quicklisp.org/quicklisp.lisp and put it into your Lisp directory.

5. Start up your Lisp and do (load "c:/lisp/quicklisp.lisp") . Follow the instructions to install Quicklisp and add it to your Lisp's init file...

(quicklisp-quickstart:install)
(ql:add-to-init-file)

6. While we're at it, install SLIME from quicklisp.

(ql:quickload "quicklisp-slime-helper")

7. Open Emacs and do C-x C-f (Ctrl-x, followed by Ctrl-f) and type "~/.emacs" in the minibuffer. This should open your Emacs file. By default it resides in "c:/users/<username>/AppData/Roaming/", this being Emacs's HOME directory.

(add-to-list 'exec-path "C:/sbcl") ;; or wherever you installed SBCL or other Lisp
(load (expand-file-name "~/quicklisp/slime-helper.el"))
(setq inferior-lisp-program "sbcl") ;; or other Lisp
(slime-setup '(slime-fancy slime-asdf)) ;; and possibly other SLIME extensions
(add-hook 'slime-mode-hook
          '(lambda ()
            (set-variable lisp-indent-function 'common-lisp-indent-function)
            (define-key slime-mode-map [tab] 'slime-indent-and-complete-symbol)
            (define-key slime-mode-map (kbd "C-<tab>") 'slime-complete-symbol)))

Type C-x C-s to save file.

8. I already mentioned that Emacs's home dir is "c:/users/<username>/AppData/Roaming/" whereas Quicklisp infrastructure assumes "c:/users/<username>/" is the home dir. This is probably configurable on Quicklisp side, and definitely configurable on Emacs side (setting environment variable HOME to "c:/users/<username>/" might solve this issue), but I found that the easiest way to resolve this is to add a symlink for quicklisp's directory. Start Windows command line (Win-R then "cmd"), and do the following:

cd AppData\Roaming
mklink /J quicklisp ..\..\quicklisp

9. Find your Lisp's init file! It should be in "c:/users/<username>/". For SBCL it's .sbclrc, for CLISP it's .clisprc and so on. When you start Lisp from within Emacs, it would try to load it from Emacs home folder, so copy it there. It might in fact be useful to have two different startup files for "bare" Lisp and SLIME shell Lisp.

10. OK, now restart your Emacs and press M-x slime (Alt-x, then type "slime" in minibuffer and press Enter). If you set up everything correctly this should start up your Lisp and load Quicklisp too. Try doing something like

(ql:quickload "cl-ppcre")

11. The only thing left is to configure ASDF so that it could recursively load your own projects from "c:/lisp" or whatever directory you created earlier. Open file "~/.config/common-lisp/source-registry.conf.d/asdf.conf" in Emacs and put the following into it:

(:tree "c:/lisp/")

12. Stuff to do:

(ql:quickload :quickproject)
(quickproject:make-project "c:/lisp/my-test-project/" :name "my-test-project" :depends-on '(:cl-ppcre))

Define some functions in c:/lisp/my-test-project/my-test-project.lisp , you should be able to do (ql:quickload :my-test-project) to load it and its dependencies. You should also be able to do (asdf:load-system :my-test-project) or ",l <Enter> my-test-project <Enter>" in SLIME.

13. Optional things:

CL+SSL/DRAKMA won't install OMGWTFBBQ

If you have 64-bit Windows, you need 64-bit OpenSSL .dll for this to work. Install "Win64 OpenSSL v1.0.1e" and "Visual C++ 2008 Redistributables (x64)" from http://slproweb.com/products/Win32OpenSSL.html and copy libssl32.dll to c:\Windows\System32

Upgrade your ASDF to ASDF 3

If (member :asdf3 *features*) is nil, then you're probably not as bleeding edge as you think! Quicklisp only comes with ASDF2 and so does the Windows threaded fork of SBCL which I mentioned in the beginning. ASDF3, among other things, contains a rather useful library UIOP, which you might want to use if you ever deal with filesystems/pathnames/OS portability/inter-Lisp portability and so on. It also can make executable files out of your ASDF systems.

Anyway, the recommended way to upgrade listed in ASDF documentation doesn't seem to work ( (asdf:load-system "asdf) doesn't load new version of ASDF if you already got an old one), so the sure way to make sure you have ASDF3 is to put new asdf.lisp somewhere and add

#-asdf3
  (load "c:/lisp/asdf") ;; or wherever you put it

to .sbclrc

Configure SLIME for several Lisp implementations

(todo)

@sami2020pro
Copy link

Thank u 🆒

@lockie
Copy link

lockie commented Aug 8, 2023

One also might be interested in ready-made, regularly updated Windows7-compatible SBCL installers (full disclosure: I'm the owner of that repository).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment