Thursday, May 9, 2013

Clojure CLR / Emacs setup based on lein-clr (Part 2)

While working with the setup as described last week, some improvements and extensions are desired. Coming from Clojue on the JVM, it is for me uneasy to keep oversight of the configuration details both of the Windows environment and Clojure CLR specifically. I wanted to have some handy functions for the REPL in order to be able to easily inspect the configuration details.

1. Load an Init Script for the REPL on the JVM

While searching for a solution to automatically load a Clojure init file for the REPL, I came across the blog entries of John PitherLawrence D. Aspen and Colin Jones which give valuable ideas for the content of such an init.clj file, but do not cover how to autoload it.

For Clojure JVM with Leiningen, there are two straight forward solutions for this task:

  1. use ~/.lein/init.clj, as decribed in the Leiningen documentation,
  2. tweak your project.clj file as described here.
For the Clojure CLR setup with lein-clr, these solutions do not work as desired. the issue is that the injected Clojure code is evaluated in the context of the JVM which is used by Leiningen.

My first attempt was to tweak the project.clj file according to solution 2. by adding command line parameters for the REPL executable. However, the lein-clr plugin does not seem to produce a valid command with parameters. 

2. Load an Init Script for the REPL on the CLR

I wrapped the command line for the REPL in $CLOJURE_CLR/Clojure.Main.bat:

I decided to have a global configuration file init-clr.clj that would be usable for all projects being located in $CLOJURE_CLR/init directory in my Clojure CLR installation path.

I find it convenient to include a ~/etc/motd file which reminds me of the customised helper functions on a start screen of the REPL.

3. Windows Environment Variables

While digesting on the content for the init-clr.clj, I decided to set the recommended compiler option not in the init file, but to define the corresponding Windows environment variable CLOJURE_COMPILE_WARN_ON_REFLECTION=true. The advantage is that this option will such not only be activated in the REPL but also any compilation done by Clojure.Compile.exe, as David Miller explains here.