This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-13
Channels
- # beginners (36)
- # boot (1)
- # cider (4)
- # cljsrn (2)
- # clojure (137)
- # clojure-brasil (3)
- # clojure-czech (3)
- # clojure-italy (17)
- # clojure-nl (8)
- # clojure-spec (7)
- # clojure-uk (153)
- # clojurescript (84)
- # data-science (2)
- # datascript (13)
- # datomic (30)
- # editors (64)
- # emacs (22)
- # events (6)
- # figwheel (26)
- # fulcro (7)
- # hoplon (5)
- # jobs (5)
- # jobs-discuss (57)
- # keechma (3)
- # leiningen (4)
- # luminus (1)
- # midje (2)
- # off-topic (26)
- # portkey (18)
- # re-frame (4)
- # reagent (10)
- # ring-swagger (3)
- # shadow-cljs (135)
- # spacemacs (5)
- # sql (14)
- # tools-deps (125)
@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?
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
(or
this
that)
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.
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.
Formatting is one of those things which seems incredibly simple, until you actually do it….
Relevant: http://journal.stuffwithstuff.com/2015/09/08/the-hardest-program-ive-ever-written/
great post! I really like Bob Nystrom’s writing.
@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”
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.
just to clarify, I’ve preferred the “as-you-type” output in every case, so it’s working great for me in that regard
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 ?
Hi there! And @pez, I’m a little bit out of context reading this from the thread, let me check the conversation on the channel.
This particular thread is about where the conversation started in the channel: that Calva and Calva Formatter disagrees about some formatting. So, when Calva has helped you get all new lines indented and carefully tried to honor some one-indent-form guidelines, and you format the document, things are reindented differently, and in particular, one-indents are thrown out the window.
Looking at cljfmt
documentation, it looks like we could try to tweak a few knobs, like this one for example :cljfmt {:indents ^:replace {#".*" [[:inner 0]]}}
> If you want to override all existing indents, instead of just supplying new indents that are merged with the defaults, you can use the :replace hint:
Changing some cljfmt (that’s the formatting library that Calva uses) knobs might work, but it would even better to actually use cljfmt APIs to format as you type.
But I don’t know if there’s such API, I need to check the code.
I was actually going to try use cljfmt for ontype formatting for this very reason, I am sick of the formatting wars and it does not feel good to be publishing extensions that engage in this war against each other! 😃
So if we can pour the one-indent-forms from Calva into that regexp, that will be very awesome. I might try today!
@pez yeah, it’s great - it comes up on Hacker News from time to time, and generally has interesting comments too.
@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
See that discussion, and various linked issues, e.g: https://github.com/clojure-emacs/clojure-mode/issues/266, https://github.com/clojure-emacs/clojure-mode/issues/265, https://github.com/clojure-emacs/clojure-mode/issues/235
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
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”
also, at some point your codebase looks like what it looks like. can't just go changing it whenever you open a file
i think the single comment ;
is brutal in emacs. i think that is hard coded to go over to the right margin
Right. I’m actually totally in favour of prescribed language formatting these days ala gofmt
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” 🙂
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
Lots of Cursive is really fun to work on, but lots is not too, you’re right (leiningen, I’m looking at you)
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.
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 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.