@alexmiller Right now there's no special way to configure those - most clients just trigger those requires themselves after connecting to the server. Part of the reason for this is that non all nREPL sessions map to interactive REPLs.
That's the code that CIDER runs for interactive REPLs:
(when-let [requires (resolve 'clojure.main/repl-requires)]
(clojure.core/apply clojure.core/require @requires))
I'm guessing the add-lib stuff will be added to the same var, right?yep
Calva does not do that. I guess it should?
@pez I think it's useful, as some users probably try to run things like source and find-doc in the REPL. In a tool like CIDER or Calva there are obviously better ways to achieve the same outcome, but I believe it's always a good idea not to surprise new users with unexpected behavior.
We do something similar for ClojureScript REPLs - (require '[cljs.repl :refer [apropos dir doc find-doc print-doc pst source]])
Yeah, Calva has a command for requiring those. But it makes sense to just do it.
In CIDER this is optional, but it's enabled by default. There's also a command to trigger those manually.
@alexmiller We can make Calva default to requiring the main/repl-requires. Just like CIDER does. Will that make things properly prepared for add-lib?
I added this issue for now: https://github.com/BetterThanTomorrow/calva/issues/2154
yep
I quickly checked with Lein and its also requiring repl-requires automatically (when you do lein repl).
thanks all
> what (if anything) sets the auto-referred vars in the user namespace? My emphasis. Does this mean that this autorequire should only happen in the user namespace? I started to implement and am adding it for any namespace the user switches to. Makes sense to always have the utilities always handy, but maybe there are reasons not to?
you can run into issues of shadowing user defined vars. You can see from the source which bindings it will create. Probably a low likelihood of shadowing but non-zero and probably quite frustrating when there is a conflict
(def ^{:doc "A sequence of lib specs that are applied to `require`
by default when a new command-line REPL is started."} repl-requires
'[[clojure.repl :refer (source apropos dir pst doc find-doc)]
[clojure.java.javadoc :refer (javadoc)]
[clojure.pprint :refer (pp pprint)]])I’ve made my own shortcut in emacs to send the string (apply require clojure.main/repl-requires) to my process to install them in my current namespace but this is a conscious decision. I think having a handy keybinding is a good balance between silently overwriting a user-defined var and giving access to these very helpful functions
Thanks. Calva has a command for requiring the utilities. With a default keybinding even.
I’ll make it configurable with the auto-require. Wether it should be done at all, only on connect, or for all namespaces.
to give you a sense of how frequent it might be, we only have one namespace that has names brought in by the repl requires:
metabase.automagic-dashboards.core has a function called source
But an example where it could bite you, clojure.data.json has a pprint function. And editing clojure.data.json in calva could be quite confusing for that reason
Thanks again. Will make it up to the user to expand the auto-require outside the initial connect, or disable it entirely.
yeah, I would just do it in 'user
Tried with clojure and lein and they both do this only for the user namespace… What does CIDER do?