This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-04
Channels
- # adventofcode (154)
- # announcements (1)
- # babashka (8)
- # beginners (28)
- # bristol-clojurians (3)
- # calva (131)
- # cider (43)
- # clj-kondo (14)
- # clojure (135)
- # clojure-europe (1)
- # clojure-italy (7)
- # clojure-madison (1)
- # clojure-nl (6)
- # clojure-spec (8)
- # clojure-uk (90)
- # clojurescript (47)
- # core-async (9)
- # cryogen (4)
- # cursive (12)
- # datomic (9)
- # emacs (7)
- # fulcro (5)
- # graalvm (56)
- # joker (4)
- # juxt (1)
- # leiningen (6)
- # off-topic (62)
- # pathom (4)
- # pedestal (2)
- # reagent (2)
- # reitit (5)
- # ring (2)
- # schema (4)
- # shadow-cljs (133)
- # sql (38)
- # tools-deps (10)
- # vim (28)
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
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.
I'm working on a formatter that removes this kind of alignment. Most places I see it make the code worse.
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:
{: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 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.
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 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")]}