you're reading...

Notes on Running Clojure and REPL in Emacs

The website BraveClojure.com offers an excellent introduction to using Clojure in an Emacs environment. Here are some notes that I have found useful.

1. Go to http://www.braveclojure.com/using-emacs-with-clojure/

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:

Screen Shot 2015-01-15 at 7.53.11 AM

Here are a bunch of key bindings for working with windows:

Keys Description
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 3 to split the window side by side again
  • C-x o to 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.

Screen Shot 2015-01-15 at 8.52.43 AM

Keys Description
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


No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: