@@ -1494,7 +1494,7 @@ and fmt_indexop_access c ctx ~fmt_atrs ~has_attr ~parens x =
14941494
14951495(* * Format a [Pexp_function]. [wrap_intro] wraps up to after the [->] and is
14961496 responsible for breaking. *)
1497- and fmt_function ?(last_arg = false ) ?force_closing_paren ~ctx ~ctx0
1497+ and fmt_function ?(last_arg = false ) ?force_closing_paren ~ctx ~ctx0 ? pro
14981498 ~wrap_intro ?box :(should_box = true ) ~label ?(parens = false ) ?ext ~attrs
14991499 ~loc c (args, typ, body) =
15001500 let should_box =
@@ -1637,13 +1637,20 @@ and fmt_function ?(last_arg = false) ?force_closing_paren ~ctx ~ctx0
16371637 wrap (fits_breaks " (" " " ) (fits_breaks " )" " " )
16381638 else Fn. id
16391639 in
1640+ let pro_outer, pro_inner =
1641+ let pro = fmt_opt pro in
1642+ if Params.Exp. function_inner_pro ~has_cmts_outer ~ctx0 then (noop, pro)
1643+ else (pro, noop)
1644+ in
16401645 let body =
16411646 let pro =
16421647 wrap_intro
1643- (hvbox_if has_cmts_outer 0
1644- ( cmts_outer
1645- $ Params.Exp. box_fun_decl ~ctx0 c.conf
1646- (fmt_label label label_sep $ cmts_inner $ opn_paren $ head) ) )
1648+ ( pro_outer
1649+ $ hvbox_if has_cmts_outer 0
1650+ ( cmts_outer
1651+ $ Params.Exp. box_fun_decl ~ctx0 c.conf
1652+ ( pro_inner $ fmt_label label label_sep $ cmts_inner
1653+ $ opn_paren $ head ) ) )
16471654 in
16481655 body ~pro $ cls_paren
16491656 in
@@ -1911,17 +1918,17 @@ and fmt_match c ?pro ?eol ~loc ~parens ?ext ctx xexp cs e0 keyword =
19111918 let cmts_before = Cmts. fmt_before c ?eol loc in
19121919 let ctx0 = xexp.ctx in
19131920 let indent = Params. match_indent c.conf ~parens ~ctx: ctx0 in
1914- let pro_outside_parens, pro_inside_parens =
1921+ let pro_outer, pro_inner =
19151922 let pro = fmt_opt pro in
1916- if Params.Exp. box_pro_with_match ~ctx0 ~parens then (noop, pro)
1923+ if Params.Exp. match_inner_pro ~ctx0 ~parens then (noop, pro)
19171924 else (pro, noop)
19181925 in
19191926 hvbox indent
1920- ( cmts_before $ pro_outside_parens
1927+ ( cmts_before $ pro_outer
19211928 $ Params.Exp. wrap c.conf ~parens ~disambiguate: true
19221929 @@ Params.Align. match_ c.conf ~xexp
19231930 @@ ( hvbox 0
1924- ( hvbox 0 (pro_inside_parens $ keyword)
1931+ ( hvbox 0 (pro_inner $ keyword)
19251932 $ fmt_extension_suffix c ext
19261933 $ fmt_attributes c xexp.ast.pexp_attributes
19271934 $ break 1 2
@@ -2358,11 +2365,10 @@ and fmt_expression c ?(box = true) ?(pro = noop) ?eol ?parens
23582365 $ cut_break $ str " ." $ fmt_longident_loc c lid $ fmt_atrs ) )
23592366 | Pexp_function (args , typ , body ) ->
23602367 let wrap_intro intro =
2361- hovbox ~name: " fmt_expression | Pexp_function" 2 (pro $ intro)
2362- $ space_break
2368+ hovbox ~name: " fmt_expression | Pexp_function" 2 intro $ space_break
23632369 in
2364- fmt_function ~wrap_intro ~box ~ctx ~ctx0 ~label: Nolabel ~parens ?ext
2365- ~attrs: pexp_attributes ~loc: pexp_loc c (args, typ, body)
2370+ fmt_function ~pro ~ wrap_intro ~box ~ctx ~ctx0 ~label: Nolabel ~parens
2371+ ?ext ~attrs: pexp_attributes ~loc: pexp_loc c (args, typ, body)
23662372 | Pexp_ident {txt; loc} ->
23672373 let outer_parens = has_attr && parens in
23682374 pro
@@ -2565,7 +2571,7 @@ and fmt_expression c ?(box = true) ?(pro = noop) ?eol ?parens
25652571 && c.conf.fmt_opts.break_cases.v <> `Vertical ) ->
25662572 let cmts_before = Cmts. fmt_before c ?eol pexp_loc in
25672573 let pro_outer, pro_inner =
2568- if Params.Exp. box_pro_with_match ~ctx0 ~parens then (noop, pro)
2574+ if Params.Exp. match_inner_pro ~ctx0 ~parens then (noop, pro)
25692575 else (pro, noop)
25702576 in
25712577 (* side effects of Cmts.fmt_before before [fmt_pattern] is important *)
@@ -2921,11 +2927,11 @@ and fmt_beginend c ?(box = true) ?(pro = noop) ~ctx ~fmt_atrs ~ext
29212927 let begin_ = str " begin" $ fmt_extension_suffix c ext $ fmt_atrs
29222928 and end_ = str " end" in
29232929 match e.pexp_desc with
2924- | Pexp_match _ | Pexp_try _ ->
2930+ | Pexp_match _ | Pexp_try _ | Pexp_function _ ->
29252931 pro
29262932 $ hvbox 0
29272933 ( fmt_expression c
2928- ~pro: (begin_ $ break 1 0 )
2934+ ~pro: (begin_ $ str " " )
29292935 ~box ?eol ~parens: false ~indent_wrap (sub_exp ~ctx e)
29302936 $ break 1 0 $ end_ )
29312937 | Pexp_extension
0 commit comments