-
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
Separator before closing? #11
Comments
This might be a dupe of this issue: #2 |
If the trailing comma should always be printed no matter how the code gets formatted, it's much simpler than issue #2. Currently, one way of achieving this is: #use "topfind";;
#require "easy-format";;
open Easy_format
let add_trailing_string x s =
List (
("", "", "", { list with
space_after_opening = false;
space_after_separator = false;
space_before_closing = false;
wrap_body = `No_breaks }),
[x; Atom (s, atom)]
)
let () =
let element = Atom (String.make 90 'a', atom) in
let element_with_sticky_comma = add_trailing_string element "," in
let elements =
List (
("[", "", "]", list),
[element_with_sticky_comma; element_with_sticky_comma]
) in
Pretty.to_stdout elements Output:
It looks like a good idea to add a |
@mjambon for my usecase (printing JavaScript) we need to only print the trailing comma if we break. I tried to implement it with the above approach and using This is what i was using:
I did manage to implement with a hack (as suggested by @jordwalke, but not a good long term solution) where we insert a token in places we potental want trailing commas and then after printing from EasyFormat to string we find the instances of the token followed by a "\n" and replace with ",\n" otherwise strip it. It mostly works but does mess with the indentation a little since you remove chars after doing all the breaking. |
Is it possible to support adding a separator before closing so we can support trailing comma like this?
or
?
The text was updated successfully, but these errors were encountered: