$ ocamlformat --break-infix=fit-or-vertical --break-infix-before-func aaa.ml
let x =
create a |> modify_by b |> enhance_with c |> format_with d |> finalize_with e
–break-infix={wrap|fit-or-vertical}
…fit-or-vertical vertically breaks expressions if they do not fit on a single line.
But I find the notion of “fitting on a single line” not very nice to deal with. I find myself renaming functions to force formatter behaviour. Is there a better way?
$ ocamlformat --break-infix=fit-or-vertical --enable-outside-detected-project --impl <(echo -e "let x = create a |> modify_by b |> enhance_with c |> format_with d |> finalize_with e")
let x =
create a |> modify_by b |> enhance_with c |> format_with d |> finalize_with e
$ ocamlformat --break-infix=fit-or-vertical --enable-outside-detected-project --impl <(echo -e "let x = create a |> modify_by b |> enhance_with c |> format_with d |> do_finalize_with e")
let x =
create a
|> modify_by b
|> enhance_with c
|> format_with d
|> do_finalize_with e
# Playing with the line length is hazardous, see below:
$ ocamlformat --margin=16 --break-infix=fit-or-vertical --enable-outside-detected-project --impl <(echo -e "let x = create a |> modify_by b |> enhance_with c |> format_with d |> finalize_with e")
let x =
create a
|> modify_by b
|> enhance_with
c
|> format_with
d
|> finalize_with
e
This is not in the spirit of ocamlformat, which is to format equivalent syntax the same no matter how the user inputed it. I think it would be more reasonable to have an option to always break in front of |>.
Maybe it already exists ?