From 1efab2b225f6c40948f7216d82c8982bfdd5c242 Mon Sep 17 00:00:00 2001 From: EmileTrotignon Date: Wed, 29 Oct 2025 15:46:58 +0100 Subject: [PATCH 1/5] allow begin end on one line in safe cases --- lib/Fmt_ast.ml | 135 +++++++++--------- test/passing/refs.ahrefs/attributes.ml.ref | 6 +- .../refs.ahrefs/exp_grouping-parens.ml.ref | 21 +-- test/passing/refs.ahrefs/exp_grouping.ml.ref | 31 +--- .../extensions_exp_grouping.ml.ref | 37 +---- .../refs.ahrefs/reformat_string.ml.ref | 12 +- test/passing/refs.ahrefs/source.ml.ref | 4 +- test/passing/refs.default/attributes.ml.ref | 7 +- .../refs.default/cases_exp_grouping.ml.ref | 8 +- .../refs.default/exp_grouping-parens.ml.ref | 25 +--- test/passing/refs.default/exp_grouping.ml.ref | 36 +---- .../extensions_exp_grouping.ml.ref | 43 +----- test/passing/refs.default/js_begin.ml.ref | 4 +- test/passing/refs.default/js_pattern.ml.ref | 5 +- .../refs.default/reformat_string.ml.ref | 13 +- test/passing/refs.default/source.ml.ref | 4 +- .../passing/refs.janestreet/attributes.ml.ref | 9 +- .../exp_grouping-parens.ml.ref | 29 +--- .../refs.janestreet/exp_grouping.ml.ref | 42 +----- .../extensions_exp_grouping.ml.ref | 49 +------ test/passing/refs.janestreet/source.ml.ref | 4 +- .../refs.ocamlformat/attributes.ml.ref | 6 +- .../cases_exp_grouping.ml.ref | 8 +- .../exp_grouping-parens.ml.ref | 21 +-- .../refs.ocamlformat/exp_grouping.ml.ref | 31 +--- .../refs.ocamlformat/extensions-indent.ml.err | 2 +- .../refs.ocamlformat/extensions-indent.ml.ref | 5 +- .../refs.ocamlformat/extensions.ml.err | 2 +- .../refs.ocamlformat/extensions.ml.ref | 5 +- .../extensions_exp_grouping.ml.ref | 37 +---- test/passing/refs.ocamlformat/js_begin.ml.ref | 4 +- .../refs.ocamlformat/js_pattern.ml.ref | 4 +- .../refs.ocamlformat/reformat_string.ml.ref | 12 +- test/passing/refs.ocamlformat/source.ml.ref | 4 +- 34 files changed, 159 insertions(+), 506 deletions(-) diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index bfcece6d41..1e8f9bc4d5 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -222,10 +222,10 @@ let fmt_item_list c ctx0 update_config ast fmt_item items = let loc = Ast.location ctx in maybe_disabled c loc [] (fun c -> fmt_item c ctx ~prev ~next itm) $ opt next (fun (i_n, c_n) -> - fmt_or - (break_between c (ctx, c.conf) (ast i_n, c_n.conf)) - (str "\n" $ force_break) - (fmt_or break_struct force_break space_break) ) + fmt_or + (break_between c (ctx, c.conf) (ast i_n, c_n.conf)) + (str "\n" $ force_break) + (fmt_or break_struct force_break space_break) ) let fmt_recmodule c ctx items fmt_item ast sub = let update_config c i = update_config c (Ast.attributes (ast i)) in @@ -473,7 +473,7 @@ let fmt_docstring_around_item' ?(is_val = false) ?(force_before = false) let floating_doc, doc = doc |> List.map ~f:(fun (({txt; loc}, _) as doc) -> - (Docstring.parse ~loc txt, doc) ) + (Docstring.parse ~loc txt, doc) ) |> List.partition_tf ~f:(fun (_, (_, floating)) -> floating) in let placement = @@ -860,8 +860,8 @@ and fmt_core_type c ?(box = true) ?pro ?(pro_space = true) ?constraint_ctx update_config_maybe_disabled c ptyp_loc ptyp_attributes @@ fun c -> ( match pro with - | Some pro -> fmt_constraint_sep ~pro_space c pro - | None -> noop ) + | Some pro -> fmt_constraint_sep ~pro_space c pro + | None -> noop ) $ let doc, atrs = doc_atrs ptyp_attributes in Cmts.fmt c ptyp_loc @@ -1131,8 +1131,8 @@ and fmt_pattern ?ext c ?pro ?parens ?(box = false) let parens = match parens with Some b -> b | None -> parenze_pat xpat in (match ctx0 with Pat {ppat_desc= Ppat_tuple _; _} -> hvbox 0 | _ -> Fn.id) @@ ( match ppat_desc with - | Ppat_or _ -> fun k -> Cmts.fmt c ppat_loc @@ k - | _ -> fun k -> Cmts.fmt c ppat_loc @@ (fmt_opt pro $ k) ) + | Ppat_or _ -> fun k -> Cmts.fmt c ppat_loc @@ k + | _ -> fun k -> Cmts.fmt c ppat_loc @@ (fmt_opt pro $ k) ) @@ hovbox_if box 0 @@ fmt_pattern_attributes c xpat @@ @@ -1533,7 +1533,7 @@ and fmt_indexop_access c ctx ~fmt_atrs ~has_attr ~parens x = (str ";" $ space_break) (sub_exp ~ctx >> fmt_expression c) ) ) $ opt pia_rhs (fun e -> - fmt_assign_arrow c $ fmt_expression c (sub_exp ~ctx e) ) ) + fmt_assign_arrow c $ fmt_expression c (sub_exp ~ctx e) ) ) $ fmt_atrs ) ) (** Format a [Pexp_function]. [wrap_intro] wraps up to after the [->] and is @@ -2740,8 +2740,8 @@ and fmt_expression c ?(box = true) ?(pro = noop) ?eol ?parens ( fmt_pattern c ~pro:(if_newline "| ") (sub_pat ~ctx pc_lhs) $ opt pc_guard (fun g -> - space_break $ str "when " - $ fmt_expression c (sub_exp ~ctx g) ) + space_break $ str "when " + $ fmt_expression c (sub_exp ~ctx g) ) $ space_break $ str "->" $ fmt_if parens_here (str " (") ) ) $ break 1 2 @@ -3051,10 +3051,9 @@ and fmt_lazy c ~ctx ?(pro = noop) ~fmt_atrs ~infix_ext_attrs ~parens e = and fmt_beginend c ~loc ?(box = true) ?(pro = noop) ~ctx ~ctx0 ~fmt_atrs ~infix_ext_attrs ~indent_wrap ?eol e = let cmts_before = Cmts.fmt_before c ?eol loc in - let begin_ = fmt_infix_ext_attrs c ~pro:(str "begin") infix_ext_attrs - and end_ = - (if not box then break 1000 (-2) else break 1000 0) - $ str "end" $ fmt_atrs + let begin_ = fmt_infix_ext_attrs c ~pro:(str "begin") infix_ext_attrs in + let end_ = + (if not box then break 1000 (-2) else break 1 0) $ str "end" $ fmt_atrs in let box_beginend_sb = Params.Exp.box_beginend_subexpr c.conf ~ctx ~ctx0 in let beginend_box = @@ -3448,8 +3447,8 @@ and fmt_case c ctx ~first ~last case = ( hvbox 0 ( fmt_pattern c ~pro:p.bar ~parens:paren_lhs xlhs $ opt pc_guard (fun g -> - break 1 2 $ str "when " $ fmt_expression c (sub_exp ~ctx g) ) - ) + break 1 2 $ str "when " + $ fmt_expression c (sub_exp ~ctx g) ) ) $ p.break_before_arrow $ str "->" $ p.break_after_arrow $ p.open_paren_branch ) $ p.break_after_opening_paren @@ -3785,9 +3784,9 @@ and fmt_type_extension c ctx $ str " +=" $ fmt_private_flag c ptyext_private $ list_fl ptyext_constructors (fun ~first ~last:_ x -> - let bar_fits = if first then "" else "| " in - cbreak ~fits:("", 1, bar_fits) ~breaks:("", 0, "| ") - $ fmt_ctor x ) ) + let bar_fits = if first then "" else "| " in + cbreak ~fits:("", 1, bar_fits) ~breaks:("", 0, "| ") + $ fmt_ctor x ) ) $ fmt_item_attributes c ~pre:(Break (1, 0)) attrs_after ) and fmt_type_exception ~pre c ctx @@ -4127,46 +4126,46 @@ and fmt_class_types c ~pre ~sep cls = and fmt_class_exprs c cls = hvbox 0 @@ list_fl cls (fun ~first ~last:_ cl -> - update_config_maybe_disabled_attrs c cl.pci_loc cl.pci_attributes - @@ fun c -> - let ctx = Cd cl in - let xargs = cl.pci_args in - let ext = cl.pci_attributes.attrs_extension in - let doc_before, doc_after, attrs_before, attrs_after = - let force_before = not (Cl.is_simple cl.pci_expr) in - fmt_docstring_around_item_attrs ~force_before c cl.pci_attributes - in - let class_expr = - let pro = - box_fun_decl_args c 2 - ( hovbox 2 - ( str (if first then "class" else "and") - $ fmt_if first (fmt_extension_suffix c ext) - $ fmt_attributes c ~pre:(Break (1, 0)) attrs_before - $ fmt_virtual_flag c cl.pci_virt - $ space_break - $ fmt_class_params c ctx cl.pci_params - $ fmt_str_loc c cl.pci_name ) - $ fmt_if (not (List.is_empty xargs)) space_break - $ wrap_fun_decl_args c (fmt_class_fun_args c xargs) ) - in - let intro = - match cl.pci_constraint with - | Some ty -> - fmt_class_type c - ~pro:(pro $ str " :" $ space_break) - (sub_cty ~ctx ty) - | None -> pro - in - hovbox 2 - ( hovbox 2 (intro $ space_break $ str "=") - $ space_break - $ fmt_class_expr c (sub_cl ~ctx cl.pci_expr) ) - $ fmt_item_attributes c ~pre:(Break (1, 0)) attrs_after - in - fmt_if (not first) (str "\n" $ force_break) - $ hovbox 0 - @@ Cmts.fmt c cl.pci_loc (doc_before $ class_expr $ doc_after) ) + update_config_maybe_disabled_attrs c cl.pci_loc cl.pci_attributes + @@ fun c -> + let ctx = Cd cl in + let xargs = cl.pci_args in + let ext = cl.pci_attributes.attrs_extension in + let doc_before, doc_after, attrs_before, attrs_after = + let force_before = not (Cl.is_simple cl.pci_expr) in + fmt_docstring_around_item_attrs ~force_before c cl.pci_attributes + in + let class_expr = + let pro = + box_fun_decl_args c 2 + ( hovbox 2 + ( str (if first then "class" else "and") + $ fmt_if first (fmt_extension_suffix c ext) + $ fmt_attributes c ~pre:(Break (1, 0)) attrs_before + $ fmt_virtual_flag c cl.pci_virt + $ space_break + $ fmt_class_params c ctx cl.pci_params + $ fmt_str_loc c cl.pci_name ) + $ fmt_if (not (List.is_empty xargs)) space_break + $ wrap_fun_decl_args c (fmt_class_fun_args c xargs) ) + in + let intro = + match cl.pci_constraint with + | Some ty -> + fmt_class_type c + ~pro:(pro $ str " :" $ space_break) + (sub_cty ~ctx ty) + | None -> pro + in + hovbox 2 + ( hovbox 2 (intro $ space_break $ str "=") + $ space_break + $ fmt_class_expr c (sub_cl ~ctx cl.pci_expr) ) + $ fmt_item_attributes c ~pre:(Break (1, 0)) attrs_after + in + fmt_if (not first) (str "\n" $ force_break) + $ hovbox 0 + @@ Cmts.fmt c cl.pci_loc (doc_before $ class_expr $ doc_after) ) and fmt_module c ctx ?rec_ ?epi ?(can_sparse = false) keyword ?(eqty = "=") name xargs xbody xmty ~attrs ~rec_flag = @@ -4277,13 +4276,13 @@ and fmt_module c ctx ?rec_ ?epi ?(can_sparse = false) keyword ?(eqty = "=") $ fmt_item_attributes c ~pre:(Break (1, 0)) attrs_after $ doc_after $ opt epi (fun epi -> - fmt_or compact - (fmt_or - ( Option.is_some blk_b.epi - && not c.conf.fmt_opts.ocp_indent_compat.v ) - (str " ") space_break ) - (break 1 (-2)) - $ epi ) ) + fmt_or compact + (fmt_or + ( Option.is_some blk_b.epi + && not c.conf.fmt_opts.ocp_indent_compat.v ) + (str " ") space_break ) + (break 1 (-2)) + $ epi ) ) and fmt_module_declaration c ~rec_flag ~first {ast= pmd; _} = protect c (Md pmd) diff --git a/test/passing/refs.ahrefs/attributes.ml.ref b/test/passing/refs.ahrefs/attributes.ml.ref index 0529fd5486..69a7fb2b72 100644 --- a/test/passing/refs.ahrefs/attributes.ml.ref +++ b/test/passing/refs.ahrefs/attributes.ml.ref @@ -576,11 +576,7 @@ let _ = let _ = ((module[@a] X) [@b]) -let _ = - begin[@a] - x - end - [@b] +let _ = begin[@a] x end [@b] let fold input ~init ~f = foldi input ~init ~f:(fun (_ : int) acc x -> f acc x) [@nontail] diff --git a/test/passing/refs.ahrefs/exp_grouping-parens.ml.ref b/test/passing/refs.ahrefs/exp_grouping-parens.ml.ref index 347b3fffd7..38576e4068 100644 --- a/test/passing/refs.ahrefs/exp_grouping-parens.ml.ref +++ b/test/passing/refs.ahrefs/exp_grouping-parens.ml.ref @@ -283,19 +283,10 @@ let _ = begin%ext end let _ = begin%ext end (* foo *) let _ = x y let _ = (* foo *) x y -let _ = - begin%ext - x y - end -let _ = - begin%ext - (* foo *) x y - end +let _ = begin%ext x y end +let _ = begin%ext (* foo *) x y end -let _ = - begin[@landmark "parse_constant_dividends"] - market_data_items := () - end +let _ = begin[@landmark "parse_constant_dividends"] market_data_items := () end let () = if a then b (* asd *) @@ -531,11 +522,7 @@ let main = | A -> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | B -> bbbbbbbbbbbbbbbbbbbbbb -let _ = - begin - a - end - [@a] +let _ = begin a end [@a] let () = fooooo diff --git a/test/passing/refs.ahrefs/exp_grouping.ml.ref b/test/passing/refs.ahrefs/exp_grouping.ml.ref index 45d49cd420..4f3790ebaa 100644 --- a/test/passing/refs.ahrefs/exp_grouping.ml.ref +++ b/test/passing/refs.ahrefs/exp_grouping.ml.ref @@ -316,27 +316,12 @@ let _ = begin end let _ = begin end (* foo *) let _ = begin%ext end let _ = begin%ext end (* foo *) -let _ = - begin - x y - end -let _ = - begin - (* foo *) x y - end -let _ = - begin%ext - x y - end -let _ = - begin%ext - (* foo *) x y - end +let _ = begin x y end +let _ = begin (* foo *) x y end +let _ = begin%ext x y end +let _ = begin%ext (* foo *) x y end -let _ = - begin[@landmark "parse_constant_dividends"] - market_data_items := () - end +let _ = begin[@landmark "parse_constant_dividends"] market_data_items := () end let () = if a then begin @@ -611,11 +596,7 @@ let main = | A -> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | B -> bbbbbbbbbbbbbbbbbbbbbb -let _ = - begin - a - end - [@a] +let _ = begin a end [@a] let () = fooooo diff --git a/test/passing/refs.ahrefs/extensions_exp_grouping.ml.ref b/test/passing/refs.ahrefs/extensions_exp_grouping.ml.ref index 0b3b4aabdc..4d40c470ff 100644 --- a/test/passing/refs.ahrefs/extensions_exp_grouping.ml.ref +++ b/test/passing/refs.ahrefs/extensions_exp_grouping.ml.ref @@ -1,34 +1,9 @@ -let _ = - begin%ext - y >>= z - end -let _ = - [%ext - begin - y >>= z - end] -let _ = - x - >>= begin%ext - y >>= z - end -let _ = - x - >>= [%ext - begin - y >>= z - end] -let _ = - f - begin%ext - y >>= z - end -let _ = - f - [%ext - begin - y >>= z - end] +let _ = begin%ext y >>= z end +let _ = [%ext begin y >>= z end] +let _ = x >>= begin%ext y >>= z end +let _ = x >>= [%ext begin y >>= z end] +let _ = f begin%ext y >>= z end +let _ = f [%ext begin y >>= z end] let _ = (module%ext S) let _ = [%ext (module S)] diff --git a/test/passing/refs.ahrefs/reformat_string.ml.ref b/test/passing/refs.ahrefs/reformat_string.ml.ref index 3d5cac7f74..77120fcff9 100644 --- a/test/passing/refs.ahrefs/reformat_string.ml.ref +++ b/test/passing/refs.ahrefs/reformat_string.ml.ref @@ -6,15 +6,9 @@ let _ = (* test *) "asd" let _ = "asd" -let _ = - begin - (* te""st *) "asd" - end - -let _ = - begin - "asd" - end +let _ = begin (* te""st *) "asd" end + +let _ = begin "asd" end let _ = 'a' diff --git a/test/passing/refs.ahrefs/source.ml.ref b/test/passing/refs.ahrefs/source.ml.ref index 11dc288f8e..2e387c954c 100644 --- a/test/passing/refs.ahrefs/source.ml.ref +++ b/test/passing/refs.ahrefs/source.ml.ref @@ -96,9 +96,7 @@ let () = assert%foo[@foo] true; lazy%foo[@foo] x; object%foo[@foo] end; - begin%foo[@foo] - 3 - end; + begin%foo[@foo] 3 end; new%foo[@foo] x; match%foo[@foo] () with diff --git a/test/passing/refs.default/attributes.ml.ref b/test/passing/refs.default/attributes.ml.ref index df28db0a04..79de991ee8 100644 --- a/test/passing/refs.default/attributes.ml.ref +++ b/test/passing/refs.default/attributes.ml.ref @@ -454,12 +454,7 @@ let _ = [@b] let _ = ((module[@a] X) [@b]) - -let _ = - begin[@a] - x - end - [@b] +let _ = begin[@a] x end [@b] let fold input ~init ~f = foldi input ~init ~f:(fun (_ : int) acc x -> f acc x) [@nontail] diff --git a/test/passing/refs.default/cases_exp_grouping.ml.ref b/test/passing/refs.default/cases_exp_grouping.ml.ref index 1153a6b1f8..6f431aa001 100644 --- a/test/passing/refs.default/cases_exp_grouping.ml.ref +++ b/test/passing/refs.default/cases_exp_grouping.ml.ref @@ -116,9 +116,7 @@ let a = | B -> bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb end -let a = - begin match f x i with A -> a | B -> b - end +let a = begin match f x i with A -> a | B -> b end let a = begin[@a] match[@b] @@ -177,9 +175,7 @@ let a = | B -> bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb end -let a = - begin try f x i with A -> a | B -> b - end +let a = begin try f x i with A -> a | B -> b end let a = begin[@a] try[@b] diff --git a/test/passing/refs.default/exp_grouping-parens.ml.ref b/test/passing/refs.default/exp_grouping-parens.ml.ref index 153fb6f88d..3fb25ea36c 100644 --- a/test/passing/refs.default/exp_grouping-parens.ml.ref +++ b/test/passing/refs.default/exp_grouping-parens.ml.ref @@ -301,22 +301,9 @@ let _ = begin%ext end let _ = begin%ext end (* foo *) let _ = x y let _ = (* foo *) x y - -let _ = - begin%ext - x y - end - -let _ = - begin%ext - (* foo *) x y - end - -let _ = - begin[@landmark "parse_constant_dividends"] - market_data_items := () - end - +let _ = begin%ext x y end +let _ = begin%ext (* foo *) x y end +let _ = begin[@landmark "parse_constant_dividends"] market_data_items := () end let () = if a then b (* asd *) let x = @@ -548,11 +535,7 @@ let main = | A -> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | B -> bbbbbbbbbbbbbbbbbbbbbb -let _ = - begin - a - end - [@a] +let _ = begin a end [@a] let () = fooooo diff --git a/test/passing/refs.default/exp_grouping.ml.ref b/test/passing/refs.default/exp_grouping.ml.ref index c4a1afb6e9..2dbcccb813 100644 --- a/test/passing/refs.default/exp_grouping.ml.ref +++ b/test/passing/refs.default/exp_grouping.ml.ref @@ -332,31 +332,11 @@ let _ = begin end let _ = begin end (* foo *) let _ = begin%ext end let _ = begin%ext end (* foo *) - -let _ = - begin - x y - end - -let _ = - begin - (* foo *) x y - end - -let _ = - begin%ext - x y - end - -let _ = - begin%ext - (* foo *) x y - end - -let _ = - begin[@landmark "parse_constant_dividends"] - market_data_items := () - end +let _ = begin x y end +let _ = begin (* foo *) x y end +let _ = begin%ext x y end +let _ = begin%ext (* foo *) x y end +let _ = begin[@landmark "parse_constant_dividends"] market_data_items := () end let () = if a then begin @@ -629,11 +609,7 @@ let main = | A -> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | B -> bbbbbbbbbbbbbbbbbbbbbb -let _ = - begin - a - end - [@a] +let _ = begin a end [@a] let () = fooooo diff --git a/test/passing/refs.default/extensions_exp_grouping.ml.ref b/test/passing/refs.default/extensions_exp_grouping.ml.ref index a18eb3ba9a..c25c206552 100644 --- a/test/passing/refs.default/extensions_exp_grouping.ml.ref +++ b/test/passing/refs.default/extensions_exp_grouping.ml.ref @@ -1,40 +1,9 @@ -let _ = - begin%ext - y >>= z - end - -let _ = - [%ext - begin - y >>= z - end] - -let _ = - x - >>= begin%ext - y >>= z - end - -let _ = - x - >>= [%ext - begin - y >>= z - end] - -let _ = - f - begin%ext - y >>= z - end - -let _ = - f - [%ext - begin - y >>= z - end] - +let _ = begin%ext y >>= z end +let _ = [%ext begin y >>= z end] +let _ = x >>= begin%ext y >>= z end +let _ = x >>= [%ext begin y >>= z end] +let _ = f begin%ext y >>= z end +let _ = f [%ext begin y >>= z end] let _ = (module%ext S) let _ = [%ext (module S)] let _ = f (module%ext S) diff --git a/test/passing/refs.default/js_begin.ml.ref b/test/passing/refs.default/js_begin.ml.ref index 36e2430e79..09f5966762 100644 --- a/test/passing/refs.default/js_begin.ml.ref +++ b/test/passing/refs.default/js_begin.ml.ref @@ -9,6 +9,4 @@ let g = function foo; bar -let () = - begin match foo with Bar -> snoo - end +let () = begin match foo with Bar -> snoo end diff --git a/test/passing/refs.default/js_pattern.ml.ref b/test/passing/refs.default/js_pattern.ml.ref index 31b486bc70..f366b55fa8 100644 --- a/test/passing/refs.default/js_pattern.ml.ref +++ b/test/passing/refs.default/js_pattern.ml.ref @@ -2,10 +2,7 @@ let f = function _ -> 0 let f x = match x with _ -> 0 let f = function _ -> 0 let f x = match x with _ -> 0 - -let f x = - begin match x with _ -> 0 - end +let f x = begin match x with _ -> 0 end let check_price t = function | { Exec.trade_at_settlement = None | Some false } -> () diff --git a/test/passing/refs.default/reformat_string.ml.ref b/test/passing/refs.default/reformat_string.ml.ref index 8a4c2d022b..843e62365e 100644 --- a/test/passing/refs.default/reformat_string.ml.ref +++ b/test/passing/refs.default/reformat_string.ml.ref @@ -2,17 +2,8 @@ let _ = 'a' let _ = 'a' let _ = (* test *) "asd" let _ = "asd" - -let _ = - begin - (* te""st *) "asd" - end - -let _ = - begin - "asd" - end - +let _ = begin (* te""st *) "asd" end +let _ = begin "asd" end let _ = 'a' let _ = 'a' let _ = function 'a' .. 'z' -> () diff --git a/test/passing/refs.default/source.ml.ref b/test/passing/refs.default/source.ml.ref index c14b59ab35..6afd4eb839 100644 --- a/test/passing/refs.default/source.ml.ref +++ b/test/passing/refs.default/source.ml.ref @@ -98,9 +98,7 @@ let () = assert%foo[@foo] true; lazy%foo[@foo] x; object%foo[@foo] end; - begin%foo[@foo] - 3 - end; + begin%foo[@foo] 3 end; new%foo[@foo] x; match%foo[@foo] () with diff --git a/test/passing/refs.janestreet/attributes.ml.ref b/test/passing/refs.janestreet/attributes.ml.ref index d6b46bebe3..03520185dc 100644 --- a/test/passing/refs.janestreet/attributes.ml.ref +++ b/test/passing/refs.janestreet/attributes.ml.ref @@ -526,14 +526,7 @@ let _ = ;; let _ = ((module[@a] X) [@b]) - -let _ = - begin[@a] - x - end - [@b] -;; - +let _ = begin[@a] x end [@b] let fold input ~init ~f = foldi input ~init ~f:(fun (_ : int) acc x -> f acc x) [@nontail] [@@@effect] diff --git a/test/passing/refs.janestreet/exp_grouping-parens.ml.ref b/test/passing/refs.janestreet/exp_grouping-parens.ml.ref index a221769b6a..30d0bf06ad 100644 --- a/test/passing/refs.janestreet/exp_grouping-parens.ml.ref +++ b/test/passing/refs.janestreet/exp_grouping-parens.ml.ref @@ -354,25 +354,9 @@ let _ = begin%ext end let _ = begin%ext end (* foo *) let _ = x y let _ = (* foo *) x y - -let _ = - begin%ext - x y - end -;; - -let _ = - begin%ext - (* foo *) x y - end -;; - -let _ = - begin[@landmark "parse_constant_dividends"] - market_data_items := () - end -;; - +let _ = begin%ext x y end +let _ = begin%ext (* foo *) x y end +let _ = begin[@landmark "parse_constant_dividends"] market_data_items := () end let () = if a then b (* asd *) let x = @@ -635,12 +619,7 @@ let main = | B -> bbbbbbbbbbbbbbbbbbbbbb ;; -let _ = - begin - a - end - [@a] -;; +let _ = begin a end [@a] let () = fooooo diff --git a/test/passing/refs.janestreet/exp_grouping.ml.ref b/test/passing/refs.janestreet/exp_grouping.ml.ref index b4f5dabfb5..718e739e33 100644 --- a/test/passing/refs.janestreet/exp_grouping.ml.ref +++ b/test/passing/refs.janestreet/exp_grouping.ml.ref @@ -391,36 +391,11 @@ let _ = begin end let _ = begin end (* foo *) let _ = begin%ext end let _ = begin%ext end (* foo *) - -let _ = - begin - x y - end -;; - -let _ = - begin - (* foo *) x y - end -;; - -let _ = - begin%ext - x y - end -;; - -let _ = - begin%ext - (* foo *) x y - end -;; - -let _ = - begin[@landmark "parse_constant_dividends"] - market_data_items := () - end -;; +let _ = begin x y end +let _ = begin (* foo *) x y end +let _ = begin%ext x y end +let _ = begin%ext (* foo *) x y end +let _ = begin[@landmark "parse_constant_dividends"] market_data_items := () end let () = if a then begin @@ -721,12 +696,7 @@ let main = | B -> bbbbbbbbbbbbbbbbbbbbbb ;; -let _ = - begin - a - end - [@a] -;; +let _ = begin a end [@a] let () = fooooo diff --git a/test/passing/refs.janestreet/extensions_exp_grouping.ml.ref b/test/passing/refs.janestreet/extensions_exp_grouping.ml.ref index d873d1e429..35661c3516 100644 --- a/test/passing/refs.janestreet/extensions_exp_grouping.ml.ref +++ b/test/passing/refs.janestreet/extensions_exp_grouping.ml.ref @@ -1,46 +1,9 @@ -let _ = - begin%ext - y >>= z - end -;; - -let _ = - [%ext - begin - y >>= z - end] -;; - -let _ = - x - >>= begin%ext - y >>= z - end -;; - -let _ = - x - >>= [%ext - begin - y >>= z - end] -;; - -let _ = - f - begin%ext - y >>= z - end -;; - -let _ = - f - [%ext - begin - y >>= z - end] -;; - +let _ = begin%ext y >>= z end +let _ = [%ext begin y >>= z end] +let _ = x >>= begin%ext y >>= z end +let _ = x >>= [%ext begin y >>= z end] +let _ = f begin%ext y >>= z end +let _ = f [%ext begin y >>= z end] let _ = (module%ext S) let _ = [%ext (module S)] let _ = f (module%ext S) diff --git a/test/passing/refs.janestreet/source.ml.ref b/test/passing/refs.janestreet/source.ml.ref index c624e3db2e..c77e626921 100644 --- a/test/passing/refs.janestreet/source.ml.ref +++ b/test/passing/refs.janestreet/source.ml.ref @@ -100,9 +100,7 @@ let () = assert%foo[@foo] true; lazy%foo[@foo] x; object%foo[@foo] end; - begin%foo[@foo] - 3 - end; + begin%foo[@foo] 3 end; new%foo[@foo] x; match%foo[@foo] () with | [%foo? diff --git a/test/passing/refs.ocamlformat/attributes.ml.ref b/test/passing/refs.ocamlformat/attributes.ml.ref index 7ed152a669..84125ff219 100644 --- a/test/passing/refs.ocamlformat/attributes.ml.ref +++ b/test/passing/refs.ocamlformat/attributes.ml.ref @@ -505,11 +505,7 @@ let _ = let _ = ((module[@a] X) [@b]) -let _ = - begin[@a] - x - end - [@b] +let _ = begin[@a] x end [@b] let fold input ~init ~f = foldi input ~init ~f:(fun (_ : int) acc x -> f acc x) [@nontail] diff --git a/test/passing/refs.ocamlformat/cases_exp_grouping.ml.ref b/test/passing/refs.ocamlformat/cases_exp_grouping.ml.ref index ea51d7d0ea..a88ed14724 100644 --- a/test/passing/refs.ocamlformat/cases_exp_grouping.ml.ref +++ b/test/passing/refs.ocamlformat/cases_exp_grouping.ml.ref @@ -124,9 +124,7 @@ let a = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb end -let a = - begin match f x i with A -> a | B -> b - end +let a = begin match f x i with A -> a | B -> b end let a = begin[@a] match[@b] @@ -201,9 +199,7 @@ let a = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb end -let a = - begin try f x i with A -> a | B -> b - end +let a = begin try f x i with A -> a | B -> b end let a = begin[@a] try[@b] diff --git a/test/passing/refs.ocamlformat/exp_grouping-parens.ml.ref b/test/passing/refs.ocamlformat/exp_grouping-parens.ml.ref index 8f10b4c4b1..4b6726b45f 100644 --- a/test/passing/refs.ocamlformat/exp_grouping-parens.ml.ref +++ b/test/passing/refs.ocamlformat/exp_grouping-parens.ml.ref @@ -300,20 +300,11 @@ let _ = x y let _ = (* foo *) x y -let _ = - begin%ext - x y - end +let _ = begin%ext x y end -let _ = - begin%ext - (* foo *) x y - end +let _ = begin%ext (* foo *) x y end -let _ = - begin[@landmark "parse_constant_dividends"] - market_data_items := () - end +let _ = begin[@landmark "parse_constant_dividends"] market_data_items := () end let () = if a then b (* asd *) @@ -552,11 +543,7 @@ let main = | B -> bbbbbbbbbbbbbbbbbbbbbb -let _ = - begin - a - end - [@a] +let _ = begin a end [@a] let () = fooooo diff --git a/test/passing/refs.ocamlformat/exp_grouping.ml.ref b/test/passing/refs.ocamlformat/exp_grouping.ml.ref index 65f27010e5..80e7b41157 100644 --- a/test/passing/refs.ocamlformat/exp_grouping.ml.ref +++ b/test/passing/refs.ocamlformat/exp_grouping.ml.ref @@ -333,30 +333,15 @@ let _ = begin%ext end let _ = begin%ext end (* foo *) -let _ = - begin - x y - end +let _ = begin x y end -let _ = - begin - (* foo *) x y - end +let _ = begin (* foo *) x y end -let _ = - begin%ext - x y - end +let _ = begin%ext x y end -let _ = - begin%ext - (* foo *) x y - end +let _ = begin%ext (* foo *) x y end -let _ = - begin[@landmark "parse_constant_dividends"] - market_data_items := () - end +let _ = begin[@landmark "parse_constant_dividends"] market_data_items := () end let () = if a then begin @@ -635,11 +620,7 @@ let main = | B -> bbbbbbbbbbbbbbbbbbbbbb -let _ = - begin - a - end - [@a] +let _ = begin a end [@a] let () = fooooo diff --git a/test/passing/refs.ocamlformat/extensions-indent.ml.err b/test/passing/refs.ocamlformat/extensions-indent.ml.err index cca4a42308..da4bd1e5cd 100644 --- a/test/passing/refs.ocamlformat/extensions-indent.ml.err +++ b/test/passing/refs.ocamlformat/extensions-indent.ml.err @@ -1 +1 @@ -Warning: extensions-indent.ml:503 exceeds the margin +Warning: extensions-indent.ml:500 exceeds the margin diff --git a/test/passing/refs.ocamlformat/extensions-indent.ml.ref b/test/passing/refs.ocamlformat/extensions-indent.ml.ref index b134617a6a..13f6662c1a 100644 --- a/test/passing/refs.ocamlformat/extensions-indent.ml.ref +++ b/test/passing/refs.ocamlformat/extensions-indent.ml.ref @@ -181,10 +181,7 @@ let _ = let+ a = b in c] -let _ = - begin%ext - "foo" ; "bar" - end +let _ = begin%ext "foo" ; "bar" end let this_function_has_a_long_name plus very many arguments = "and a kind of long body" diff --git a/test/passing/refs.ocamlformat/extensions.ml.err b/test/passing/refs.ocamlformat/extensions.ml.err index d3952988ff..4142883aa4 100644 --- a/test/passing/refs.ocamlformat/extensions.ml.err +++ b/test/passing/refs.ocamlformat/extensions.ml.err @@ -1 +1 @@ -Warning: extensions.ml:503 exceeds the margin +Warning: extensions.ml:500 exceeds the margin diff --git a/test/passing/refs.ocamlformat/extensions.ml.ref b/test/passing/refs.ocamlformat/extensions.ml.ref index 964f5d299b..8364979989 100644 --- a/test/passing/refs.ocamlformat/extensions.ml.ref +++ b/test/passing/refs.ocamlformat/extensions.ml.ref @@ -181,10 +181,7 @@ let _ = let+ a = b in c] -let _ = - begin%ext - "foo" ; "bar" - end +let _ = begin%ext "foo" ; "bar" end let this_function_has_a_long_name plus very many arguments = "and a kind of long body" diff --git a/test/passing/refs.ocamlformat/extensions_exp_grouping.ml.ref b/test/passing/refs.ocamlformat/extensions_exp_grouping.ml.ref index 5d3e96a15e..aa9020942b 100644 --- a/test/passing/refs.ocamlformat/extensions_exp_grouping.ml.ref +++ b/test/passing/refs.ocamlformat/extensions_exp_grouping.ml.ref @@ -1,39 +1,14 @@ -let _ = - begin%ext - y >>= z - end +let _ = begin%ext y >>= z end -let _ = - [%ext - begin - y >>= z - end] +let _ = [%ext begin y >>= z end] -let _ = - x - >>= begin%ext - y >>= z - end +let _ = x >>= begin%ext y >>= z end -let _ = - x - >>= [%ext - begin - y >>= z - end] +let _ = x >>= [%ext begin y >>= z end] -let _ = - f - begin%ext - y >>= z - end +let _ = f begin%ext y >>= z end -let _ = - f - [%ext - begin - y >>= z - end] +let _ = f [%ext begin y >>= z end] let _ = (module%ext S) diff --git a/test/passing/refs.ocamlformat/js_begin.ml.ref b/test/passing/refs.ocamlformat/js_begin.ml.ref index 87e266fd96..f35f826e29 100644 --- a/test/passing/refs.ocamlformat/js_begin.ml.ref +++ b/test/passing/refs.ocamlformat/js_begin.ml.ref @@ -2,6 +2,4 @@ let f = function zoo -> begin foo ; bar end let g = function zoo -> foo ; bar -let () = - begin match foo with Bar -> snoo - end +let () = begin match foo with Bar -> snoo end diff --git a/test/passing/refs.ocamlformat/js_pattern.ml.ref b/test/passing/refs.ocamlformat/js_pattern.ml.ref index b126b25d05..1fb99f971e 100644 --- a/test/passing/refs.ocamlformat/js_pattern.ml.ref +++ b/test/passing/refs.ocamlformat/js_pattern.ml.ref @@ -6,9 +6,7 @@ let f = function _ -> 0 let f x = match x with _ -> 0 -let f x = - begin match x with _ -> 0 - end +let f x = begin match x with _ -> 0 end let check_price t = function | {Exec.trade_at_settlement= None | Some false} -> diff --git a/test/passing/refs.ocamlformat/reformat_string.ml.ref b/test/passing/refs.ocamlformat/reformat_string.ml.ref index c2dfa0fb5c..5988c193d5 100644 --- a/test/passing/refs.ocamlformat/reformat_string.ml.ref +++ b/test/passing/refs.ocamlformat/reformat_string.ml.ref @@ -6,15 +6,9 @@ let _ = (* test *) "asd" let _ = "asd" -let _ = - begin - (* te""st *) "asd" - end - -let _ = - begin - "asd" - end +let _ = begin (* te""st *) "asd" end + +let _ = begin "asd" end let _ = 'a' diff --git a/test/passing/refs.ocamlformat/source.ml.ref b/test/passing/refs.ocamlformat/source.ml.ref index 9333078ed7..3dacef7d26 100644 --- a/test/passing/refs.ocamlformat/source.ml.ref +++ b/test/passing/refs.ocamlformat/source.ml.ref @@ -107,9 +107,7 @@ let () = assert%foo[@foo] true ; lazy%foo[@foo] x ; object%foo[@foo] end ; - begin%foo[@foo] - 3 - end ; + begin%foo[@foo] 3 end ; new%foo[@foo] x ; match%foo[@foo] () with | [%foo? From ae3192b5d0bef73f6b6fa06e590a7f2f812a0714 Mon Sep 17 00:00:00 2001 From: EmileTrotignon Date: Wed, 29 Oct 2025 17:04:54 +0100 Subject: [PATCH 2/5] changelog --- CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 4ca871543b..6c083c1da5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -85,6 +85,10 @@ profile. This started with version 0.26.0. end ``` +- \* Allow `begin end` on one line in most cases. (#2745, @EmileTrotignon). + `f begin fun x -> y end` is not supported for now and is still always + multiline. + ## 0.28.1 ### Highlight From 9eb1d3f5d25fc2d9ff61d766f6d4c151e5f7170d Mon Sep 17 00:00:00 2001 From: EmileTrotignon Date: Wed, 29 Oct 2025 17:12:14 +0100 Subject: [PATCH 3/5] fmt --- lib/Fmt_ast.ml | 128 ++++++++++++++++++++++++------------------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index 1e8f9bc4d5..9131d792f9 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -222,10 +222,10 @@ let fmt_item_list c ctx0 update_config ast fmt_item items = let loc = Ast.location ctx in maybe_disabled c loc [] (fun c -> fmt_item c ctx ~prev ~next itm) $ opt next (fun (i_n, c_n) -> - fmt_or - (break_between c (ctx, c.conf) (ast i_n, c_n.conf)) - (str "\n" $ force_break) - (fmt_or break_struct force_break space_break) ) + fmt_or + (break_between c (ctx, c.conf) (ast i_n, c_n.conf)) + (str "\n" $ force_break) + (fmt_or break_struct force_break space_break) ) let fmt_recmodule c ctx items fmt_item ast sub = let update_config c i = update_config c (Ast.attributes (ast i)) in @@ -473,7 +473,7 @@ let fmt_docstring_around_item' ?(is_val = false) ?(force_before = false) let floating_doc, doc = doc |> List.map ~f:(fun (({txt; loc}, _) as doc) -> - (Docstring.parse ~loc txt, doc) ) + (Docstring.parse ~loc txt, doc) ) |> List.partition_tf ~f:(fun (_, (_, floating)) -> floating) in let placement = @@ -860,8 +860,8 @@ and fmt_core_type c ?(box = true) ?pro ?(pro_space = true) ?constraint_ctx update_config_maybe_disabled c ptyp_loc ptyp_attributes @@ fun c -> ( match pro with - | Some pro -> fmt_constraint_sep ~pro_space c pro - | None -> noop ) + | Some pro -> fmt_constraint_sep ~pro_space c pro + | None -> noop ) $ let doc, atrs = doc_atrs ptyp_attributes in Cmts.fmt c ptyp_loc @@ -1131,8 +1131,8 @@ and fmt_pattern ?ext c ?pro ?parens ?(box = false) let parens = match parens with Some b -> b | None -> parenze_pat xpat in (match ctx0 with Pat {ppat_desc= Ppat_tuple _; _} -> hvbox 0 | _ -> Fn.id) @@ ( match ppat_desc with - | Ppat_or _ -> fun k -> Cmts.fmt c ppat_loc @@ k - | _ -> fun k -> Cmts.fmt c ppat_loc @@ (fmt_opt pro $ k) ) + | Ppat_or _ -> fun k -> Cmts.fmt c ppat_loc @@ k + | _ -> fun k -> Cmts.fmt c ppat_loc @@ (fmt_opt pro $ k) ) @@ hovbox_if box 0 @@ fmt_pattern_attributes c xpat @@ @@ -1533,7 +1533,7 @@ and fmt_indexop_access c ctx ~fmt_atrs ~has_attr ~parens x = (str ";" $ space_break) (sub_exp ~ctx >> fmt_expression c) ) ) $ opt pia_rhs (fun e -> - fmt_assign_arrow c $ fmt_expression c (sub_exp ~ctx e) ) ) + fmt_assign_arrow c $ fmt_expression c (sub_exp ~ctx e) ) ) $ fmt_atrs ) ) (** Format a [Pexp_function]. [wrap_intro] wraps up to after the [->] and is @@ -2740,8 +2740,8 @@ and fmt_expression c ?(box = true) ?(pro = noop) ?eol ?parens ( fmt_pattern c ~pro:(if_newline "| ") (sub_pat ~ctx pc_lhs) $ opt pc_guard (fun g -> - space_break $ str "when " - $ fmt_expression c (sub_exp ~ctx g) ) + space_break $ str "when " + $ fmt_expression c (sub_exp ~ctx g) ) $ space_break $ str "->" $ fmt_if parens_here (str " (") ) ) $ break 1 2 @@ -3447,8 +3447,8 @@ and fmt_case c ctx ~first ~last case = ( hvbox 0 ( fmt_pattern c ~pro:p.bar ~parens:paren_lhs xlhs $ opt pc_guard (fun g -> - break 1 2 $ str "when " - $ fmt_expression c (sub_exp ~ctx g) ) ) + break 1 2 $ str "when " $ fmt_expression c (sub_exp ~ctx g) ) + ) $ p.break_before_arrow $ str "->" $ p.break_after_arrow $ p.open_paren_branch ) $ p.break_after_opening_paren @@ -3784,9 +3784,9 @@ and fmt_type_extension c ctx $ str " +=" $ fmt_private_flag c ptyext_private $ list_fl ptyext_constructors (fun ~first ~last:_ x -> - let bar_fits = if first then "" else "| " in - cbreak ~fits:("", 1, bar_fits) ~breaks:("", 0, "| ") - $ fmt_ctor x ) ) + let bar_fits = if first then "" else "| " in + cbreak ~fits:("", 1, bar_fits) ~breaks:("", 0, "| ") + $ fmt_ctor x ) ) $ fmt_item_attributes c ~pre:(Break (1, 0)) attrs_after ) and fmt_type_exception ~pre c ctx @@ -4126,46 +4126,46 @@ and fmt_class_types c ~pre ~sep cls = and fmt_class_exprs c cls = hvbox 0 @@ list_fl cls (fun ~first ~last:_ cl -> - update_config_maybe_disabled_attrs c cl.pci_loc cl.pci_attributes - @@ fun c -> - let ctx = Cd cl in - let xargs = cl.pci_args in - let ext = cl.pci_attributes.attrs_extension in - let doc_before, doc_after, attrs_before, attrs_after = - let force_before = not (Cl.is_simple cl.pci_expr) in - fmt_docstring_around_item_attrs ~force_before c cl.pci_attributes - in - let class_expr = - let pro = - box_fun_decl_args c 2 - ( hovbox 2 - ( str (if first then "class" else "and") - $ fmt_if first (fmt_extension_suffix c ext) - $ fmt_attributes c ~pre:(Break (1, 0)) attrs_before - $ fmt_virtual_flag c cl.pci_virt - $ space_break - $ fmt_class_params c ctx cl.pci_params - $ fmt_str_loc c cl.pci_name ) - $ fmt_if (not (List.is_empty xargs)) space_break - $ wrap_fun_decl_args c (fmt_class_fun_args c xargs) ) - in - let intro = - match cl.pci_constraint with - | Some ty -> - fmt_class_type c - ~pro:(pro $ str " :" $ space_break) - (sub_cty ~ctx ty) - | None -> pro - in - hovbox 2 - ( hovbox 2 (intro $ space_break $ str "=") - $ space_break - $ fmt_class_expr c (sub_cl ~ctx cl.pci_expr) ) - $ fmt_item_attributes c ~pre:(Break (1, 0)) attrs_after - in - fmt_if (not first) (str "\n" $ force_break) - $ hovbox 0 - @@ Cmts.fmt c cl.pci_loc (doc_before $ class_expr $ doc_after) ) + update_config_maybe_disabled_attrs c cl.pci_loc cl.pci_attributes + @@ fun c -> + let ctx = Cd cl in + let xargs = cl.pci_args in + let ext = cl.pci_attributes.attrs_extension in + let doc_before, doc_after, attrs_before, attrs_after = + let force_before = not (Cl.is_simple cl.pci_expr) in + fmt_docstring_around_item_attrs ~force_before c cl.pci_attributes + in + let class_expr = + let pro = + box_fun_decl_args c 2 + ( hovbox 2 + ( str (if first then "class" else "and") + $ fmt_if first (fmt_extension_suffix c ext) + $ fmt_attributes c ~pre:(Break (1, 0)) attrs_before + $ fmt_virtual_flag c cl.pci_virt + $ space_break + $ fmt_class_params c ctx cl.pci_params + $ fmt_str_loc c cl.pci_name ) + $ fmt_if (not (List.is_empty xargs)) space_break + $ wrap_fun_decl_args c (fmt_class_fun_args c xargs) ) + in + let intro = + match cl.pci_constraint with + | Some ty -> + fmt_class_type c + ~pro:(pro $ str " :" $ space_break) + (sub_cty ~ctx ty) + | None -> pro + in + hovbox 2 + ( hovbox 2 (intro $ space_break $ str "=") + $ space_break + $ fmt_class_expr c (sub_cl ~ctx cl.pci_expr) ) + $ fmt_item_attributes c ~pre:(Break (1, 0)) attrs_after + in + fmt_if (not first) (str "\n" $ force_break) + $ hovbox 0 + @@ Cmts.fmt c cl.pci_loc (doc_before $ class_expr $ doc_after) ) and fmt_module c ctx ?rec_ ?epi ?(can_sparse = false) keyword ?(eqty = "=") name xargs xbody xmty ~attrs ~rec_flag = @@ -4276,13 +4276,13 @@ and fmt_module c ctx ?rec_ ?epi ?(can_sparse = false) keyword ?(eqty = "=") $ fmt_item_attributes c ~pre:(Break (1, 0)) attrs_after $ doc_after $ opt epi (fun epi -> - fmt_or compact - (fmt_or - ( Option.is_some blk_b.epi - && not c.conf.fmt_opts.ocp_indent_compat.v ) - (str " ") space_break ) - (break 1 (-2)) - $ epi ) ) + fmt_or compact + (fmt_or + ( Option.is_some blk_b.epi + && not c.conf.fmt_opts.ocp_indent_compat.v ) + (str " ") space_break ) + (break 1 (-2)) + $ epi ) ) and fmt_module_declaration c ~rec_flag ~first {ast= pmd; _} = protect c (Md pmd) From 36ac4c71d057ea8b203f5103e517d7bee7561e92 Mon Sep 17 00:00:00 2001 From: EmileTrotignon Date: Wed, 29 Oct 2025 17:16:49 +0100 Subject: [PATCH 4/5] promote test --- test/unit/test_fmt_ast.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/test_fmt_ast.ml b/test/unit/test_fmt_ast.ml index 071a5e7c5c..56c33c67fb 100644 --- a/test/unit/test_fmt_ast.ml +++ b/test/unit/test_fmt_ast.ml @@ -114,7 +114,7 @@ let updated_ast_tests = check_updated_test "[%extension 1]" "[%extension 1]" ; check_updated_test "function _ -> ." "function _ -> ." ; check_updated_test "_" "_" ; - check_updated_test "begin () end" "begin\n ()\nend" ; + check_updated_test "begin () end" "begin () end" ; check_updated_test "a :: b" "a :: b" ; check_updated_test "a.!(b)" "a.!(b)" ; check_updated_test "a.!(b) <- c" "a.!(b) <- c" ; From e436e7b27a232fe45e54a447a005311433e776ef Mon Sep 17 00:00:00 2001 From: EmileTrotignon Date: Tue, 2 Dec 2025 19:14:29 +0100 Subject: [PATCH 5/5] promote margin --- test/passing/refs.ahrefs/source.ml.err | 8 ++++---- test/passing/refs.default/source.ml.err | 8 ++++---- test/passing/refs.ocamlformat/source.ml.err | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/passing/refs.ahrefs/source.ml.err b/test/passing/refs.ahrefs/source.ml.err index 1269cc4736..da3c73773e 100644 --- a/test/passing/refs.ahrefs/source.ml.err +++ b/test/passing/refs.ahrefs/source.ml.err @@ -1,4 +1,4 @@ -Warning: source.ml:3417 exceeds the margin -Warning: source.ml:6551 exceeds the margin -Warning: source.ml:6985 exceeds the margin -Warning: source.ml:7817 exceeds the margin +Warning: source.ml:3415 exceeds the margin +Warning: source.ml:6549 exceeds the margin +Warning: source.ml:6983 exceeds the margin +Warning: source.ml:7815 exceeds the margin diff --git a/test/passing/refs.default/source.ml.err b/test/passing/refs.default/source.ml.err index 6e017154b8..1c673e9eb2 100644 --- a/test/passing/refs.default/source.ml.err +++ b/test/passing/refs.default/source.ml.err @@ -1,4 +1,4 @@ -Warning: source.ml:917 exceeds the margin -Warning: source.ml:992 exceeds the margin -Warning: source.ml:6638 exceeds the margin -Warning: source.ml:7097 exceeds the margin +Warning: source.ml:915 exceeds the margin +Warning: source.ml:990 exceeds the margin +Warning: source.ml:6636 exceeds the margin +Warning: source.ml:7095 exceeds the margin diff --git a/test/passing/refs.ocamlformat/source.ml.err b/test/passing/refs.ocamlformat/source.ml.err index 37900d4c2d..c0c2125caa 100644 --- a/test/passing/refs.ocamlformat/source.ml.err +++ b/test/passing/refs.ocamlformat/source.ml.err @@ -1,3 +1,3 @@ -Warning: source.ml:6495 exceeds the margin -Warning: source.ml:7369 exceeds the margin -Warning: source.ml:7887 exceeds the margin +Warning: source.ml:6493 exceeds the margin +Warning: source.ml:7367 exceeds the margin +Warning: source.ml:7885 exceeds the margin