Skip to content

Commit

Permalink
to fixup with previous
Browse files Browse the repository at this point in the history
  • Loading branch information
EmileTrotignon committed Jul 25, 2024
1 parent 5598472 commit 69ed0c1
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/Params.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ let is_unlabelled_arg args exp =
| Labelled _, _ | Optional _, _ -> false )
args

let is_arg args exp =
List.exists
~f:(function
| Nolabel, x -> phys_equal x exp
| Labelled _, x | Optional _, x -> phys_equal x exp )
args

let ctx_is_infix = function
| Exp {pexp_desc= Pexp_infix ({txt= ":="; _}, _, _); _} -> false
| Exp {pexp_desc= Pexp_infix _; _} -> true
Expand All @@ -47,12 +54,18 @@ let ctx_is_beginend = function
| Exp {pexp_desc= Pexp_beginend _; _} -> true
| _ -> false

let ctx_is_apply_and_exp_is_arg ~ctx ctx0 =
let ctx_is_apply_and_exp_is_unlabelled_arg ~ctx ctx0 =
match (ctx, ctx0) with
| Exp exp, Exp {pexp_desc= Pexp_apply (_, args); _} ->
is_unlabelled_arg args exp
| _ -> false

let ctx_is_apply_and_exp_is_arg ~ctx ctx0 =
match (ctx, ctx0) with
| Exp exp, Exp {pexp_desc= Pexp_apply (_, args); _} ->
is_arg args exp
| _ -> false

(** [ctx_is_let ~ctx ctx0] checks whether [ctx0] is a let binding containing
[ctx]. *)
let ctx_is_let ~ctx = function
Expand Down Expand Up @@ -140,16 +153,17 @@ module Exp = struct
let box_fun_expr (c : Conf.t) ~ctx0 ~ctx ~parens:_ ~has_label =
let indent =
if ctx_is_infix ctx0 then if ocp c && has_label then 2 else 0
else if ctx_is_beginend ctx0 then 2
else if ctx_is_beginend ctx0 then 2
else
match c.fmt_opts.function_indent_nested.v with
| `Always -> c.fmt_opts.function_indent.v
| _ ->
if ctx_is_let ~ctx ctx0 then
if c.fmt_opts.let_binding_deindent_fun.v then 1 else 0
else if ocp c then
if ctx_is_apply_and_exp_is_arg ~ctx ctx0 then 4 else 2
else 4
if ctx_is_apply_and_exp_is_unlabelled_arg ~ctx ctx0 then 4 else 2
else if ctx_is_apply_and_exp_is_arg ~ctx ctx0 then 4
else 2
in
let name = "Params.box_fun_expr" in
match ctx0 with Str _ -> hvbox ~name indent | _ -> hovbox ~name indent
Expand Down

0 comments on commit 69ed0c1

Please sign in to comment.