Sunday, June 24, 2012

Lein, noir and emacs

I like emacs, and I like the support emacs provides for lisp languages, including clojure. I'd like to have my clojure instance running as an inferior process as I develop my application. And given that I'm playing with web apps, I'd like that process to also include noir, my (tentative) web application framework.

Step 0: My Dev Environment

My primary box is windows 7, but I don't want to develop in windows for various reasons. So I have virtualbox running ubuntu, where I have installed emacs 24.

Step 1: clojure-mode in emacs

In emacs 24, run M-x package-list-packages, and install clojure-mode. After that, M-x clojure-jack-in starts up an inferior clojure process, and connects emacs to that process.

Step 2: Create a noir project

Install lein 2. Then,
$ lein new noir my-project
creates a new project. This is a complete web application with some sample pages.

Step 3: Load the project in emacs

Once again, run emacs and open the project.clj for my-project. Then M-x clojure-jack-in. Load your web app into clojure with:

user> (require :reload-all 'my-project.server)
nil
user> (my-project.server/-main)
Starting server...
Server started on port [8080].
You can view the site at http://localhost:8080
#<Server org.eclipse.jetty.server.Server@5c67718d>

I had to look at the server.clj generated by noir to find the precise calls I had to make. I imagine these would be subject to change as noir evolves.