31

I've tried to migrate to Emacs several times for Clojure development, following a variety of blogposts, screencast and tutorials, but somewhere along the way something always went wrong - keybindings that didn't work, incompatible versions, etc, and I found myself scrambling back to Vim. But I know I want Paredit and SLIME.

So, I'm going to try again, this time backed by the powerful Stack Overflow™ community.

I hope that the answer to this question will remain up-to-date, and can serve as a reference for tentative converts like me.

What I'd like is:

  • The latest stable release of Clojure
  • Aquamacs (if it's good enough for Rich Hickey, it's good enough for me), a recent version
  • Clojure Mode
  • SLIME/SWANK
  • Paredit
  • Anything else that's indispensible?

Step-by-step instructions to install the above would be excellent - preferably in shell script format. I'd also like some hints on how to get started with the most common Clojure-related actions (including key-bindings), including links to documentation and cheatsheets.

Boann
  • 48,794
  • 16
  • 117
  • 146
Michiel de Mare
  • 41,982
  • 29
  • 103
  • 134
  • My first steps: downloaded and installed Aquamacs 1.9. git clone git://github.com/jochu/clojure-mode.git Made .emacs file in homedir with contents: (add-to-list 'load-path "~/git/clojure-mode") Launched Aquamacs, did m-x clojure-install, which proceeded to install clojure, clojure-contrib, but gave an error during the installation of Swank. (require 'clojure-mode) – Michiel de Mare Jan 22 '10 at 22:12
  • Apparently that was the wrong version of clojure-mode. I tried git://github.com/technomancy/clojure-mode.git instead. Did m-x clojure-install, which said that this function was deprecated in favor of swank-clojure. No idea how to install that. – Michiel de Mare Jan 22 '10 at 22:24
  • So paredit is installed, but doesn't do anything. Why not? – Michiel de Mare Jan 24 '10 at 11:28
  • 1
    Is active? Try M-x paredit-mode. – mac Jan 24 '10 at 14:11
  • Apparently it was not active - how to make it active by default? What's the go-to config-file for Aquamacs (.emacs is deprecated?) – Michiel de Mare Jan 25 '10 at 11:04
  • You can use .emacs, that is what I do. – mac Jan 25 '10 at 11:50
  • Did you get everything to work? – mac Jan 28 '10 at 07:28
  • I got paredit to work by adding the following code *after* the ELPA load-package statement: (require 'paredit) (mapcar (lambda (hook) (add-hook hook 'enable-paredit-mode)) '(clojure-mode-hook lisp-mode-hook slime-repl-mode-hook emacs-lisp-mode-hook)) But still no slime/swank. – Michiel de Mare Jan 29 '10 at 18:41
  • Have you tried M-x swank-clojure-project? – mac Jan 31 '10 at 09:14

6 Answers6

7

These are the steps I took to set them up without using ELPA. Hope this helps.

Get SLIME using MacPorts

sudo port -v install slime

Get paredit

curl -O http://mumble.net/~campbell/emacs/paredit.el

Get clojure & clojure-contrib

  • Either using MacPorts
sudo port -v install clojure clojure-contrib
  • Or downloading directly
curl -O http://build.clojure.org/snapshots/org/clojure/clojure/1.1.0-master-SNAPSHOT/clojure-1.1.0-master-20091202.150145-1.jar
curl -O http://build.clojure.org/snapshots/org/clojure/clojure-contrib/1.1.0-master-SNAPSHOT/clojure-contrib-1.1.0-master-20091212.205045-1.jar

Get clojure-mode and swank-clojure (Emacs side)

git clone http://github.com/technomancy/clojure-mode.git
git clone http://github.com/technomancy/swank-clojure.git

Get swank-clojure (Clojure side)

  • Either downloading pre-built jar file
curl -O http://repo.technomancy.us/swank-clojure-1.1.0.jar
  • Or building from source (assuming lein is installed)
cd path/to/dir/swank-clojure
lein jar

Put clojure, clojure-contrib and swank-clojure .jar files in ~/.swank-clojure or ~/.clojure (the default places where swank-clojure.el searches for them).


Add to either ~/.emacs or ~/Library/Preferences/Aquamacs Emacs/customization.el (change paths to match your own settings)

