Fork me on GitHub
#cider
<
2022-03-21
>
dergutemoritz10:03:56

What's the recommended way to set up an initial namespace for a clojure-cli repl? https://docs.cider.mx/cider/repl/configuration.html#customizing-the-initial-repl-namespace only mentions Leiningen's builtin setting. The only option that probably could be made to work that I could find so far is customizing cider-repl-init-code via an eval form in .dir-locals.el since one needs to add to the default rather than replace it. Is there a cleaner alternative?

practicalli-johnny14:03:48

I recommend using the user namespace to set the namespace, or require/start other development tools I create a dev/user.clj file and add the dev path via an alias, e.g. :env/dev In the user.clj file, require the namespace and then use (in-ns 'namespace.name) to switch to the namespace This works fine for a terminal UI to the REPL, but I don't remember testing it with the Cider repl buffer (I use the source code buffers to evaluate, so setting the namespace is redundant, as Cider manages that for me) Here are some examples of how I use the dev/user.clj file https://practical.li/clojure/clojure-cli/projects/configure-repl-startup.html

practicalli 1
👍 1
dergutemoritz14:03:50

Thanks! I should mention that this is in the context of a monorepo with a common user.clj for all subprojects but each subproject has its own dev helpers namespace (e.g. with some convenience functions for a "reloaded" workflow) which is probably a bit of a special situation. I solved this now by passing in a jvm property via an alias which determines the dev namespace to load when said common user namespace is loaded. However, invoking in-ns this way doesn't affect CIDER's current REPL namespace. But that's alright. Just wanted to be sure that I'm not missing anything obvious!

practicalli-johnny20:03:28

Yes, I could change the namespace but couldnt get the REPL to stick with changed namespace, its always reverting back to user at some point before the REPL prompt displays.

ahungry15:03:53

Thanks for this conversation, helped me get a deps.edn setup going

practicalli-johnny16:03:40

Yes, it was interesting to revisit this issue. I do have a way to set it the namespace for a terminal repl (Rebel Readline), but its a bit of a hack. I made some notes in this issue in case I have time for more investigation https://github.com/practicalli/clojure/issues/409

dpsutton13:03:39

That's really not a cider property there. I think it's common to make a user.clj file with a function that requires and then in-ns whichever namespace you need

practicalli-johnny14:03:48

I recommend using the user namespace to set the namespace, or require/start other development tools I create a dev/user.clj file and add the dev path via an alias, e.g. :env/dev In the user.clj file, require the namespace and then use (in-ns 'namespace.name) to switch to the namespace This works fine for a terminal UI to the REPL, but I don't remember testing it with the Cider repl buffer (I use the source code buffers to evaluate, so setting the namespace is redundant, as Cider manages that for me) Here are some examples of how I use the dev/user.clj file https://practical.li/clojure/clojure-cli/projects/configure-repl-startup.html

practicalli 1
👍 1