Setting up Emacs+Lein+Clojure in 15 minutes30.01.2013 Permalink Why for heaven's sake do I start using Emacs in 2013?
I have read that quite some Clojurians prefer Emacs over other IDEs so I gave it a shot and trained myself the necessary keystrokes until I felt comfortable. Now Clojure-Mode and Paredit really relieve my eyes and my head after having tried Counterclockwise for a while. But it took me about 2 hours to figure out the settings for Emacs to properly support Clojure development. If you're used to Eclipse and just want to experiment with Clojure then Counterclockwise might be the natural first approach as you avoid learning Emacs + Clojure at the same time.
So here's the recipe for Debian based distros like Ubuntu or Linux Mint.
- Ensure you have Java 7 or better 8 installed.
- Download the Leiningen Script. Leiningen is the central build and development tool for Clojure. Follow the simple instructions.
- For Emacs add the snapshot PPA
sudo apt-add-repository ppa:ubuntu-elisp/ppain a terminal window.
- To actually install Emacs type
sudo apt-get install emacs-snapshot emacs-snapshot-el
- You find my ~/.emacs.d contents on GitHub,
to get it use
git clone https://github.com/friemen/emacsd.git ~/.emacs.d
- Start Emacs, wait until install is complete and restart Emacs.
~/.lein/profiles.clj. Here's my profiles.clj contents as example.
Ok, the infrastructure is now set up. To get started with a new Hello World project:
lein new helloworld. If this is the first start of the lein script then it will download some stuff before actually creating a new project skeleton.
- Start Emacs.
- Load a file into the left buffer:
C-x C-f ~/projects/helloworld/src/helloword/core.clj.
C-c M-j(Emacs parlance for Ctrl-C and Alt-J on PC keyboards). This starts a JVM REPL process and connects Emacs with it.
- In the cider-repl buffer switch to the helloworld namespace with the command
- Switch the input focus using
C-x o. Type
C-c C-kto load, compile and evaluate the currents buffer code into the REPL process.
- Switch back to the cider-repl buffer with
C-x o. Invoke the foo function with
(foo "Hey!"). You're ready to play.