Fork me on GitHub

Formatting: does anyone know of a vim way/plugin to format forms into tables? For example looks like this:

 {camel-snake-kebab {:mvn/version "0.4.0"} {:mvn/version "7.4.1.jre8"}
  org.clojure/tools.namespace {:mvn/version "0.3.1"}}}
into something like
 {camel-snake-kebab                  {:mvn/version "0.4.0"} {: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:

herald11:12:02 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)

👍 8

if you don't want a dedicated plugin you can use column -t

👍 4

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


A job for tree-sitter? "Align according to type of element at <cword>, in the local sub-tree"


@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


Just curious, how should this code look:

 [(when some-boolean? "class-a")
  (when other "class-b")
  (when xyza-fooo "class-c")]}
 [(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)




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"} {:mvn/version "7.4.1.jre8"}
        org.clojure/tools.namespace        {:mvn/version "0.3.1"}}}
{: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.