Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Emacs, nrepl.el and Leiningen to play along?

Tags:

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.
like image 525
Cubic Avatar asked Oct 11 '12 11:10

Cubic


1 Answers

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.

like image 58
Bozhidar Batsov Avatar answered Oct 26 '22 23:10

Bozhidar Batsov