nrepl

bozhidar 2023-04-12T08:19:42.643769Z

@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.

bozhidar 2023-04-12T08:21:57.581979Z

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?

Alex Miller (Clojure team) 2023-04-12T13:00:45.583719Z

yep

pez 2023-04-12T08:23:08.858299Z

Calva does not do that. I guess it should?

bozhidar 2023-04-12T08:24:53.270629Z

@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.

bozhidar 2023-04-12T08:26:49.352549Z

We do something similar for ClojureScript REPLs - (require '[cljs.repl :refer [apropos dir doc find-doc print-doc pst source]])

pez 2023-04-12T08:27:11.594399Z

Yeah, Calva has a command for requiring those. But it makes sense to just do it.

bozhidar 2023-04-12T08:27:35.187369Z

In CIDER this is optional, but it's enabled by default. There's also a command to trigger those manually.

pez 2023-04-12T08:32:51.307569Z

@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?

pez 2023-04-12T11:50:01.481919Z

I added this issue for now: https://github.com/BetterThanTomorrow/calva/issues/2154

Alex Miller (Clojure team) 2023-04-12T12:59:30.727939Z

yep

🙏 1
bozhidar 2023-04-12T10:37:15.844749Z

I quickly checked with Lein and its also requiring repl-requires automatically (when you do lein repl).

Alex Miller (Clojure team) 2023-04-12T13:01:29.111989Z

thanks all

pez 2023-04-12T20:21:25.447609Z

> 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?

dpsutton 2023-04-12T20:32:29.011309Z

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)]])

dpsutton 2023-04-12T20:34:01.202369Z

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

pez 2023-04-12T20:37:41.488229Z

Thanks. Calva has a command for requiring the utilities. With a default keybinding even.

pez 2023-04-12T20:38:53.042139Z

I’ll make it configurable with the auto-require. Wether it should be done at all, only on connect, or for all namespaces.

dpsutton 2023-04-12T20:43:52.718249Z

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

dpsutton 2023-04-12T20:44:29.837669Z

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

pez 2023-04-12T20:53:39.128209Z

Thanks again. Will make it up to the user to expand the auto-require outside the initial connect, or disable it entirely.

Alex Miller (Clojure team) 2023-04-12T21:39:47.892919Z

yeah, I would just do it in 'user

🙏 1
pez 2023-04-12T20:27:29.005979Z

Tried with clojure and lein and they both do this only for the user namespace… What does CIDER do?