greglook / cljstyle

A tool for formatting Clojure code
Eclipse Public License 1.0
293 stars 39 forks source link

Support for vertical alignment? #47

Open robhanlon22 opened 4 years ago

robhanlon22 commented 4 years ago

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 commented 4 years ago

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

mpenet commented 4 years ago

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.

greglook commented 4 years ago

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.

robhanlon22 commented 4 years ago

Excellent. Here's the prior art:

robhanlon22 commented 4 years ago

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

robhanlon22 commented 4 years ago

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.

dparis commented 4 years ago

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.

felipetanios commented 2 months ago

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?