Editing Clojure with Emacs
This gist will guide you to setting up a basic emacs-starter-kit-based Emacs configuration for editing Clojure.
- Getting Emacs - How to get Emacs.
- Installing the config - How to install this config.
- Keyboard shortcuts - Keybindings used during the presentation.
The first step is to get Emacs. Whatever you do, just make sure you get Emacs 24.
To paraphrase Install the right Emacs:
On a Mac? Also see note for Mac users.
$ brew install emacs --cocoa
$ your-package-manager install emacs
Once you've installed Emacs verify you have the correct version with
▸ emacs --version GNU Emacs 24.2.1 Copyright (C) 2012 Free Software Foundation, Inc. GNU Emacs comes with ABSOLUTELY NO WARRANTY. You may redistribute copies of Emacs under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING.
Now, for the config...
Installing the config
Prerequisite: Install Leiningen. Installation instructions.
To follow along with the contents of the presentation I would suggest you download and install the Emacs configuration bundled in this gist like so:
- Clean out any existing Emacs configurations you have.
Clone this gist to your
~/.emacs.dfolder with the command
$ git clone https://gist.github.com/5126926.git ~/.emacs.d
Launch emacs without any arguments like
$ emacs. You'll see a number of package fetch and compilation messages fly by as Emacs installs all of the packages specified in init.el.
If you didn't encounter any errors you've likely arrived at a simple, stable Emacs configuration. The configuration is annotated, so feel free to read and edit as you see fit.
A special note for Mac users
If you try to follow along into the Paredit sections you'll be sorely disappointed when you start trying to do things like
C-→. The problem is this: every Mac terminal sends the incorrect key codes to your terminal, and by-proxy, Emacs.
Fix this by following the excellent instructions of Cosmin Stejerean's Emacs + paredit under terminal. His instructions address how to fix Terminal.app, iTerm and iTerm2 to send the proper key codes for using Paredit.
Protip: To find out what any keybinding does use
C-h k followed by the keybinding in question to discover what it does.
REPL-driven Development with nREPL:
||Open an nREPL session. Intelligently loads project context if launched from any file within a Leiningen project.|
||Browse up or down through nREPL's history of commands.|
||Split window vertically|
||Evaluate expression at cursor. This command evaluates whatever top-level expression is under your cursor.|
||Change the namespace of your nREPL REPL to match the command was issued from.|
||Evaluate an entire file.|
||Evaluate the expression preceding your cursor.|
||Evaluate a selected region. Start selecting text with the keybinding
||Jump to the definition of the symbol under your cursor.|
||Jump back one level (after jumping with
||Absorb one expression from the right of the current expression
||"Splice sexp killing backwards". A utility-knife of a command that unwraps an expression, deleting anything before the cursor.