Skip to content

Commit ae7eeef

Browse files
authored
Restore indentation of -> (#2398)
* Restore indentation of fun arrow This is the formatting of 0.25.1. * Improve indent of fun args preceded by a label The arguments must be indented more to avoid them aligning with the `fun` and `->` in case of a break: let () = very_long_function_name ~very_long_argument_label:(* foo *) (fun very_long_argument_name_one very_long_argument_name_two very_long_argument_name_three -> () )
1 parent 0e1ffb3 commit ae7eeef

File tree

10 files changed

+88
-20
lines changed

10 files changed

+88
-20
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
- Consistent indentation of `@@ let+ x = ...` (#2315, #2396, @Julow)
1919
- Remove double parenthesis around tuple in a match (#2308, @Julow)
2020
- Consistent indentation of `fun (type a) ->` that follow `fun x ->` (#2294, @Julow)
21-
- Avoid adding breaks inside `~label:(fun` and base the indentation on the label. (#2271, #2291, #2293, #2298, @Julow)
21+
- Improve indentation of `~label:(fun` (#2271, #2291, #2293, #2298, #2398, @Julow)
2222
- Fix non-stabilizing comments attached to private/virtual/mutable keywords (#2272, #2307, @gpetiot, @Julow)
2323
- Fix formatting of comments in "disable" chunks (#2279, @gpetiot)
2424
- Fix indentation of trailing double-semicolons (#2295, @gpetiot)

lib/Conf_decl.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,8 @@ let removed_option ~names ~since ~msg =
436436
let update store ~config ~from:new_from ~name ~value ~inline =
437437
List.find_map store
438438
~f:(fun
439-
(Pack {names; parse; update; allow_inline; get_value; to_string; _}) ->
439+
(Pack {names; parse; update; allow_inline; get_value; to_string; _})
440+
->
440441
if List.exists names ~f:(String.equal name) then
441442
if inline && not allow_inline then
442443
Some (Error (Error.Misplaced (name, value)))

lib/Fmt_ast.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,10 +1352,11 @@ and fmt_fun ?force_closing_paren
13521352
else noop
13531353
in
13541354
let (label_sep : s), break_fun =
1355-
(* Break between the label and the fun to avoid ocp-indent's
1356-
alignment. *)
1355+
(* Break between the label and the fun to avoid ocp-indent's alignment.
1356+
If a label is present, arguments should be indented more than the
1357+
arrow and the eventually breaking [fun] keyword. *)
13571358
if c.conf.fmt_opts.ocp_indent_compat.v then (":@,", fmt "@;<1 2>")
1358-
else (":", fmt "@ ")
1359+
else (":", if has_label then fmt "@;<1 2>" else fmt "@ ")
13591360
in
13601361
hovbox_if box 2
13611362
( wrap_intro
@@ -1366,8 +1367,8 @@ and fmt_fun ?force_closing_paren
13661367
$ fmt "fun" $ break_fun
13671368
$ hvbox 0
13681369
( fmt_attributes c ast.pexp_attributes ~suf:" "
1369-
$ fmt_fun_args c xargs $ fmt_opt fmt_cstr $ fmt "@ ->" )
1370-
) ) )
1370+
$ fmt_fun_args c xargs $ fmt_opt fmt_cstr
1371+
$ fmt "@;<1 -2>->" ) ) ) )
13711372
$ body $ closing
13721373
$ Cmts.fmt_after c ast.pexp_loc )
13731374

test/passing/tests/break_fun_decl-fit_or_vertical.ml.ref

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,20 @@ class type ffffffffffffffffffff = object
116116
-> cccccccccccccccccccccc
117117
-> dddddddddddddddddddddd
118118
end
119+
120+
let _ =
121+
fun (module Store : Irmin.Generic_key.S with type repo = repo)
122+
(module Store : Irmin.Generic_key.S with type repo = repo) ->
123+
body
124+
125+
let _ =
126+
f
127+
(fun
128+
(module Store : Irmin.Generic_key.S with type repo = repo)
129+
(module Store : Irmin.Generic_key.S with type repo = repo)
130+
-> body )
131+
132+
let f
133+
(module Store : Irmin.Generic_key.S with type repo = repo)
134+
(module Store : Irmin.Generic_key.S with type repo = repo) =
135+
body

test/passing/tests/break_fun_decl-smart.ml.ref

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,20 @@ class type ffffffffffffffffffff = object
110110
-> cccccccccccccccccccccc
111111
-> dddddddddddddddddddddd
112112
end
113+
114+
let _ =
115+
fun (module Store : Irmin.Generic_key.S with type repo = repo)
116+
(module Store : Irmin.Generic_key.S with type repo = repo) ->
117+
body
118+
119+
let _ =
120+
f
121+
(fun
122+
(module Store : Irmin.Generic_key.S with type repo = repo)
123+
(module Store : Irmin.Generic_key.S with type repo = repo)
124+
-> body )
125+
126+
let f
127+
(module Store : Irmin.Generic_key.S with type repo = repo)
128+
(module Store : Irmin.Generic_key.S with type repo = repo) =
129+
body

test/passing/tests/break_fun_decl-wrap.ml.ref

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,19 @@ class type ffffffffffffffffffff = object
9292
-> cccccccccccccccccccccc
9393
-> dddddddddddddddddddddd
9494
end
95+
96+
let _ =
97+
fun (module Store : Irmin.Generic_key.S with type repo = repo)
98+
(module Store : Irmin.Generic_key.S with type repo = repo) ->
99+
body
100+
101+
let _ =
102+
f
103+
(fun
104+
(module Store : Irmin.Generic_key.S with type repo = repo)
105+
(module Store : Irmin.Generic_key.S with type repo = repo)
106+
-> body )
107+
108+
let f (module Store : Irmin.Generic_key.S with type repo = repo)
109+
(module Store : Irmin.Generic_key.S with type repo = repo) =
110+
body

test/passing/tests/break_fun_decl.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,19 @@ class type ffffffffffffffffffff = object
9292
-> cccccccccccccccccccccc
9393
-> dddddddddddddddddddddd
9494
end
95+
96+
let _ =
97+
fun (module Store : Irmin.Generic_key.S with type repo = repo)
98+
(module Store : Irmin.Generic_key.S with type repo = repo) ->
99+
body
100+
101+
let _ =
102+
f
103+
(fun
104+
(module Store : Irmin.Generic_key.S with type repo = repo)
105+
(module Store : Irmin.Generic_key.S with type repo = repo)
106+
-> body )
107+
108+
let f (module Store : Irmin.Generic_key.S with type repo = repo)
109+
(module Store : Irmin.Generic_key.S with type repo = repo) =
110+
body

test/passing/tests/js_source.ml.ref

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9883,7 +9883,7 @@ let () =
98839883
very_long_argument_name_one
98849884
very_long_argument_name_two
98859885
very_long_argument_name_three
9886-
-> ())
9886+
-> ())
98879887
;;
98889888

98899889
let () =

test/passing/tests/labelled_args-414.ml.ref

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ let _ =
55
let () =
66
very_long_function_name
77
~very_long_argument_label:(fun
8-
very_long_argument_name_one
9-
very_long_argument_name_two
10-
very_long_argument_name_three
8+
very_long_argument_name_one
9+
very_long_argument_name_two
10+
very_long_argument_name_three
1111
-> () )
1212

1313
let () =
1414
very_long_function_name
1515
~very_long_argument_label:(* foo *)
1616
(fun
17-
very_long_argument_name_one
18-
very_long_argument_name_two
19-
very_long_argument_name_three
17+
very_long_argument_name_one
18+
very_long_argument_name_two
19+
very_long_argument_name_three
2020
-> () )

test/passing/tests/labelled_args.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ let _ =
55
let () =
66
very_long_function_name
77
~very_long_argument_label:(fun
8-
very_long_argument_name_one
9-
very_long_argument_name_two
10-
very_long_argument_name_three
8+
very_long_argument_name_one
9+
very_long_argument_name_two
10+
very_long_argument_name_three
1111
-> () )
1212

1313
let () =
1414
very_long_function_name
1515
~very_long_argument_label:(* foo *)
1616
(fun
17-
very_long_argument_name_one
18-
very_long_argument_name_two
19-
very_long_argument_name_three
17+
very_long_argument_name_one
18+
very_long_argument_name_two
19+
very_long_argument_name_three
2020
-> () )

0 commit comments

Comments
 (0)