This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-03
Channels
- # aleph (1)
- # announcements (3)
- # aws (36)
- # babashka (35)
- # beginners (25)
- # cider (14)
- # clj-kondo (3)
- # clojure (154)
- # clojure-europe (8)
- # clojure-italy (2)
- # clojure-nl (5)
- # clojure-serbia (1)
- # clojure-uk (133)
- # clojurescript (36)
- # cursive (15)
- # data-science (7)
- # datomic (16)
- # fulcro (34)
- # immutant (9)
- # jackdaw (5)
- # jobs (1)
- # leiningen (39)
- # off-topic (25)
- # pathom (42)
- # planck (13)
- # play-clj (1)
- # re-frame (18)
- # reagent (6)
- # reitit (3)
- # remote-jobs (1)
- # ring-swagger (16)
- # shadow-cljs (67)
- # sql (22)
- # testing (1)
- # uncomplicate (2)
- # vim (21)
- # vscode (6)
@cfleming do you use your own code format implementation or something open source? all I really need is a function to make maps like this:
{:a 1
:aa 2}
into this:
{:a 1
:aa 2}
clojure's pprint does not really do this : (@misha have you checked https://github.com/weavejester/cljfmt ?
Also, cljstyle, which is a fork of cljfmt but compiled to GraalVM https://github.com/greglook/cljstyle
I did, but it did not seem to work within time I spent playing with it. and all the docs are conveniently contain let
forms with single char binding names, like
(let [x 1]
y 2])
If you just need a function you can use this:
thank you. but the use case is arbitrary data structures (e.g. maps with vectors of maps, etc), which has to be pretty-printed, so simplistic implementation will not cut it, (where e.g. cursive's "format selection" seems to be a fit). And 2 pages of custom code not worth it in this case.
Yeah for arbitrary data structures that's a no-go, I thought you just wanted a simple data dump.
@misha Well, it’s open source, but probably not what you mean - it’s the IntelliJ code formatter, with extensions for Clojure code from Cursive. As you’ve found, some apparently-simple cases are decidedly non-trivial. I can make your case even more non-trivial by doing this:
{{:a 1
:aa 2} 3
:b 4}
For these reasons, IntelliJ’s code formatter uses a constraint algorithm with multiple passes until a solution converges, which is required for this sort of case. Cursive actually never breaks lines, which means that a simpler algorithm might suffice, but I might start breaking lines at some point, and then a naive algorithm gets extremely hard: https://journal.stuffwithstuff.com/2015/09/08/the-hardest-program-ive-ever-written/
No, sadly - that requires Cursive to understand CLJS REPLs better, which I’m struggling to get around to.
Well, in this case I don't really need to know anything CLJS specific. A cljc function returns a large structure that is just regular data. It's hard to eyeball what is different. Since it's regular data, it seems like Cursive's diff UI would "just work"
I guess I could go make a temporary .clj test file, paste the failing test, and then run the test haha
It’s not the diff that wouldn’t work, it’s the getting the data back from the test framework via the CLJS REPL. I actually also have plans to allow diffing of arbitrary structures from the REPL (something like (cursive.runtime.repl/diff first-thing second-thing)
), but that also requires some jiggery pokery to work.