June 2012 - overview

This will walk through the simplest and best environment for clojure in emacs, as of [25 Mar 2012]. You don’t have to think about slime and swank - after installation it “just works”.

installation

lein: https://github.com/technomancy/leiningen

latest emacs:

brew install emacs --cocoa #stable

brew install emacs --cocoa --use-git-head --HEAD #latest

emacs plugins for clojure: emacs prelude

in .bashrc:

export TERM=xterm-256color

alias emacs='open -a /Applications/Emacs.app $1'

export PATH=$PATH:~/.cabal/bin (for example)

in .bash_profile:

[[ -s ~/.bashrc ]] && source ~/.bashrc

in ~/.lein/profiles.clj: (https://github.com/bbatsov/prelude/issues/637)

{:user

{:plugins [[cider/cider-nrepl "0.8.0-SNAPSHOT"]]}}

(by convention, i put software that is not managed by a package manager in ~/opt, as opposed to using an installer or homebrew, which can go wherever it ends up. that way i can remove them by hand too.)

Everything below here is obselete and probably no longer relevant or correct

first project

lein new helloworld

cd helloworld

lein deps

emacs src/helloworld/core.clj

`M-x clojure-jack-in`

in core.clj, type in (+ 3 4), put the cursor after the last paren, C-x C-e to evaluate the expression, observe “7” in bottom left

documentation

notes

i’m starting to use emacs in windowed mode, iterm eats certain keychords like C-M-f which is pretty important in paredit. `open -a emacs` was sufficient. i don’t think i’m going to make an alias to keep the distinction between terminal and cocoa emacs.

here’s whats going on under the hood

There are different ways people configure their emacs and clojure, some deprecated, many different ways to get working with various levels of success and complexity. This document will walk you through my way with no magic, from scratch. I don’t like magic because when it breaks i can’t fix it, and it requires putting complicated stuff in my .emacs that i don’t understand.

I don’t recommend cloning one of many emacs configurations on github. They may not be using the best tools and they will have lots of other dependencies, custom keybindings, etc. However they are useful to look at if you get stuck. Here are two configurations from PHL Clojure Club members:

configuration notes

paredit won’t let you have unbalanced parens - you can’t backspace some random paren. use C-q to override paredit to insert a paren. C-u <backspace> to delete paren. the constraint that parens are always balanced means we can use things like kill-sexpr - so we can edit s-expressions instead of edit text. so C-k turns into “kill sexpr”. see header comments in http://mumble.net/~campbell/emacs/paredit.el