Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Consistent" cond formatting #235

Closed
NoahTheDuke opened this issue Apr 20, 2022 · 4 comments
Closed

"Consistent" cond formatting #235

NoahTheDuke opened this issue Apr 20, 2022 · 4 comments

Comments

@NoahTheDuke
Copy link

Hey hey! Love the library so much.

Right now, cond (and related forms) will start each pair on a newline, attempt to put the then expression on the same line, and then place the then expression on the next line if it doesn't fit:

(cond
  (simple-check) (short-function-call)
  (and (much-more-complicated-check) (an-even-longer-check-that-is-too-long))
  (look-im-on-the-next-line)
  :else (another-short-call))

I would like if it, any time any then expression is placed on the next line, all then expressions are placed on the next lines:

(cond
  (simple-check)
  (short-function-call)
  (and (much-more-complicated-check) (an-even-longer-check-that-is-too-long))
  (look-im-on-the-next-line)
  :else
  (another-short-call))

Is this possible?

(I really wish clojure hadn't dropped the parentheses around pairs in cond and let and other binding forms lol.)

@kkinnear
Copy link
Owner

kkinnear commented May 2, 2022

Sorry to be slow to respond. I was away, and then wrapped up with another issue.

For what it is worth, I too think the extra parentheses around pairs in cond and let were not all that "extra".

I see what you want, and agree that it is a reasonable approach. There is no way to configure zprint to do that at present.

It turns out that zprint more or less does things in "order", so that finding out that the last thing in a cond had the second elements of the pair fit on the next line isn't so easy when doing the first pair in the cond. That said, the justification code does something like this, where if everything justifies correctly, it moves on, but if one element of the cond doesn't justify correctly, it will re-do the whole cond without justification. I'm thinking that perhaps I could use the same approach to see if all of the pairs fit on the same line, and if they didn't, then (if it was configured to do so), all of the pairs could be done as though all of the second elements didn't fit. This would be a more attractive an approach if the current code that handles the justification (or not) wasn't so complex and tangled up. Maybe an opportunity to clean it up?

Anyway, the bottom line is that I see this as a perfectly reasonable request, and will try to implement it soon. I don't know if I will get it into1.2.4 or the next release after that, but I'm definitely interested in making it happen.

Thanks for asking!

@NoahTheDuke
Copy link
Author

That's awesome and very kind of you, thank you!

kkinnear added a commit that referenced this issue Jun 8, 2022
kkinnear added a commit that referenced this issue Aug 2, 2022
@kkinnear
Copy link
Owner

kkinnear commented Aug 2, 2022

This is in 1.2.4, just out now. A nice idea, thanks for the suggestion.

From the CHANGELOG.md:

There are pairs in functions like cond, in maps, and in bindings. When the right hand part of the pair doesn't fit, it "flows" onto the next line. A new feature is now available to flow all of the right hand pairs onto the next line if any of them flow because they don't fit. This will certainly make things take more vertical space, but the additional consistency may make the pairs more easily distinguishable. You can enable this in any of the three possible places by setting :flow-all-if-any? true in :pair, :map, or :binding.

@NoahTheDuke
Copy link
Author

That's awesome, thank you for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants