-
Notifications
You must be signed in to change notification settings - Fork 16
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
Ability to include and customize "Trailing separators" #2
Comments
I don't know how we can achieve val print_if_newline : unit -> unit "Executes the next formatting command if the preceding line has just been split. Otherwise, ignore the next formatting command." We'd like to print something before the decision to print a newline is made. It would be problematic if what we want to print is too long. |
Yes, I agree. Your concern is that the decision to break doesn't take into account the length of the separator itself? You could have a clarification that "print trailing separator only if break" might make line length maximums more of a "target" than a "maximum". It seems much better than whatever hacks I would come up with otherwise. |
For posterity, I thought I'd add one more use case here: Variant types: You may only want to include the leading bar if the line breaks. type suit = Spades | Diamonds | Hearts | Clubs type suit =
| Spades
| Diamonds
| Hearts
| Clubs |
Summary:Per request of @jberdine, we no longer require the final semicolon. There's a small tradeoff that had to be made (no punned, single item records) - but that case is very rare, and would surely be caught by the type system. I also took the opportunity to start a clean directory of type checked formatting test cases. Many bugs in parsing/printing would be caught by simple type checking of the AST. Thanks for the suggesion, Josh. I like this much better. The next step is to make it so when pretty printing, the final semicolon is ommitted. Similarly, it is easy to make it such that the final item in a module/signature does not require a semicolon. Test Plan:Added type-checked formatting tests. Reviewers:@jberdine, @cristianoc CC:
Am I overlooking something, or is the situation for printing leading separators only after line breaks possible using Would it be possible to hack up an implementation of |
@jordwalke @jberdine I only mentioned |
@jberdine |
Looking into this problem. Another thing maybe we can do is to temporarily overwrite the "out_newline" function only when we are printing the last item of a list. |
It would be great to have a few features for specifying if separators should be included in the "trailing" portion of the list.
A couple of options:
``Trailing_separator_never`
``Trailing_separator_always`
And
``Trailing_separator_if_breaks`
You mentioned that
Trailing_separator_always
could be accomplished via wrapping in anAtom
. I will try to confirm that. But I'm not sure how I would accomplishTrailing_separator_if_breaks
.The text was updated successfully, but these errors were encountered: