The website BraveClojure.com offers an excellent introduction to using Clojure in an Emacs environment. Here are some notes that I have found useful.
2. Install Emacs and the package CIDER.
3. In Emacs do
M-x cider-jack-in. And after a short wait (it should be less than a minute), you should see something like this with the code editor in top and REPL in bottom frame:
Here are a bunch of key bindings for working with windows:
|C-x o||Switch cursor to another window. Go ahead and try this now to switch between your Clojure file and the REPL|
|C-x 1||Delete all other windows. This doesn’t close your buffers and it won’t cause you to lose any work. It just un-splits your frame.|
|C-x 2||Split window, above and below|
|C-x 3||Split window, side by side|
|C-x 0||Delete current window|
For example, to get the side-by-side put your cursor in one frame, the one with the Clojure file, and do
C-x 1. This should un-split your frame and you should only see the Clojure code. Then do:
C-x 3to split the window side by side again
C-x oto switch to the right window
C-x b *cider-repl*to switch to the CIDER buffer in the right window
The key binding
C-x C-e runs the command
cider-eval-last-expression. As the command suggests, this makes Emacs send the expression immediately preceding point to nrepl, which then evaluates it.
Summary of Cider’s Paredit mode
This paredit-mode, a minor mode which turns Lisp’s profusion of parentheses from a liability into an asset. Paredit ensures that all parentheses, double quotes, and brackets are closed, relieving you of that odious burden. We’ll use wrapping, slurping, and barfing to surround an expression with parenthesis and to move parenthesis to left and right. Note that on my mac I needed to use the shift key with arrows to get slurp and barf to work.
|M-x paredit-mode||Toggle paredit mode|
|M-(||paredit-wrap-round, surround expression after point in parentheses|
|C-→||Slurp; move closing parenthesis to the right to include next expression|
|C-←||Barf; move closing parenthesis to the left to exclude last expression|
|C-M-f, C-M-b||Move to the opening/closing parenthesis|