Formatting: does anyone know of a vim way/plugin to format forms into tables? For example looks like this:
{:deps
{camel-snake-kebab {:mvn/version "0.4.0"}
com.microsoft.sqlserver/mssql-jdbc {:mvn/version "7.4.1.jre8"}
org.clojure/tools.namespace {:mvn/version "0.3.1"}}}
into something like
{:deps
{camel-snake-kebab {:mvn/version "0.4.0"}
com.microsoft.sqlserver/mssql-jdbc {:mvn/version "7.4.1.jre8"}
org.clojure/tools.namespace {:mvn/version "0.3.1"}}}
Not just for deps.edn obviously, but for any forms. I got inspiration from this talk, and would like some support for this in (neo)vim: https://www.youtube.com/watch?v=b5UK-VHbJlQhttps://github.com/junegunn/vim-easy-align
It can be complcated to use imo. You can align the forms in your example with gaip
(note that the last character is pressing the space key)
if you don't want a dedicated plugin you can use column -t
https://stackoverflow.com/questions/1229900/reformat-in-vim-for-a-nice-column-layout
i've been desperate to do this sort of thing in a way that's fully knowledgeable about clojure, for a long time now vim alignment plugins get you most of the way there, but they can't possibly get it right 100% of the time without parsing EDN. there are edge cases like strings containing spaces that they can't really address, as far as i'm aware i haven't dug much into cljfmt and friends... it's possible that an existing formatter can provide this, but i also know that it's a controversial preference, so maybe it isn't supported π i'm half-tempted to take a stab at writing a little utility that does this, maybe by leveraging https://github.com/borkdude/edamame
π‘
@dave, I agree fully. I donβt think itβs possible to get it right without the consept of clojure forms. Itβs probably controversial, but within a project, you decide for yourself, and I seriously think it would make reading some types of code/data much faster.
Cljfmt has an open PR to add this
I'm working on a formatter that removes this kind of alignment. Most places I see it make the code worse.
i'm well aware that dominic and i are adversaries in this debate π
it's great to hear that there is movement to add this in cljfmt. i'm sure it will be configurable, because some people love it, some people hate it
Marmite :D
Just curious, how should this code look:
{:class
[(when some-boolean? "class-a")
(when other "class-b")
(when xyza-fooo "class-c")]}
or
{:class
[(when some-boolean? "class-a")
(when other "class-b")
(when xyza-fooo "class-c")]}
As far as I'm aware, there's no obvious way to write a tool that produces the latter. You have to inspect the form and somehow decide that nested things should be aligned.i prefer the former
+π
i like to do the vertical alignment thing in these cases: β’ bindings (doseq, let, etc.) β’ maps β’ namespace declarations and maybe others, too, that i'm not thinking of
oh, that doesn't work for this client. You get the point π Those are pretty toolable places, with the exception of ns decls, I believe that cljfmt is targetting all of them.
there's going to be config for custom macros (e.g. manifold's let
's)
excellent
i can see how the ns decl case would be difficult to support. it isn't clear-cut how to vertically align those, assuming you want to in the first place
like if some of the requires have :refer
and some have :as
and some have both, what do you do?
i'm not even consistent in the way that i do it
i basically just want the :as foo
aliases to be vertically aligned
I prefer the aligned one in quite a few cases, and the more βdataβ it is, the more natural it feels (think tables that happens to have code snippets in them for instance).
I tried the examples above in VSCode with Calva and itβs new experimental formatting, and the result turned out like this:
{:deps {camel-snake-kebab {:mvn/version "0.4.0"}
com.microsoft.sqlserver/mssql-jdbc {:mvn/version "7.4.1.jre8"}
org.clojure/tools.namespace {:mvn/version "0.3.1"}}}
and
{:class [(when some-boolean? "class-a")
(when other "class-b")
(when xyza-fooo "class-c")]}
I believe they're using a cljfmt fork
Branched from the vertical alignment fork.