Fork me on GitHub
#clojure
<
2022-11-18
>
Dallas Surewood05:11:08

What are people using for formatting? Cljstyle doesn't appear to be available on windows

p-himik05:11:57

cljfmt or zprint. Although I just use my IDE.

hifumi12306:11:39

Whatever happens to be the default with clojure-mode and cider , I guess. The most formatting specific stuff I deal with is metadata like :style/indent within macros I write myself. But otherwise just whatever my editor does for me

Joshua Suskalo16:11:56

A critical failure point for cljfmt and cljstyle and zprint as formatters is that they do not support a way for library authors to distribute indentation rules for their macros, which I believe is a critical part of the infrastructure of a formatter in a language with macros.

greglook16:11:26

cljstyle can be run from the uberjar if you want to run it on windows; unfortunately I don't really do any development on win, which is why I never built a graal-compiled version of it for that platform

greglook16:11:41

> they do not support a way for library authors to distribute indentation rules for their macros How would you want this to work, out of curiosity? Right now cljstyle isn't really semantically aware of the code, it's purely syntax-driven. I think a good next step would be to start understanding what aliases and forms actually map to what source namespaces, so it can start doing more complex things like :style-as configs (a-la clj-kondo's :lint-as)

Joshua Suskalo17:11:25

So I don't particularly care how it works, as long as it does. There's two key aspects to it that need to be supported: having configs distributed as a part of the dependency jar, like clj-kondo with the --copy-configs option, or like cider with the :style/indent metadata. Personally I add both to my libraries, so adding a third thing for another formatter would be perfectly fine with me. The second aspect of it is that it must understand where a symbol comes from. For example, cljfmt doesn't understand differences between multiple foo symbols based on where it was defined, it only understands applying rules to foo in the current namespace. This one is maybe slightly less big of a deal if macros are named in a relatively unique way, but I don't know if that's the case universally. An example usecase for this is https://github.com/IGJoshua/farolero which includes https://github.com/IGJoshua/farolero/blob/master/src/cljc/farolero/core.cljc#L382 on all its macros.

greglook17:11:35

cool, I'll check out those as prior art :thinking_face:

greglook17:11:48

...whenever I circle back around to the backlog of cljstyle work 😅

Joshua Suskalo17:11:17

that's fair, I'm just glad to have someone listen to this problem, I haven't gotten any positive response to this as a request when I've talked about it before wr/t other formatters 😅

👍 1
hifumi12320:11:58

Something like this would indeed be beneficial. At work people share a bunch of intricate clj-kondo configuration files just so their linter plays nicely with macros.

vemv22:11:11

cljfmt is the closest default to clojure-mode's. although zprint will soon ship an alternative set of defaults which also match them (following my requests) CIDER's cider-format uses cljfmt internally. there isn't an automated bridge between :style/indent var metadata and cljfmt's config format. But it isn't hard to author one (PR welcome in cider-nrepl - the only reason it's not there is because people haven't cared much)

ivana22:11:12

Using cljstyle compiled binaries from here in my custom VSCode plugin (on Linux & Mac) https://github.com/greglook/cljstyle/releases It's config pretty enough for me to add my custom formatting rules, depending on a project. PS one project I participated in, we had 4 developers with^ spacemax, gui-emacs, Idea with Cursive and VSCode with my plugin, and we hadn't any problems with conflicting formatting rules.

ivana08:11:32

Hello! All the time I used lein with some helpful plugins (whidbey f.e.), but now I'm on a project with clojure/cli & deps.edn. May I have formatted & colorized repl output with cli, like whidbey did with lein? PS I'm using raw terminal repl, no emacs/cider/lighttable/nighttable etc.

ivana09:11:52

Looks like this way kinda works, but wiyh some issues - looking for a more fresh & stable custom pprint function

clojure -e "(use 'aprint.core) (clojure.main/repl :init #(apply require clojure.main/repl-requires) :print aprint)"

ivana09:11:57

Thanks, will try it soon

ivana09:11:45

It works nice with arrows & some other keybindings, but unfortunatelly I can't find how to customize repl prompt function (I really need it) and change color scheme (maybe it posssible though...).

flowthing10:11:09

I don’t use Rebel readline, but it seems to me that you can customize the prompt using the :prompt arg to clojure.main/repl (see e.g. https://github.com/bhauman/rebel-readline#quick-usage).

👍 1
ivana10:11:37

Hmm, it's interesting, thanks! I'll definitely try to customize it and choose between it and puget, which I'm playng with now https://github.com/greglook/puget

ivana11:11:20

For now, running subrepl with custom prompt & puget options does all I need exept arrows behaves stupid way... So, maybe will play with rebel, trying to customize it

clojure \
-Sdeps "{:deps {mvxcvi/puget {:mvn/version \"1.3.4\"}}}" \
-e "\
(use 'puget.printer) \
(clojure.main/repl \
:init #(apply require clojure.main/repl-requires) \
:prompt #(print (str (char 0) (ns-name *ns*) \"=> \")) \
:print #(cprint % \
{:width 120 \
 :sort-keys false \
 :map-delimiter \",\" \
 :namespace-maps false \
 :seq-limit 10 \
 :print-color true \
 :print-fallback :pretty \
 :color-scheme {:delimiter \[:fg-256 5 243\] \
                :tag       \[:fg-256 5 243\] \
                :nil       \[:fg-256 2 156 93 39\] \
                :boolean   \[:fg-256 2 156 93 39\] \
                :number    \[:fg-256 2 156 93 39\] \
                :string    \[:fg-256 2 68 140 39\] \
                :character \[:black\] \
                :keyword   \[:fg-256 2 156 93 39\] \
                :symbol    \[:black\] \
                :function-symbol \[:bold :fg-256 2 170 55 49\] \
                :class-delimiter \[:black\] \
                :class-name      \[:black\]}} \
))"

flowthing11:11:39

Try clj instead of clojure.

💪 1
💥 1
ivana11:11:11

Isn't it just an alias?

flowthing11:11:27

clj == clojure + rlwrap.

ivana11:11:41

Ah, ok, trying....

flowthing11:11:07

(If you encounter any problems with clj, that is.)

ivana11:11:30

Oh my! clj solved the problems with arrows and now they behaves right way! I don't know what I may wish else! It's exactly as whidbey for lein I used long time. Maybe there would be some issues due to nested subrepl running, but will see! But for now I'm happy - I have a usable way for living in clojure cli! Thanks alot, man!

👍 1
ivana11:11:15

Actually I use the command above into expect file wrapped into spawn .... interact and at least for now I haven't promlems with indentation, maybe cause of it. But my custom clojure plugin is based on special interaction with terminal process and a terminal-pipeline-middleware, so it works as I expected, a least for now

ivana11:11:48

And now not on unix + lein, but also on mac + cli 🙂

flowthing11:11:50

I’m not sure how you ran Lein before, but since it uses nREPL by default, I’d imagine your new setup will have better support for nested REPLs, since nREPL doesn’t allow for nesting REPLs. Just out of interest, though, can I ask what you use nested REPLs for? I don’t think I’ve ever come across anyone using them before.

ivana11:11:37

I use them for 2 purposes: • for customising repl prompt (see :prompt key above, maybe I may customize it without starting subrepl with params, but I don't know the way) • for running my debugger, it allows infinite hierarhical levels of debugging processes by stopping the debugged code and openeing subrepl where you may analyse everything in a snapshot of current environment, but it a special case So in this question I use subrepl only (!) for customizing prompt and print functions

flowthing11:11:51

Interesting, thanks! Is your debugger open source?

flowthing11:11:01

I know there’s stuff like https://github.com/technomancy/limit-break, but I’m interested in all tools in this area.

ivana11:11:00

Yep, but github code is very old, it doesn't have any usageof somebody, so I forget to update it and make only local changes on my machine. But for the fist look^ https://github.com/Ivana-/bb-debug

ivana11:11:49

26 & 26 by stars, nose-to-nose! 😁

😁 1
ivana11:11:50

Btw you may get some ideas directly from the code, it you are interested in such tools development )

jpmonettas11:11:11

nice! I have also been working in a debugger, which is also ide independent and can be used just with a repl https://github.com/jpmonettas/flow-storm-debugger/ maybe you find it useful

👍 1
💪 1
flowthing11:11:28

Yeah, I’ve toyed with something similar (https://github.com/eerohele/Tutkain/blob/master/clojure/src/tutkain/repl/loop.clj — there’s no GUI, though, and it’s not fully-fledged at all), but I’m always interested when I hear about people using nested REPLs. 🙂

😊 1
ivana11:11:55

Thanks guyes, I'l look into tools you use & create! 🙂 👍

greglook17:11:16

heh [I've been going through these same things lately](https://clojurians.slack.com/archives/C03S1KBA2/p1668706004986359?thread_ts=1668648556.562199&amp;cid=C03S1KBA2) as I transitioned from lein to tools.deps (hi, author of puget and whidbey here 👋)

ivana17:11:40

Yep, it's interesting to fixing problems by myself, and after it things becames clearer, but on the other hand it would be nice to have just stable working tool & solution ))) Btw, thanks for your tools, @greg316! 👍

🙇 1
greglook17:11:50

I'll make a gist later with the stuff I put together, seems like it could be extractable as a stand-alone tool on top of rebel

👍 1
ivana09:01:57

@greg316 sorry for mentioning you, but maybe you may help me? I shared terminal command for starting clj REPL with puget and it works fine. Now I need the same, but with connection to existing REPL via nrepl port. I found another command

clj -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.5.3"}}}' -m nrepl.cmdline -c --host 127.0.0.1 --port PORT
but can't combine it with puget - if I use -e key above, it conflicts with -m key for running repl function. Can I have puget with nrepl connection via clj?

greglook16:01:47

For nrepl you'd need to do something similar to what whidbey does for leiningen setups, and run some initialization code to set the *print-fn* to use puget: https://github.com/greglook/whidbey/blob/a7c2111523ec660c3b6fd25d84221b0b1d74a4b5/src/whidbey/repl.clj#L76-L81

👍 2
💪 2
ivana17:01:57

Thanks alot, found that dynamic variable some hours ago and tried set it with puget.print/cprint wrapped with needed parameters & fixed for needed arity, and it works! And moreover, I don't need to alter some :middleware or other keys, but just run that set call directly in a connected REPL-client. Thanks again for excellent tool like puget, @greg316! I'm using it in all my projects & infrastructures: lein/cli, local/started/connected repls etc!

greglook17:01:52

Glad you are getting a lot of value from it. 😁

ivana17:01:13

That's my regular screen on Clojure dev process - left up is code, right up is my own data inspector and letf & down is terminal output fornatted & colored by puget (I set the same color schemes everywhere for more usability) 😊

Joshua Suskalo17:11:44

Is there a way to specify multiple interfaces in a type hint?

ivana09:01:57

@greg316 sorry for mentioning you, but maybe you may help me? I shared terminal command for starting clj REPL with puget and it works fine. Now I need the same, but with connection to existing REPL via nrepl port. I found another command

clj -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.5.3"}}}' -m nrepl.cmdline -c --host 127.0.0.1 --port PORT
but can't combine it with puget - if I use -e key above, it conflicts with -m key for running repl function. Can I have puget with nrepl connection via clj?