You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Actual behaviour: When I pass a fun lambda function to another function, the body of the lambda function is indented with 4 spaces when max-indent is explicitly set to two
Expected behaviour: The body is intended with two spaces
How to Reproduce
I have the followating OCaml code in the test.ml file:
letlwt_applyfres=Lwt.bind res (funr ->
f r;
res )
The .ocamlformat file is empty.
When I format the code with max-indent=2 and ocp-indent-compat flags, ocamlformat formats everything with two spaces consistently:
$ ocamlformat --max-indent=2 --ocp-indent-compat test.ml
let lwt_apply f res =
Lwt.bind res (fun r ->
f r;
res)
However, when I disable ocp-indent-compat, the fun lambda function is indented with 4 spaces (instead of expected 2) despite specifying max-indent=2:
$ ocamlformat --max-indent=2 --no-ocp-indent-compat test.ml
let lwt_apply f res =
Lwt.bind res (fun r ->
f r;
res)
In this trivial example, ocp-indent-compat affects only spacing, but in a bigger projects, setting this flag to true introduces lots of other undesired changes, so it would be great to have consistent 2 spaces formatting everywhere without ocp-indent-compat=false!
My system settings:
$ ocamlformat --version
0.26.2
I'm MacOS Sonoma 14.5 (but I also see this issue on Linux).
The text was updated successfully, but these errors were encountered:
The expected formatting is due to ocp-indent-compat and is the same regardless of the value of max-indent. max-indent is a very challenging option to implement and maintain and is known to not work well in many cases. Help is welcome on fixing this issue.
For context, the reason for this 4-indentation is to avoid small change to the code causing a large indentation change:
letlwt_applyfres=Lwt.bind res (funr ->
f r;
res)
letlwt_applyfres=Lwt.bind res (* Small change makes the argument list longer here *)
(funr ->
f r; (* Indentation of the possibly long fun body didn't change. *)
res)
Describe the bug
Actual behaviour: When I pass a
fun
lambda function to another function, the body of the lambda function is indented with 4 spaces whenmax-indent
is explicitly set to twoExpected behaviour: The body is intended with two spaces
How to Reproduce
I have the followating OCaml code in the
test.ml
file:The
.ocamlformat
file is empty.When I format the code with
max-indent=2
andocp-indent-compat
flags,ocamlformat
formats everything with two spaces consistently:However, when I disable
ocp-indent-compat
, thefun
lambda function is indented with 4 spaces (instead of expected 2) despite specifyingmax-indent=2
:In this trivial example,
ocp-indent-compat
affects only spacing, but in a bigger projects, setting this flag to true introduces lots of other undesired changes, so it would be great to have consistent 2 spaces formatting everywhere withoutocp-indent-compat=false
!My system settings:
I'm MacOS Sonoma 14.5 (but I also see this issue on Linux).
The text was updated successfully, but these errors were encountered: