Question

I have done a lot of research on clojure programming. I would like to have a clean set up where I can easily see and access all of my projects, quickly test/modify them in a REPL, and package them once they are complete so that I can call them from the command line.

Through multiple recommendations, I currently have a confusing mosh of CCW in Eclipse, Leiningen, maven, and SublimeREPL. Experienced Clojurians, especially mac users, what are the tools that you use?

I would particularly appreciate a step-by-step account of working on a project, such as how you have your windows set up and how to quickly load files into a REPL.

On a related note, whenever I hit an error while using the REPL in eclipse, I have to close it and restart it every time. If I try to continue, all I get is an 'unhandled REPL exception'.

Was it helpful?

Solution

For Clojure development on the Mac, I use Sam Aaron's excellent "curated emacs experience", Emacs-live. It's a set of customisations to emacs which were put together primarily to turn emacs into a live music performance tool (with Overtone, a Clojure library for making music). However as a side effect of this it looks beautiful, and comes with a neat Clojure configuration. I use it for all my Clojure development work on the Mac.

To get up and running with Clojure emacs-live:

  1. Install the latest emacs. You can get Mac binaries at http://emacsformacosx.com/
  2. Install emacs-live. Easiest way is to run the "brogrammer" installation script

    bash <(curl -fksSL https://raw.github.com/overtone/emacs-live/master/installer/install-emacs-live.sh)
    

    You can also do a manual installation following instructions at the github repo https://github.com/overtone/emacs-live

  3. Install leiningen. Sounds like you have that already. If not, just do brew install leiningen (you have homebrew right? If not, you can follow the instructions at the leiningen repo https://github.com/technomancy/leiningen).

Now for your real questions....

  1. How do I easily see and access all of my projects? Emacs has built in bookmarking - I just bookmark the root directory of each project so I can jump to it quickly. To bookmark a file or folder use the key command C-x r m, and to see the bookmark list use C-x r l. You can browse around directories in emacs using a text-based directory browser (called dired) which is accessible by the key command C-x d.

  2. How do I quickly test/modify my projects in a REPL? Emacs-live has nrepl.el included. This means that from any clojure source file you can invoke the command M-x nrepl-jack-in. This will give you a repl which you can use to test your program. Any .clj file loaded in emacs will put you into clojure-mode. Some useful commands in clojure-mode are:

    • C-c M-n (from source file) switch namespace of repl to namespace of current source file
    • C-c C-k evaluate current buffer (file)
    • C-x C-e evaluate last s-expression
    • M-. jump to definition
    • M-, jump back
  3. How do I have my windows set up? I usually have a horizontal split (C-x 2), with a repl in the lower window and the source file I'm currently working with in the top window. I'll switch between open source files in the top window using C-x b (switch buffer). Works for me.

  4. How do I package them once they are complete? Use lein uberjar from a command line (M-x eshell) to package up the project and its dependencies.

Note: I've used the standard shorthand for expressing keyboard shortcuts in emacs above. It's a bit archaic, but on the Mac, as standard, C is mapped to the control key, and M is mapped to the alt key.

OTHER TIPS

My personal setup is:

  • Lein (installed via Homebrew)
  • VIM (Vim-Clojure, Powerline, vim-fugitive plugins)

That is, easy and simple! And I worked in Clojure professionally for one year.

But you might also want to have a look at: LightTable and NightCode. Both look interesting approaches to Clojure development.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top