Mate Varga
Mate Varga

Reputation: 3416

Lein repl resets namespace after loading Clojure script

Strange problem, I know. So lein can be instructed to load a specific namespace when running the REPL with lein repl. That's great, let's assume I have a file called ns1.clj, so my project.clj file contains the line:

:repl-options {:init-ns ns1}

And, as expected, that file is loaded. However, I want to switch to another namespace (ns2) after ns1.clj does it's job, so I append the following to ns1.clj:

(ns ns2)

The problem is that Leiningen resets the REPL namespace to ns1 after the ns1.clj has finished. Is there any way to start the REPL by loading ns1.clj but not resetting the namespace post-load? By the way, I would assume that Leiningen should just execute the script and not set the namespace explicitly.

Background: I want to load a clj script and then switch to a namespace that has been loaded from an external source by that very script. So the logic in ns1.clj figures out what namespace should the REPL start in.

Upvotes: 2

Views: 227

Answers (1)

Tim X
Tim X

Reputation: 4235

Based on your goal of wanting to extend repl functionality, I think you might do better to look at creating a lien plugin. You can then use this plugin without needing to modify your code and through your lein profiles, only have it installed when needed.

You might get some good ideas/pointers by looking at a number of existing lein plugins. In particular, there was quite an interesting blog post on planet clojure talking about a plugin called 'ultra' which extends the repl by adding ansi colours, improved test output formatting, enhanced stacktrace display and a few other repl tweaks. The project can be found on githug at https://www.github.com/venantius/ultra

Upvotes: 1

Related Questions