cljstyle icon indicating copy to clipboard operation
cljstyle copied to clipboard

Support for vertical alignment?

Open robhanlon22 opened this issue 5 years ago • 8 comments

Clojure Mode for Emacs supports vertical alignment, as does Calva's formatter. Any thoughts on what it might take to add this to cljstyle?

robhanlon22 avatar May 14 '20 21:05 robhanlon22

Looks like cljfmt has had a WIP PR open for a while for this: https://github.com/weavejester/cljfmt/pull/77

robhanlon22 avatar May 14 '20 21:05 robhanlon22

I personally would like that to be doable both ways if possible (via config), turn a vertical style code base into "normal" alignement or the inverse.

mpenet avatar May 19 '20 07:05 mpenet

This does seem like it would be a good optional feature. You would need to write a formatting rule that looks for maps and various kinds of bindings with alternating pairs, then figure out how much whitespace needed to be between each binding to align with the longest one.

greglook avatar May 29 '20 16:05 greglook

Excellent. Here's the prior art:

  • Clojure Mode for Emacs: https://github.com/clojure-emacs/clojure-mode/blob/master/clojure-mode.el#L1246
  • Calva's formatter eventually just calls a fork of cljfmt: https://github.com/PEZ/cljfmt/blob/master/cljfmt/src/cljfmt/core.cljc#L497

robhanlon22 avatar May 29 '20 20:05 robhanlon22

I'll take a stab at this when I have some time.

robhanlon22 avatar May 29 '20 20:05 robhanlon22

Just kidding, @dparis is going to take a stab at it. I know this because I work with him. You're on the hook now, buddy.

robhanlon22 avatar May 29 '20 23:05 robhanlon22

Update: I've gotten a first pass implementation up on my fork https://github.com/dparis/cljstyle/pull/1/files

There are a few known cases that aren't working that I still need to fix, and I'd like to do a code quality pass, but overall seems to work decently. I'll submit a PR against upstream once those things are sorted out.

dparis avatar Jun 01 '20 22:06 dparis

Hi guys, i was just trying enable this in cljstyle and bumped in this issue and there is a help-needed label, is there a way to help in this?

felipetanios avatar Jun 19 '24 14:06 felipetanios