Pull up a chair and watch as I install Swank, SLIME and Clojure on a clean Ubuntu. After my last screencast I received several comments, where people really wanted to get started developing with Clojure but did not know how. This post aims to resolve that problem.
This video is Clojure 101: Installing Swank, SLIME and Clojure in Emacs on a fresh Ubuntu. Initially I failed to understand why this was so hard for many people, but after trying to install using ELPA and Emacs22 it became very clear. The automated install fails in about 90% of the cases - After seeing this screencast, you'll know how to resolve that.
(double click for full-screen - if you're not seeing it, try hitting F5 or using Firefox)
Ok, so are you all set with start your own Clojure project? There is still an abundance of tweaks which you can apply to your emacs configuration, here's some of mine:
;;;;;;;;;;;;;;; LOAD PATH AND AUTOLOADS (add-to-list 'load-path "~/.emacs.d/") (add-to-list 'load-path "~/.emacs.d/color-theme") (add-to-list 'load-path "~/.emacs.d/magit/") (add-to-list 'load-path "~/.emacs.d/slime") (add-to-list 'load-path "~/.emacs.d/slime/contrib/") (add-to-list 'load-path "~/coding/clojure-root/clojure-mode/") (require 'egg) (require 'ido) (require 'htmlize) (require 'color-theme) (require 'clojure-mode) (setq swank-clojure-jar-path "~/.swank-clojure/swank-clojure-1.0.jar" swank-clojure-jar-home "~/.swank-clojure/" swank-clojure-classpath (list "~/.swank-clojure/*" "~/coding/lisp/clojure/libs/*")) ;; All my Java jars ;;;;;;;;;;;;;;; GLOBAL SETTINGS (ido-mode t) (setq backup-directory-alist (list (cons ".*" (expand-file-name "~/.emacsbackup/")))) (setq x-select-enable-clipboard t) (color-theme-initialize) (color-theme-sitaramv-nt) ; Loading this first gives me yellow buffer names (color-theme-charcoal-black) (set-default-font "-unknown-Inconsolata-normal-normal-normal-*-12-*-*-*-m-0-iso10646-1") (global-font-lock-mode 1) ;; Enable syntax highlighting when editing code. (setq current-language-environment "UTF-8") (show-paren-mode 1) (tool-bar-mode -1) (setq transient-mark-mode t) (setq visible-bell t) (setq inhibit-startup-screen t) ;;;;;;;;;;;;;;; GLOBAL KEYBOARD-BINDINGS ;;;;;;;;;;;;;;; (can be overridden by other modes) (global-set-key (kbd "C-z") 'set-mark-command) ; I have Tilda on C-spc (global-set-key [C-tab] 'other-window) (global-set-key "\r" 'newline-and-indent) (global-set-key [f2] 'egg-status) (global-set-key [f6] 'slime-load-file) ; Hit this to eval an entire file (global-set-key [s-left] 'enlarge-window-horizontally) ; S = Super/Window (global-set-key [s-right] 'shrink-window-horizontally) ;;;;;;;;;;;;;;; HOOKS (add-hook 'clojure-mode-hook '(lambda () (define-key clojure-mode-map "\C-c\C-e" 'lisp-eval-last-sexp) (define-key clojure-mode-map "\C-x\C-e" 'lisp-eval-last-sexp) (local-set-key (kbd "
") 'slime-eval-defun) (local-set-key (kbd "M-RET") 'dabbrev-expand))) (setq auto-mode-alist (append '(("\.lisp$" . lisp-mode) ("\.lsp$" . lisp-mode) ("\.cl$" . lisp-mode) ("\\.js$" . java-mode) ("SConstruct$" . python-mode) ("\.py$" . python-mode) ("\.asd$" . lisp-mode) ("\.system$" . lisp-mode) ("\\.org$" . org-mode) ("\\.mbox$" . vm-mode) ("\\.muse$" . muse-mode) ("\\.clj$" . clojure-mode)) auto-mode-alist)) (eval-after-load "slime" '(progn (require 'slime-fuzzy) (setq slime-complete-symbol*-fancy t) (setq slime-complete-symbol-function 'slime-fuzzy-complete-symbol) (slime-setup))) ;;;;;; PREPARE WINDOW ; This fits my screen (1680x1024) (when window-system (set-frame-height (selected-frame) 225) (set-frame-width (selected-frame) 230))
As you can see, I had a legacy SLIME installed under ~/.emacs.d/ so that's added to my classpath. In addition I use htmlize for the blog and Egg and Magit for my Git interface. You'll also notice I'm using 'ido' which is a handy helper that keeps track of which files you open, so that if I want to start working on ClojureQL I hit C-x C-f (open file) and type "backend", Ido then auto-completes to "/home/lau/coding/projects/clojureql/src/clojureql/backend.clj" - very handy.
Specific for my Clojure-development is only the definition of Swanks-Classpaths(+ extras). Update: There has been reported problems with the ...extra-classpaths option, so I recommend sticking with swank-clojure-classpath. When I don't start my project with M-x swank-clojure-project these are used instead of the classpath specific to that project and in libs/* I have all of my regular Java jars, which I consider part of my toolbox. Make sure, for your projects that you remember to set them up as a swank-project - hit Phils link at the bottom if you don't know how.
If you're in the unfortunate situation that you bought a PC which has Windows pre-installed don't be further discouraged, all of these commands will run on your PC as well as soon as you have installed Ubuntu, which takes about 20 minutes.
Update: I've just tried following these instructions on OSX/Aquamacs and with the exception of how to get Clojure.jar into the ~/.swank-clojure folder, it all works perfectly well leading me to believe that Windows users will have the same experience.
Allow me to point the way to a few of my regular stops
Did I leave something out, drop me a line.