This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-29
Channels
- # announcements (7)
- # asami (13)
- # babashka (22)
- # beginners (52)
- # calva (95)
- # clj-kondo (14)
- # cljs-dev (7)
- # clojars (5)
- # clojure (94)
- # clojure-austin (5)
- # clojure-dev (15)
- # clojure-europe (25)
- # clojure-nl (18)
- # clojure-uk (15)
- # clojuredesign-podcast (28)
- # clojurescript (63)
- # copenhagen-clojurians (1)
- # cursive (3)
- # datalevin (7)
- # datascript (13)
- # datomic (13)
- # duct (14)
- # emacs (24)
- # events (1)
- # fulcro (13)
- # graphql (7)
- # kaocha (4)
- # lambdaisland (6)
- # lsp (22)
- # music (5)
- # off-topic (24)
- # rdf (1)
- # re-frame (3)
- # reitit (9)
- # shadow-cljs (23)
- # sql (15)
- # testing (4)
- # tools-build (6)
- # vim (7)
- # vscode (7)
- # xtdb (21)
ooooh never heard of this
it looks simple/good
We just did that at my work to get all those editors to match, seems to work well so far
It should definitely be possible to make this happen (with some work). Cursive has some doc on matching Emacs: https://cursive-ide.com/userguide/formatting.html#matching-indentation-to-emacs
Since Calva uses cljfmt, the indentation rule for achieving Tonsky formatting is
:indents ^:replace {#"^\w" [[:inner 0]]}
It's quite controversial though, as this thread illustrates, https://clojureverse.org/t/clj-commons-building-a-formatter-like-gofmt-for-clojure/, so harmonizing formatting will always have to be on a per project/company level.
"tonsky" formatting disregards 10+y of Clojure history and all the muscle (visual?) memory one may have built in that period, so it seems unlikely that will happen. Honestly I remain surprised that people give so much attention to what amounts to a blog post. The good news is that cljfmt and emacs (clojure-mode / cider) are so close that they are practically the same. cljfmt is in use in clojure-lsp, calva, it's what us CIDER guys recommend. So it's as close as a workable/de-facto standard as it can be. Also zprint is an amazingly powerful/flexible formatter. From what I've been talking with the author, there's very cool stuff coming around the corner. My prediction is that if the situation will improve, it will be via great engineering and collaboration between tool makers. We can leave simplistic solutions to other communities - we have Lisp, we have rewrite-clj, there's no real reason to settle for less 🙂
@U45T93RA6 my sample size of 4 new-to-Clojure devs has this data: Two simple rules for formatting makes it very easy for them to see the pattern and to grok the code fast. Helps a lot with the "parentheses becomes invisible" step. Regular and consistent matters for this. They like that "right" is obvious, and easily verifiable. And easy to mechanically "fix up" if something goes off. I don't love Tonsky formatting. This I do love: It's a "one and done" conversation. We can move on and have one less concern to carry around mentally.
Agreed, had a similar experience with new people. A common mistake with the default formatting is being stingy with newlines, leading to bizarre looking code that drifts way too much to the right. By not requiring function argument alignment, Tonsky formatting helps a lot here. To me the objections people raise against Tonsky formatting seem very superficial, and you get over them real quick if you are actually wanting to solve the problem of supporting 3 different editors. To me these minor syntax quibbles don't even come close to outweighing the cross-editor formatting problem. I understand the people who don't want to get on-board though, I could see just sticking with the current standards making sense if you have a smaller team, or everyone just uses the same/similar editors. I could also see zprint making sense if you don't need to support windows (last time I checked, they only offer a jar for windows).
We got the same problem as a team and we use zprint
to post-process and reconcile 😄
tonsky style basically complects macro calls and function calls. It makes Clojure look less like a language, and more like a bunch of unstructured sexprs.
In many other programming languages, you can easily, visually differentiate language constructs from function calls (be it via indentation, or via distinct delimiters e.g. end
/`}`).
I don't want to lose that - it's an important tool for understanding the semantics of code. Especially in a language featuring macros i.e. syntax-transformation is not only common but also extensible.
Which also explains why this problem isn't present in other languages - they don't have macros, so a formatter for them perceives a 'closed world' which is easier to process.
Honestly, I think the “one style to rule them all” for Clojure is a ship that has sailed at this point. JS and Python have options for that now (prettier/black) which have seen pretty good uptake, but it will never be as universal as gofmt. So as long as there are decent options such that each team can make editors coincide, that’s probably the best we can hope for.
That said, if I ever make my own language it will have a gofmt-like thing out of the box, even if it uses sexprs.
@U08JKUHA9 @U9E8C7QRJ is it true what I said above about what is enough to implement Tonsky formatting in Calva? I'd like to update the information about this in the Calva docs to be less defensive about it if I can. So if you know what rules it takes, please let me know. https://calva.io/formatting/#indentation-rules
@U0ETXRFEW We ended up with :indents _^:replace_ {#"" [[:inner 0]]}
almost the same (not sure if it is functionally different from what you had - it wasn't from me). Anyway that has worked fine, I haven't seen any style clashes since then.
[necrobump] Have any of you managed to set up Tonsky formatting for clojure-lsp/cljfmt, or is :indents ^:replace {#"^\w" [[:inner 0]]}
still the best known solution?
https://editorconfig.org/ I've never used this project but it seems like its intended purpose is to reduce the pain of conflicting defaults
clojure indentation styles are a little more complicated than what that supports, unfortunately
[necrobump] Have any of you managed to set up Tonsky formatting for clojure-lsp/cljfmt, or is :indents ^:replace {#"^\w" [[:inner 0]]}
still the best known solution?