Fork me on GitHub
Cora (she/her)21:03:19

I really wish emacs + cursive + calva indentation all matched

👏 3

I'm (again) on a mission to get Tonsky formatting everywhere.

Cora (she/her)22:03:10

ooooh never heard of this

Cora (she/her)22:03:14

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:


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,, so harmonizing formatting will always have to be on a per project/company level.

👀 1

"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.

👍 2

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.


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

🙏 1

[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?

respatialized21:03:04 I've never used this project but it seems like its intended purpose is to reduce the pain of conflicting defaults

eccentric J00:03:58

Been using it for about 5 years at this point, very useful

eccentric J00:03:51

oh but not for clojure though

Cora (she/her)21:03:01

clojure indentation styles are a little more complicated than what that supports, unfortunately

😕 1

Is there any community out there like this one, but for Java?

👀 1

[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?