vim

For discussion on all things (neo)vim.
niclasnilsson 2019-12-04T11:12:23.012600Z

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-VHbJlQ

uosl 2019-12-04T11:42:02.015200Z

https://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)

2πŸ‘
tmt 2019-12-04T11:43:18.015900Z

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

1πŸ‘
sheluchin 2019-12-04T12:34:57.016100Z

I'm new to Clojure - this is actually the first set of tests I'm writing. It looks like calling load-file is a common way to execute tests while developing as long as there's a call to run-tests in the file. I left a comment with a bit more info here: https://github.com/tpope/vim-fireplace/issues/369#issuecomment-561620687 Example src/test/sheluchin/poker/core_test.cljs:

(ns sheluchin.poker.core-test
  (:require
    [cljs.test :refer-macros [deftest is run-tests]]))

(deftest test-numbers
  (is (= 1 1)))

(run-tests)
Loading it prints the results to the REPL.

dave 2019-12-04T15:16:58.020800Z

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 2019-12-06T19:09:38.040500Z

πŸ’‘

niclasnilsson 2019-12-04T15:29:21.023100Z

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

dominicm 2019-12-04T15:57:15.023700Z

Cljfmt has an open PR to add this

dominicm 2019-12-04T15:57:43.024500Z

I'm working on a formatter that removes this kind of alignment. Most places I see it make the code worse.

dave 2019-12-04T16:03:25.025Z

i'm well aware that dominic and i are adversaries in this debate πŸ˜„

dave 2019-12-04T16:04:00.025700Z

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

dominicm 2019-12-04T16:43:25.025800Z

Marmite :D

dominicm 2019-12-04T16:44:58.025900Z

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.

dave 2019-12-04T16:51:28.026300Z

i prefer the former

dominicm 2019-12-04T16:52:17.027200Z

+πŸ‘

dave 2019-12-04T16:52:20.027300Z

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

dominicm 2019-12-04T16:52:57.027400Z

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.

dominicm 2019-12-04T16:53:57.027700Z

there's going to be config for custom macros (e.g. manifold's let's)

dave 2019-12-04T17:07:54.027900Z

excellent

dave 2019-12-04T17:08:25.028400Z

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

dave 2019-12-04T17:09:26.029300Z

like if some of the requires have :refer and some have :as and some have both, what do you do?

dave 2019-12-04T17:09:33.029600Z

i'm not even consistent in the way that i do it

dave 2019-12-04T17:09:52.030Z

i basically just want the :as foo aliases to be vertically aligned

niclasnilsson 2019-12-04T21:34:54.031700Z

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

niclasnilsson 2019-12-04T21:35:46.032700Z

I tried the examples above in VSCode with Calva and it’s new experimental formatting, and the result turned out like this:

niclasnilsson 2019-12-04T21:35:58.033100Z

{: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")]}

dominicm 2019-12-04T22:04:42.035400Z

I believe they're using a cljfmt fork

dominicm 2019-12-04T22:05:05.035900Z

Branched from the vertical alignment fork.