Emacs is a great tool for clojure development. In fact you often hear people raving about the marriage of emacs and clojure without any clear explanation of if or why it's better than any other editor that you could use for clojure development.
I'm not going to get into why emacs is good for clojure development here. The aim of this post is to help someone who is looking to try it get up and running quickly, so they can try it for themselves.
I'm assuming you already have emacs installed and clojure setup. I won't go into the basics of using emacs here, but I'll outline a few of the features that you may find handy for working with clojure code.
Emacs Live
The quickest way to get your emacs up and running is to install emacs-live. Emacs live is
"An opinionated set of defaults for getting started with a specific focus on live coding with Overtoneand Quil."
It provides an excellent default setup for working with clojure.
Emacs Modes for clojure development
Among the most important modes are Clojure-mode and Paredit along with repl integration via Cider.
Paredit
One of the most common complaints I hear from people who haven't tried clojure is about the abundant parentheses and how difficult they are to manage. Managing and matching parentheses is really a problem for the text editor, not the programmer. If you have trouble with unmatched parentheses, then either your text editor is not up to the task or you're not using it correctly.
Paredit mode is an emacs mode that takes care of the minutiae of working with s-expressions. Some of the things it does for you include:
- Ensures your parentheses are always balanced. E.g. It won't allow you to create an opening bracket without the corresponding bracket, or it won't let you delete a single bracket - you have to delete the entire expression.
- Lets you cut, paste, move etc s-expressions in their entirety. You can move the entire sub-tree of an expression somewhere else or wrap an entire expression with another one.
If you've never used Paredit before, it can be a little off-putting. You need to move from thinking in terms of text-tokens to thinking in terms of expressions. Once you get used to it though, the parentheses that so many people are wary of fade into the background. They become easy to manage.
To get a feel for Paredit, lets edit a small clojure file and play around with the brackets.
Lets create a new clojure project...