This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-06-26
Channels
- # aws (8)
- # babashka (18)
- # beginners (17)
- # calva (19)
- # clj-kondo (2)
- # clojure (44)
- # clojure-brasil (100)
- # clojure-denver (8)
- # clojure-europe (20)
- # clojure-norway (165)
- # clojure-uk (1)
- # clojurescript (21)
- # cursive (4)
- # datalevin (18)
- # datomic (3)
- # emacs (22)
- # events (3)
- # hoplon (6)
- # hyperfiddle (13)
- # juxt (4)
- # kaocha (3)
- # london-clojurians (1)
- # malli (10)
- # off-topic (20)
- # pedestal (6)
- # rdf (7)
- # reagent (3)
- # releases (1)
- # shadow-cljs (5)
- # vim (3)
- # xtdb (3)
Hey, to use Calva with a custom zprint configuration, is setting up something custom via printFn
the route to follow, or is something simpler possible?
Yeah, that might work. If printFn
works, I don’t think I know of anyone using it. I wonder if it is worth going the whole route with custom printFn
for custom pretty printing. How are you planning to use it?
Still figuring that out, but basically I wanted to call zprint/zprint
, because I thought, I could configure that with an options map. But it seems it picks up its settings from ~/.zprintrc
which would be good enough for me. Now I wonder, the zprint
which comes with Calva, wouldn’t that also pick .zprintrc
up?
If we are talking about the pretty printer, yes, if it is the server side one. I don’t think the client side pretty printer does that.
server side is automatically active when i have connected to a running generic REPL?
The nREPL server will need to have the zprint dependency satisfied. So depends on how generic that REPL is and how it is configured.
ok, cool. let me see if i can make that work. thank you, @U0ETXRFEW
Yeah, maybe. It’s just that we have this auto-formatting for PRs at work going on and I hope I can avoid some weird diffs if I get my own formatting work exactly like the one that goes on in CI later on
Ah, no. Maybe I misunderstood you. At the moment I am trying to satisfy this dependency that the REPl can pick up the zprint dependency.
but it didn’t seem to pick it up, according to the output window:
Calva is utilizing cider-nrepl and clojure-lsp to create this VS Code experience.
nREPL dependencies configured:
nrepl: 1.0.0
cider-nrepl: 0.28.5
cider/piggieback: 0.5.3
even if I put this
{:user {:plugins [[cider/cider-nrepl "0.30.0"]
[refactor-nrepl "3.6.0"]
[zprint/zprint "1.2.5"]]}}
in my ~/.lein/profiles.clj
. While starting the app, however, I saw it loading the new dependencies. Hm :thinking_face:Thing is that even if you get it to work it will only affect the pretty printer. Which is different from Calva’s formatter. What you might want to do is to run zprint as a file watcher and format files as they are saved.
Hey, first of all, thanks, because up until now I did not see the distinction between pretty printing and formatting very clearly. So in general I want “Replace Current Form (or Selection) with Pretty Printed Form” instead “Calva Format: Format and Align Current Form (recursively, experimental)“, at least for what I originally had in mind.
Now it seems to work with my current setup that when I change in settings.json
to "calva.prettyPrintingOptions": { "printEngine": "zprint", "enabled": true, }
, it picks it up. Compared it to the output from using zprint directly (against pprint) and indeed it seems to work.
My general setup is that I connect to a running REPL in my project and at first suspected that it does use the server-side pretty printing. But since it didn’t display any dependencies under nREPL dependencies configured:
, I assume it pretty prints client-side, which I understand means that Calva itself parses a string and triggers reformatting, instead Cider doing it.
Thanks also for the hint with regards to the formatting on save. That would definitely also be an options. But now I am actually curious about learning more about the interplay between Calva, Cider and Leiningen, and how I would get Cider to use zprint (, such that it picks up an opts map from a config file, which still is my goal), server-side. How does Calva determine which nREPL dependencies are configured?
When printEngine
is set to zprint
, Calva will inject the zprint dependency on Jack-in. I am guessing you are not using jack-in, since you mentioned you are using a generic repl? Calva doesn’t really know anything about which nREPL dependencies are configured, other than that it injects the ones it depends on, or assumes the user has configured them, in case Calva does not start the repl.
The pretty printer is used for formatting things printed by Calva’s repl client. And also for the Replace Current Form (or Selection) with Pretty Printed Form command. The formatter is responsible for formatting the code in the editors. Which happens as-you-type (on paste, etc), as well as on demand with tab
(Format Current Form), Format Selection, Format Document, and if Format on Save is enabled. The formatter is using cljfmt, there is no option there, apart from disabling Calva as a Clojure formatter, or configuring cljfmt.
Not sure I am answering your question. I’m trying to relay stuff about how things are setup.
Right, I am not using jack-in with this project, but connect to a generic REPL. So if I am understanding correctly, I should add those dependencies to my Leiningen project. But in general it works that Calva sends a command somehow to this nREPL which then takes care of the formatting? And how does Calva choose between what is called client side and server side pretty printing?
Hey @U03GYEFN2U8. Just read the above and thinking maybe I can clarify a couple things.
Calva is utilizing cider-nrepl and clojure-lsp to create this VS Code experience.
nREPL dependencies configured:
nrepl: 1.0.0
cider-nrepl: 0.28.5
cider/piggieback: 0.5.3
When you see the above ^, it's reporting only dependencies which can be configured for jack-in: https://calva.io/customizing/#jack-in-dependency-versions. It doesn't report other dependencies you might add.
> I am actually curious about learning more about the interplay between Calva, Cider and Leiningen
There's not really interplay between Calva and Leiningen. Lein might start your repl, but after that Calva talks to nrepl.
Cider (the Emacs editing environment for Clojure) is not involved at all. Rather, the cider-nrepl middleware is involved and provides some of the functionality Calva offers via communication with nrepl.
If you haven't read the page on https://calva.io/pprint/, you might find it helpful. Formatting and pretty printing are not really related in Calva, though. So if you're looking for help with formatting, the https://calva.io/formatting/ might help you, if you haven't read it yet.
> But in general it works that Calva sends a command somehow to this nREPL which then takes care of the formatting?
nREPL does not handle formatting. Formatting is done via cljfmt.
You should be able to match whatever formatting is happening in CI with cljfmt settings, but I can't say that for sure since I don't know how your CI handles formatting.Hey @U9A1RLFNV. Thank you for writing this down, orry for the late answer. I think what confused me was the section Why does Server or Client Side Matter? on this page: https://calva.io/pprint/. I thought there was somehow an option of using zprint either on the client or on the server. I hoped when it is run on the server I have more control over how zprint is configured. But I think there is still a lot I need to wrap my head around. I abandonded my maybe mistaken idea for now and will do what PEZ proposed (formatting the file on save) and will read a bit more widely, to get an actual picture how things are working. Reading this here https://calva.io/nrepl_and_cider-nrepl/, for example.