Saturday, February 27, 2010

Leiningen and VimClojure

Leiningen seems cool. It will take care of installing any jars you need for your clojure application, and setting up the classpath, so you don't have to worry about all the Java stuff and can get down to clojure hacking.

I spent some time yesterday getting Leiningen and VimClojure to work together. Here are the notes in case someone else has the same problem:

> mkdir code/clojure
> cd code/clojure

LEININGEN

I downloaded the install script from http://github.com/technomancy/leiningen and put it
in ~/code/clojure/lein.

> chmod a+x lein
> ./lein self-install
> ./lein new helloworld
> cd helloworld

NAILGUN server

Next step was to add the nailgun server needed by vimclojure. To do this I added these lines
to project.clj (which was generated by "lein new helloworld" before)
[org.clojars.ato/nailgun "0.7.1"]
[org.clojars.gilbertl/vimclojure "2.1.2"]

Now update the dependencies to generate a lib directory with all jars we need:

> ../lein deps

VIMCLOJURE

I already had the vimclojure vim plugin installed, but needed to add the nailgun client for VimClojure. For this I downloaded VimClojure (http://www.vim.org/scripts/script.php?script_id=2501), unpacked it somewhere and ran "make". This generated a file called "ng" which I copied to ~/code/clojure. I then added this line to .vimrc:
let vimclojure#NailgunClient = "/home/johan/code/clojure/ng"

I then put these alias definitions in .bashrc:
alias lein='/home/johan/code/clojure/lein'
alias ng='java -server -cp src:classes:lib/* com.martiansoftware.nailgun.NGServer 127.0.0.1'

TESTING AND RUNNING

> cd ~/code/clojure
> ng &
> vim src/helloworld.core.clj
You should now be able to type sr to open a REPL buffer (\sr if using the default settings)