(add-to-list 'load-path "/opt/local/share/emacs/site-lisp/slime/")
(add-to-list 'load-path "/opt/local/share/emacs/site-lisp/slime/contrib/")
;; Change these paths to match your settings
(add-to-list 'load-path "path/to/dir/clojure-mode/")
(add-to-list 'load-path "path/to/dir/swank-clojure/")
(add-to-list 'load-path "path/to/dir/paredit/")

;; Customize swank-clojure start-up to reflect possible classpath changes
;; M-x ielm `slime-lisp-implementations RET or see `swank-clojure.el' for more info 
(defadvice slime-read-interactive-args (before add-clojure)
(require 'assoc)
(aput 'slime-lisp-implementations 'clojure
(list (swank-clojure-cmd) :init 'swank-clojure-init)))

(require 'slime)
(require 'paredit)
(require 'clojure-mode)
(require 'swank-clojure)

(eval-after-load "slime"
  '(progn
    ;; "Extra" features (contrib)
    (slime-setup 
     '(slime-repl slime-banner slime-highlight-edits slime-fuzzy))
    (setq 
     ;; Use UTF-8 coding
     slime-net-coding-system 'utf-8-unix
     ;; Use fuzzy completion (M-Tab)
     slime-complete-symbol-function 'slime-fuzzy-complete-symbol)
    ;; Use parentheses editting mode paredit
    (defun paredit-mode-enable () (paredit-mode 1))
    (add-hook 'slime-mode-hook 'paredit-mode-enable)
    (add-hook 'slime-repl-mode-hook 'paredit-mode-enable)))

;; By default inputs and results have the same color
;; Customize result color to differentiate them
;; Look for `defface' in `slime-repl.el' if you want to further customize
(custom-set-faces
 '(slime-repl-result-face ((t (:foreground "LightGreen")))))

(eval-after-load "swank-clojure"
  '(progn
    ;; Make REPL more friendly to Clojure (ELPA does not include this?)
    ;; The function is defined in swank-clojure.el but not used?!?
    (add-hook 'slime-repl-mode-hook
      'swank-clojure-slime-repl-modify-syntax t)
    ;; Add classpath for Incanter (just an example)
    ;; The preferred way to set classpath is to use swank-clojure-project
    (add-to-list 'swank-clojure-classpath 
"path/to/incanter/modules/incanter-app/target/*")))
ubolonton
  • 121
  • 1
  • 3
  • Thanks for your elaborate reply - I'm going to give it a try tonight. Do you have an alternative to installing SLIME with MacPorts? I'm aiming to have a minimal set of dependencies. – Michiel de Mare Feb 02 '10 at 11:09
  • You can download it at http://common-lisp.net/project/slime/snapshots/slime-current.tgz or use CVS to clone the repo: cvs -d :pserver:anonymous:anonymous@common-lisp.net:/project/slime/cvsroot co slime – ubolonton Feb 02 '10 at 13:11
5

Download and install Aquamacs.

Download and install ELPA (http://tromey.com/elpa/install.html)

Do M-x package-list-packages

Mark the lines called "clojure-mode" and "swank-clojure" with "I" then press "X".

Done.

mac
  • 9,885
  • 4
  • 36
  • 51
  • There are no instructions for installing ELPA on Aquamacs, and the instructions for Emacs 22 don't work. – Michiel de Mare Jan 23 '10 at 18:46
  • 1
    Don't work in what way? do you get an error message. Oh - you execute by positioning the cursor right of the last paren and press C-x-e. – mac Jan 23 '10 at 18:50
  • The ELPA-documentation said C-j, but C-x-e (that's C-x C-e) works. Well, it gave a http error the first time, but the second time showed the package list. I also selected the packages slime, and slime-repl, by pressing 'i', not 'I'. Pressing 'x' started compilation, which gave me a bunch of warnings and one error (in slime-repl), hopefully not fatal. – Michiel de Mare Jan 23 '10 at 23:47
  • 1
    You can always do C-h m (That's a separate simple m, not C-m) to get help on the current major mode, as well as any minor modes in operation, which will tell you all the current keybindings. That's true for Emacs, anyway; but I imagine Aquamacs probably has it too. – Michał Marczyk Jan 24 '10 at 12:00
5

Here's a blog post that mentions Aquamacs: Setting up Clojure, Incanter, Emacs, Slime, Swank, and Paredit

Jouni K. Seppänen
  • 43,139
  • 5
  • 71
  • 100
  • 1
    The blog is a more detailed version of my reply above. It also explains the diffs btw versions of Emacs for OSX. Good find! – mac Jan 24 '10 at 21:26
  • Great article - pity it used Maven. I picked up an virulent allergy to maven around 2004 or so - apparently it's gotten better but I'd like to do without it all the same. – Michiel de Mare Jan 29 '10 at 18:27
1

There seems to be a fairly easy way to set up Aquamacs 2.4 and SLIME for clojure:

  1. Install Clojure
  2. Install Aquamacs 2.4 from here "http://aquamacs.org/"
  3. Install the Aquamacs SLIME package from here "http://aquamacs.org/download.shtml"

This will not work so...

  1. Get the latest version of SLIME from here "http://common-lisp.net/project/slime/#downloading" - you want the CVS snapshot tar file
  2. Unpack the SLIME tar file and copy it into /Library/Application Support/Aquamacs Emacs/SLIME

Seems to work OK for me...

Jim
  • 11
  • 1
0

I know the OP wants to use Emacs for Clojure dev. I'm an emacs fan myself, but I found using Enclojure (http://www.enclojure.org/home) to be a great way to get started quickly with hacking Clojure.

  • 1
    Thanks for the tip, I'm aware that there are good alternatives, but this thread is really for Aquamacs tips - even Carbon Emacs is off-topic. – Michiel de Mare Feb 02 '10 at 11:10
0

Today I would head for https://github.com/tehcurtis/aquamacs-emacs-starter-kit/network

this is for ruby and wont work at first but anyway. git clone and copy things to Preferences.el according to readme. Fix the brokenness by edit the ~/Library/Preferences/Aquamacs Emacs/ and comment out almost everything in modes.el (I have only (setq-default indent-tabs-mode nil) left in the file)

The good part: you have installed elpa-package-manager with less hassle

now: use

M-x package-list-packages

go to

clojure-mode   (press I)
slime          (press I)
slime-repl     (press I)

Press X to install

done.

Caveat: clojure-jack-in wont work so you have to

M-x slime-connect

and press enter twice and y to start.

claj
  • 5,172
  • 2
  • 27
  • 30