Skip to content

Clojure Editors

Christopher Small edited this page Mar 30, 2018 · 1 revision

Clojure is wonderful, but you'll want a good text editor with all those parens! And also, in order to get the most out of Clojure's REPL joy.

Clojure is a Lisp, and as such Clojurists have a tendency towards Emacs, likely because of Emacs' Lisp connection via EmacsLisp. I am personally a vim fanatic, and find Clojure support in Vim to be reasonable enough that I typically stay in Vim. I've looked at SpaceMacs as a possible alternative, and it looks great! The vim emulation in particular is quite good, however I wasn't easily able to get Parinfer working, which was a deal breaker for me (see more below on this).

If you're not into the ancients, and would rather have a full IDE experience, IntelliJ's IDEA is pretty good for Clojure, and has tolerable Vim emulation. However,you'll want to use it with the Cursive plugin, which requires a license. If you only need it for non-commercial work (personal projects, open source, and student work), it is free, but if you want an environment that you can also do commercial Clojure work on, you will need to pay for a license ($99/yr). The Parinfer support for IntelliJ is quite good, much better than Vim's actually. However, it can take a little while to set things up to your liking, at least for me, and the Vim emulation gap was painful enough for me that I went back to Vim. However, I'll note that the extra static analysis of Cursive is really wonderful, and was able to keep me on IDEA for quite a while. I'm just a sucker for Vim + tmux.

Visual Studio I've heard is getting pretty ok for doing Clojure. However, I've heard the Parinfer plugin is a little fussy.

LightTable is an interesting editor built with Clojure that comes packaged with Parinfer and has inline evaluation built in. It's not the mostly widely adopted tool in general though, so explore with caution.

Atom is supposed to have a passable Clojure plugin now, though I haven't tried it. Sublime, as well. You'll be able to use most things, but default preferences aside, I'd highly recommend that whatever you pick have both parinfer and some way of connecting to a REPL for inline code execution. Linters and static code analysis like Cursive does are nice as well if you can get em.

Feel free to add below any pertinent information for how you've managed to set up your environment.

Vim

I highly recommend using Fireplace to establish What I've been doing in the past is using tmux and tslime to move code back and forth between a running REPL and my source files. So I'll include some of my setup for that as well.

Fireplace et. al

The following seem to work decently together:

  • fireplace: Some REPL-ability, nice functionality for finding docs and so on.

Some nice .vimrc tidbits...

vmap e :Eval<enter> "evaluates visual selection
map E Ve "select and evaluates the current line
map <leader>e :%Eval<enter> "evaluates entire file

Basics...

`K` - Show docs for function under cursor
`[d` - Display source code for a function
`cpp` - evaluate current form
`cqq` - open up small repl window with current form
`cqc` - open up small, blank repl window

Tmux

If you are using a terminal based text editor like vim or emacs, Tmux is another nice tool you may want to use to put together an ad-hoc terminal based IDE. This ends up being pretty robust, and works with any kind of coding language that supports a REPL, so there is some advantage to that.

The idea is that instead of opening up a single terminal window for every process, you start a tmux session and open up new panes (or windows) within that session. Multiple panes can exist within a given window, and you can organize/tile these panes spatially as you wish. With vim, I'll open a text editor in one pane, fire up a Clojure REPL in another pane, and zsh session in a third pane, for working with git and such. If I like, I can open additional panes to run programs like htop, for monitoring CPU/memory usage. Sky is the limit!

First install tmux. Ubuntu can apt-get install tmux. Mac users are on their own (try installing homebrew and running brew install tmux and report back here?). Once installed just type tmux or tmux attach if you already have a session running.

I highly suggest mobbing my tmuxrc file, as it has more vim-like motion commands. With this, tmux key-commands start with Ctrl-A (herein CA). Here are a few pointers:

  • CA-| - vertically split current window into two panes
  • CA-_ - horizontally split current window into two panes
  • CA-[hjkl] - move between panes
  • CA-C - new window
  • CA-[<space>|<backspace>] - toggle windows
  • CA-, - name window
  • CA-' - switch window menu (can find be name)
  • CA-[ - Switch to buffer copy mode.
    • Start selecting text with <space>
    • v block select mode
    • <enter> - copy selection
    • Ctrl-[U|D] - Move up and down by half pages
  • CA-] - insert buffer of text from above
  • CA-? - help, obviously...

vim + tmux, specifically

You can also install the tslime vim plugin, which lets you select a tmux pane to move stuff back and forth between a REPL runing in another pane. You do this by visual selecting and then typing Ctrl-C. The first time you do this in a vim session you will be queried for which session, window and pane you want to paste to. Note that you can generally tab through these, and it will tell you which ones you are using now. So you really just need to specify the pane number (these are just assigned clockwise, but you can always check with CA-w). Easy and works with any REPL-able language!