diff --git a/TODO.md b/TODO.md index dbfa7a3771..c0b9663761 100644 --- a/TODO.md +++ b/TODO.md @@ -73,17 +73,3 @@ Argument-list wrapping at toplevel in aux versions ``` - -`fun -> function` argument - -``` - List.fold_left - (fun acc -> function -- | List [ Atom name; Atom value ] -> (name, value) :: acc -- | _ -> acc) -+ | List [ Atom name; Atom value ] -> (name, value) :: acc -+ | _ -> acc) - [] - l - |> List.rev -``` diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index cc9f5b8557..d01aae62ba 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -1538,8 +1538,9 @@ and fmt_function ?(last_arg = false) ?force_closing_paren ~ctx ~ctx0 | args, typ -> ( fmt_fun_args_typ args typ $ space_break , [] - , hvbox (Params.Indent.docked_function_after_fun c.conf ~ctx0) - ) + , hvbox + (Params.Indent.docked_function_after_fun c.conf ~parens + ~ctx0 ~ctx ) ) in let function_ = let pre = diff --git a/lib/Params.ml b/lib/Params.ml index 8c1434437f..7844c9f1d3 100644 --- a/lib/Params.ml +++ b/lib/Params.ml @@ -905,13 +905,17 @@ module Indent = struct let fun_args c = if ocp c then 6 else 4 - let docked_function_after_fun (c : Conf.t) ~ctx0 = + let docked_function_after_fun (c : Conf.t) ~parens ~ctx0 ~ctx = match ctx0 with | Str _ -> (* Cases must be 2-indented relative to the [let], even when [let_binding_deindent_fun] is on. *) if c.fmt_opts.let_binding_deindent_fun.v then 1 else 0 | _ when ctx_is_infix ctx0 -> 0 + | _ when ocp c -> ( + match ctx_is_apply_and_exp_is_arg ~ctx ctx0 with + | Some (_, _, false) when parens -> (* Not last argument *) 3 + | _ -> 2 ) | _ -> 2 let fun_args_group (c : Conf.t) ~lbl exp = diff --git a/lib/Params.mli b/lib/Params.mli index b83463fb71..803172821a 100644 --- a/lib/Params.mli +++ b/lib/Params.mli @@ -232,7 +232,8 @@ module Indent : sig val fun_type_annot : Conf.t -> int - val docked_function_after_fun : Conf.t -> ctx0:Ast.t -> int + val docked_function_after_fun : + Conf.t -> parens:bool -> ctx0:Ast.t -> ctx:Ast.t -> int val fun_args_group : Conf.t -> lbl:arg_label -> expression -> int