Fork me on GitHub
#cursive
<
2020-02-03
>
misha12:02:39

@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 : (

jvtrigueros17:02:31

Also, cljstyle, which is a fork of cljfmt but compiled to GraalVM https://github.com/greglook/cljstyle

misha19:02:24

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

manutter5113:02:34

If you just need a function you can use this:

misha22:02:00

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.

manutter5101:02:26

Yeah for arbitrary data structures that's a no-go, I thought you just wanted a simple data dump.

cfleming23:02:05

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

cfleming23:02:22

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/

kenny23:02:27

There's no way to use Cursive's test diffing when running CLJS tests, right?

cfleming23:02:17

No, sadly - that requires Cursive to understand CLJS REPLs better, which I’m struggling to get around to.

kenny23:02:28

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"

kenny23:02:06

I guess I could go make a temporary .clj test file, paste the failing test, and then run the test haha

cfleming23:02:59

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.

kenny00:02:16

Oh I see haha. That's a cool idea! I support the jiggery pokery 🙂