Discussion about all editors used for Clojure/ClojureScript

@pez I’m really enjoying Calva for vscode! One question. The code formatting you and your team have implemented for Calva that adheres to this guide: https://github.com/bbatsov/clojure-style-guide is excellent, but it differs in output from the clj-format library used by calva-format. Any plans long term to make calva-format use your custom code formatter?

pez 2018-06-13T19:43:57.000427Z

Good to hear, @nick652! Can you give an example for where the output differs? It is not supposed to differ.


Sure, here’s one rule from that guide that Calva gets right, but calva-format (clj-format) gets wrong: https://github.com/bbatsov/clojure-style-guide#one-space-indent




clj-format doesn’t seem to have a concept of “single-space indented forms”


I’ve noticed a couple other discrepancies while writing code, but I didn’t write them down and I’m having some trouble recalling the specifics. Happy to add more detail as I encounter it. I figured I’d ask here before logging anything in github in case it’s as-designed (since calva-format intentionally uses a different lib).


Thanks for the quick response, by the way.

pez 2018-06-13T21:13:49.000638Z

The whole thing is a bit confusing because different formatters are in play. The formatting done by Calva still (which is a leftover from when we moved the formatting from Calva to calva-fmt) is actually ”just” a way to try get the cursor at the right place when entering new lines. It’s a very naive implementation that (sometimes) fails when comments and strings have brackets. I was hoping we should be able to use the same module as calva-fmt uses for that task too, but maybe it is not one-indent form aware. Maybe @pedrorgirardi knows more about that.

cfleming 2018-06-13T21:19:27.000174Z

Formatting is one of those things which seems incredibly simple, until you actually do it….


great post! I really like Bob Nystrom’s writing.

cfleming 2018-06-13T21:21:16.000606Z

Yeah, Bob is awesome.


@pez that makes sense. I haven’t encountered any discrepancies that are a huge deal. I mainly figured I’d ask about it here since I was surprised to see the great work of the Calva extension get tweaked when I run calva-format with cmd+shift+p > “Format Doc”

pez 2018-06-13T21:34:19.000166Z

Thanks for alerting us to it. I really would like formatting to be fully automatic and as-you-type. But that might be a pipe dream. We will keep trying for Calva Formatter to be as helpful as possible.

pez 2018-06-13T21:34:57.000197Z

Very nice article, @cfleming !


just to clarify, I’ve preferred the “as-you-type” output in every case, so it’s working great for me in that regard

cfleming 2018-06-13T22:07:14.000320Z

@pez yeah, it’s great - it comes up on Hacker News from time to time, and generally has interesting comments too.

pez 2018-06-13T22:26:18.000096Z

I am glad to hear! It gives me guidance when re-implementing the feature in Calva Formatter, where it will be done in clojurescript instead. Also, we will need to figure out if we can get cljfmt to not undo it, right @pedrorgirardi ?

cfleming 2018-06-13T22:27:27.000020Z

@nick652 Also, note that the style guide is contentious in some areas, and particularly around 1-space indents: https://groups.google.com/d/topic/clojure/ihiEerO3trA/discussion

dpsutton 2018-06-13T22:27:58.000057Z

there was a big kerfluffle about indentation of (-> ...) as well

dpsutton 2018-06-13T22:28:23.000070Z

those are good reads

cfleming 2018-06-13T22:28:23.000091Z

Yeah, that one is in there 🙂

dpsutton 2018-06-13T22:29:28.000116Z

my coworkers go back and forth whether arguments on the next line are aligned with the first argument or indented two spaces. lots of ways to argue about indentation

cfleming 2018-06-13T22:29:31.000060Z

I tend to argue these things a lot, because it’s often the case that what people think of as “what lisp needs to do” often boils down to “that’s what emacs does, and it’s hard to change”

dpsutton 2018-06-13T22:29:38.000158Z


dpsutton 2018-06-13T22:29:55.000313Z

also, at some point your codebase looks like what it looks like. can't just go changing it whenever you open a file

dpsutton 2018-06-13T22:30:14.000293Z

i think the single comment ; is brutal in emacs. i think that is hard coded to go over to the right margin

cfleming 2018-06-13T22:30:30.000098Z

Right. I’m actually totally in favour of prescribed language formatting these days ala gofmt

cfleming 2018-06-13T22:30:43.000080Z

That ship has sailed for Clojure, but any new language should totally do that.

dpsutton 2018-06-13T22:30:50.000384Z

yeah starting with that is the ticket

dpsutton 2018-06-13T22:31:01.000135Z

i think elm is like that as well.

cfleming 2018-06-13T22:31:22.000035Z

Oh yeah, I had that ; discussion recently too. Again, it started out as “Cursive is clearly wrong” and ended up as “Emacs is hard to change” 🙂

cfleming 2018-06-13T22:31:45.000008Z

I’m going to have to support that just for mixed teams’ sanity.

dpsutton 2018-06-13T22:32:41.000263Z

well i hope your customers appreciate what you do for them. it is not particularly fun. but you sure do make a professional environment for them

cfleming 2018-06-13T22:33:06.000023Z

Yeah, generally they’re very appreciative - I’m lucky!

cfleming 2018-06-13T22:33:25.000298Z

Lots of Cursive is really fun to work on, but lots is not too, you’re right (leiningen, I’m looking at you)

cfleming 2018-06-13T22:35:30.000079Z

A funny story about customer appreciation was when I finished the current lein integration, which was something like 3 months of blood sweat and tears. I think I closed 25 issues with that change. At the last moment, I also added the CLJS community icon for CLJS files, a change which literally took 5 minutes.

dpsutton 2018-06-13T22:35:59.000203Z

cljs was fast for you?

cfleming 2018-06-13T22:36:00.000271Z

After the release, everyone was like: OMG! CLJS FILES NOW HAVE THE ICON!!!>!>!>!

dpsutton 2018-06-13T22:36:06.000273Z

hahaha ohhh

cfleming 2018-06-13T22:36:21.000379Z

There was something like a 30-tweet thread on twitter about it.

dpsutton 2018-06-13T22:36:22.000020Z

little polish can go a long way ha

dpsutton 2018-06-13T22:36:38.000059Z

i thought you meant you enabled cljs support and "it took 5 minutes" lol

cfleming 2018-06-13T22:36:39.000024Z

I’m going to change an icon on every release 🙂

dpsutton 2018-06-13T22:36:49.000389Z

make it animated while the repl is processing

cfleming 2018-06-13T22:36:51.000005Z

Haha, no, that was more blood sweat and tears

dpsutton 2018-06-13T22:36:51.000314Z


cfleming 2018-06-13T22:36:57.000183Z


dpsutton 2018-06-13T22:36:59.000444Z

yeah. so many different ways things can work

cfleming 2018-06-13T22:37:00.000162Z

I like that

cfleming 2018-06-13T22:37:14.000192Z

Yeah, CLJS is tough, and it’s hard to keep up with

cfleming 2018-06-13T22:37:24.000219Z

It’s really complex now.

dpsutton 2018-06-13T22:38:26.000156Z

i wish we could all standardize on one thing and that was what cljs looked like. like figwheel is blessed. that's what we use. or everyone only uses shadow-cljs and the compiler will always have a front end on it

cfleming 2018-06-13T22:39:08.000432Z

Yeah, again more closed ecosystems like Elm get some wins there


@cfleming yeah there are a lot probably a few things in that style guide where I might disagree if pressed for an opinion. But as for Calva, I was only wondering what the goal was for parity between the vscode features it provides: realtime formatting, and the “Format Document” implementation.