22

I was actually quite happy with using vim + lein repl, but since so many people keep saying that Emacs is the way to go when it comes to Lisps, I've decided to give it a try. The problem is now setting up a clojure environment that does all the fancy things that people keep talking about - for now I managed to install clojure-mode and nREPL and that works reasonably well, but I need to get the repl to work with my Leiningen projects if this experiment is going to go somewhere (having a repl in the editor would be pretty pointless if that meant having to manage of all my dependencies (especially classpath related ones) on my own again). The problematic point here is that most articles I see online are

  • A) about swank-clojure, which is deprecated
  • B) about Leiningen 1.x, which is deprecated
  • C) both
  • D) Only cover installation, not how to actually use the things you just installed (or even what they do)

Now what I'm looking for is:

  • Get nrepl.el to respect my project.clj
  • Find out what the normal workflow with leiningen + emacs + clojure-mode + nrepl.el is
  • Has nothing to do with the question, but I'd be interested in why emacs sometimes covers up text (changes font color to background color until hit by the cursor) without me asking it to.
Cubic
  • 14,902
  • 5
  • 47
  • 92

1 Answers1

22

Assuming you have both lein2 and nrepl.el installed:

Option A:

You simply open in Emacs a file belonging to your lein project (like foo.clj) and you type M-x nrepl-jack-in. This will start a nREPL with all the deps loaded in and you can play with it more or less in the same manner as with swank-clojure. (that's what I do most of the time)

Option B:

You go to your project's dir in a terminal and type there:

lein repl

Afterwards typing M-x nrepl will allow you to connect to the running nrepl session.

nrepl.el comes with a handy minor mode that allows you to evaluate code in your Clojure source files and load it directly in the repl (same as swank-clojure). A list of all available commands in available in the nREPL menu section.

P.S.

nrepl.el was renamed to CIDER.

Bozhidar Batsov
  • 55,802
  • 13
  • 100
  • 117
  • It appears that nrepl.el is already aware of leiningen projects by default - that's neat. – Cubic Oct 11 '12 at 13:39
  • nrepl.el is aware of lein 2 projects. It won't work with lein 1.x – Bozhidar Batsov Oct 11 '12 at 13:54
  • 1
    That's fine, I'm not really interested in lein 1.x - I just started with clojure recently and have been trying really hard to avoid 'old' stuff (things tend to get old really fast when you have a relatively new language). – Cubic Oct 11 '12 at 13:56
  • 1
    incase you are using boath lein1 and lein2 . just add (setq nrepl-lein-command "/Users/locojay/bin/lein2") in your .emacs file. you should also have a look at ac-nrepl for autocompletion – jassinm Oct 11 '12 at 15:12