Skip to content

Commit

Permalink
Fix indent of 'fun -> function' arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Julow committed Oct 10, 2024
1 parent ef86c82 commit 0710547
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
14 changes: 0 additions & 14 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
5 changes: 3 additions & 2 deletions lib/Fmt_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
6 changes: 5 additions & 1 deletion lib/Params.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
3 changes: 2 additions & 1 deletion lib/Params.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0710547

Please sign in to comment.