add max-column-anchor-gap to align columns to the gap instead of collapsing on row with short keys - #425
Conversation
5a863c3 to
7d82f81
Compare
|
If I'm understanding this correctly, you're proposing a maximum column width size? Anything above the maximum width is separated by just a single space; anything equal to or below is padded as normal. Is that correct? |
7d82f81 to
038815a
Compare
Yes, that is correct. Its specifically this current behavior that I find backwards: |
|
In which case I think we want to call this something like |
That sounds good to me. I was trying to stay with the "gap" term since the flags are related. The "anchor" would be the longest key that is dragging the gap bigger. Max anchor gap would be the max the anchor could add a gap. |
da3b56d to
806e54d
Compare
|
@weavejester I added a text animation video to the description for clarity |
5abfa5b to
7d73ba2
Compare
|
Other than the previous comment, this looks fine. Once that comment is addressed I think we're ready to merge. |
7d73ba2 to
2f4affc
Compare
|
@weavejester Updated. I have one more related rule to follow up, if you want to wait to release them all in a group. I'm going to add a rule to break the link if it exceeds this max width rule. |
|
No problem, I can wait. This PR looks good, but I've noticed that the |
Add a new :max-column-alignment-width option for column alignment. Keys whose end column is at or within N participate in alignment; keys that end past column N receive a single space and are not padded.
2f4affc to
ab54188
Compare
@weavejester I added that in. Thanks for reviewing! |
| (defn- pad-to-position [zloc start-position {max-gap :max-column-alignment-gap | ||
| align-width :max-column-alignment-width}] |
There was a problem hiding this comment.
Could you wrap this at 80 characters? i.e.:
(defn- pad-to-position
[zloc start-position {max-gap :max-column-alignment-gap
align-width :max-column-alignment-width}]
@weavejester I can't remember if you want an issue per PR, so I included the details here. I can make it an issue if you prefer.
LLM notice
I have reviewed all of what is being submitted. The PR description was partially generated with llm to show the current and expected.
Problem
Here, I am not sure if this is a bug or a differene in expected behavior so I went with a new flag.
When
:max-column-alignment-gapis set, the alignment anchor is still the longest key in the form. Individual rows whose gap would exceed the limit fall back to a single space, but rows with medium-length keys are still extended all the way to the inflated anchor column. This produces inconsistent alignment: the shortest key falls back, medium keys over-extend, and the longest key (which caused the problem) sets the column for all of them.Current behavior
Config:
{:align-form-columns? true, :max-column-alignment-gap 5}Input:
Output —
long-namestays as anchor;afalls back (gap 9 > 5);abcdeandabcdefgextend unnecessarily to thelong-namecolumn:The same behavior affects maps with
:align-map-columns?.Solution
This PR does not change the behavior of
:max-column-alignment-gap. Instead it introduces a new flag,:max-column-anchor-gap, which applies the limit at anchor selection time rather than per row.When
:max-column-anchor-gap Nis set, cljfmt selects the largest key for which every shorter key would need at most N spaces to align. Keys longer than the chosen anchor are not padded.Expected behavior
Config:
{:align-form-columns? true, :max-column-anchor-gap 5}Composing both flags
The two flags are orthogonal and can be combined.
:max-column-anchor-gaprunsfirst to select a conservative anchor;
:max-column-alignment-gapthen appliesper-row fallback to the result.
Changes
:max-column-anchor-gapadded todefault-options(nil by default)column-start-positionapplies cascade demotion when:max-column-anchor-gapis setpad-to-positiongains a guard for keys wider than the demoted anchor, preventingtheir spacing from collapsing to zero
:max-column-alignment-gaptest-max-column-anchor-gapdeftest with form, map, and compose casesComparison
Screen.Recording.2026-07-26.at.2.20.02.PM.mov