Fork me on GitHub
#leiningen
<
2020-02-10
>
caio18:02:21

sup! quick question: how to define functions on :injections? My ~/.lein/profiles.clj looks like this, but add-dependency is never available in my repl (`hashp.core` is loaded correctly, which is stranger for me)

{:user {:plugins      [[lein-pprint "1.1.2"]
                       [com.jakemccrary/lein-test-refresh "0.23.0"]
                       [com.cemerick/pomegranate "0.4.0"]]
        :dependencies [[fipp "0.6.14"]
                       [hashp "0.1.1"]
                       [com.cemerick/pomegranate "0.4.0"]]
        :injections   [(do
                         (require 'hashp.core)
                         (defn add-dependency [dep-vec]
                           (require 'cemerick.pomegranate)
                           ((resolve 'cemerick.pomegranate/add-dependencies)
                            :coordinates [dep-vec]
                            :repositories (merge @(resolve 'cemerick.pomegranate.aether/maven-central)
                                                 {"clojars" ""}))))]
        :test-refresh {:notify-command ["notify-send" "-t" "1000"]
                       :quiet          true
                       :changes-only   true}}} 

caio18:02:42

(I also tried without wrapping it with do

noisesmith19:02:36

the injections don't neccessarily happen in your init-ns do they?

noisesmith19:02:27

my suspicion is that those requires happen in some other ns, before your ns is loaded, you use hashp.core by its full name, so it just works

caio19:02:26

that's what I thought too, but the docs say: > Forms to prepend to every form that is evaluated inside your project.

noisesmith20:02:44

that doesn't imply they ever run inside your ns

noisesmith20:02:41

with a prepend, (require 'my-ns) (in-ns 'my.ns) turns into (custom form) (require 'my.ns) (in-ns 'my.ns) - I wouldn't expect a prepend to end up running code in your init-ns unless you explicitly make it do so

caio20:02:42

but that'd be just the first form in the ns. I'd expect it to prepend it to every form

caio20:02:55

but yeah, makes sense for it to be some quirky behavior related to that

noisesmith20:02:48

every form that is evaluated inside your project isn't your repl, it's literally the forms in the project.clj file

caio20:02:18

ahhhh. ok

noisesmith20:02:08

@caio I bet what you want is :repl-options {:init ...} - that code will run in your startup ns, when a new repl connection is made

noisesmith20:02:34

and the lein docs make clear it is run in your startup ns

caio20:02:18

damn, right on. thanks a lot