Skip to content

Commit 4fca068

Browse files
makes exp-grouping=preserve the default (#2716)
1 parent 236a5ed commit 4fca068

23 files changed

+263
-165
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ profile. This started with version 0.26.0.
149149
`@@ match` can now also be on one line.
150150
(#2694, @EmileTrotignon)
151151

152+
- `exp-grouping=preserve` is now the default in `default` and `ocamlformat`
153+
profiles. This means that its now possible to use `begin ... end` without
154+
tweaking ocamlformat. (#2716, @EmileTrotignon)
152155
## 0.27.0
153156

154157
### Highlight

doc/manpage_ocamlformat.mld

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ OPTIONS (CODE FORMATTING STYLE)
174174
on the preceding line and closed on the following line. The flag
175175
is set by default.
176176

177-
--exp-grouping={parens|preserve}
178-
Style of expression grouping. parens groups expressions using
179-
parentheses. preserve preserves the original grouping syntax
180-
(parentheses or begin/end). The default value is parens. Cannot be
181-
set in attributes.
177+
--exp-grouping={preserve|parens}
178+
Style of expression grouping. preserve preserves the original
179+
grouping syntax (parentheses or begin/end). parens groups
180+
expressions using parentheses. The default value is preserve.
181+
Cannot be set in attributes.
182182

183183
--extension-indent=COLS
184184
Indentation of items inside extension nodes (COLS columns). The

lib/Conf.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ let conventional_profile from =
7070
; doc_comments_padding= elt 2
7171
; doc_comments_tag_only= elt `Default
7272
; dock_collection_brackets= elt true
73-
; exp_grouping= elt `Parens
73+
; exp_grouping= elt `Preserve
7474
; extension_indent= elt 2
7575
; field_space= elt `Loose
7676
; function_indent= elt 2
@@ -140,7 +140,7 @@ let ocamlformat_profile from =
140140
; doc_comments_padding= elt 2
141141
; doc_comments_tag_only= elt `Default
142142
; dock_collection_brackets= elt false
143-
; exp_grouping= elt `Parens
143+
; exp_grouping= elt `Preserve
144144
; extension_indent= elt 2
145145
; field_space= elt `Tight
146146
; function_indent= elt 2
@@ -745,11 +745,11 @@ module Formatting = struct
745745
let doc = "Style of expression grouping." in
746746
let names = ["exp-grouping"] in
747747
let all =
748-
[ Decl.Value.make ~name:"parens" `Parens
749-
"$(b,parens) groups expressions using parentheses."
750-
; Decl.Value.make ~name:"preserve" `Preserve
748+
[ Decl.Value.make ~name:"preserve" `Preserve
751749
"$(b,preserve) preserves the original grouping syntax \
752-
(parentheses or $(i,begin)/$(i,end))." ]
750+
(parentheses or $(i,begin)/$(i,end))."
751+
; Decl.Value.make ~name:"parens" `Parens
752+
"$(b,parens) groups expressions using parentheses." ]
753753
in
754754
Decl.choice ~names ~all ~default ~doc ~kind ~allow_inline:false
755755
(fun conf elt -> update conf ~f:(fun f -> {f with exp_grouping= elt}))

test/cli/print_config.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ No redundant values:
4242
doc-comments-padding=2 (profile conventional (file .ocamlformat:1))
4343
doc-comments-tag-only=default (profile conventional (file .ocamlformat:1))
4444
dock-collection-brackets=true (profile conventional (file .ocamlformat:1))
45-
exp-grouping=parens (profile conventional (file .ocamlformat:1))
45+
exp-grouping=preserve (profile conventional (file .ocamlformat:1))
4646
extension-indent=2 (profile conventional (file .ocamlformat:1))
4747
field-space=tight (file .ocamlformat:2)
4848
function-indent=2 (profile conventional (file .ocamlformat:1))
@@ -122,7 +122,7 @@ Redundant values from the conventional profile:
122122
doc-comments-padding=2 (profile conventional (file .ocamlformat:1))
123123
doc-comments-tag-only=default (profile conventional (file .ocamlformat:1))
124124
dock-collection-brackets=true (profile conventional (file .ocamlformat:1))
125-
exp-grouping=parens (profile conventional (file .ocamlformat:1))
125+
exp-grouping=preserve (profile conventional (file .ocamlformat:1))
126126
extension-indent=2 (profile conventional (file .ocamlformat:1))
127127
field-space=loose (profile conventional (file .ocamlformat:1))
128128
function-indent=2 (profile conventional (file .ocamlformat:1))
@@ -202,7 +202,7 @@ Redundant values from the ocamlformat profile:
202202
doc-comments-padding=2 (profile ocamlformat (file .ocamlformat:1))
203203
doc-comments-tag-only=default (profile ocamlformat (file .ocamlformat:1))
204204
dock-collection-brackets=false (profile ocamlformat (file .ocamlformat:1))
205-
exp-grouping=parens (profile ocamlformat (file .ocamlformat:1))
205+
exp-grouping=preserve (profile ocamlformat (file .ocamlformat:1))
206206
extension-indent=2 (profile ocamlformat (file .ocamlformat:1))
207207
field-space=tight (profile ocamlformat (file .ocamlformat:1))
208208
function-indent=2 (profile ocamlformat (file .ocamlformat:1))

test/passing/refs.default/effects.ml.ref

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ let run (main : unit -> unit) : unit =
1616
in
1717
let dequeue () =
1818
if Queue.is_empty run_q then () (* done *)
19-
else
19+
else begin
2020
let task = Queue.pop run_q in
2121
task ()
22+
end
2223
in
2324
let rec spawn (f : unit -> unit) : unit =
2425
match f () with
@@ -32,15 +33,16 @@ let run (main : unit -> unit) : unit =
3233
| effect Fork f, k ->
3334
enqueue k ();
3435
spawn f
35-
| effect Xchg n, k -> (
36+
| effect Xchg n, k -> begin
3637
match !exchanger with
3738
| Some (n', k') ->
3839
exchanger := None;
3940
enqueue k' n;
4041
continue k n'
4142
| None ->
4243
exchanger := Some (n, k);
43-
dequeue ())
44+
dequeue ()
45+
end
4446
in
4547
spawn main
4648

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
let _ = if cond1 && cond2 then _
2-
let _ = function _ when x = 2 && y = 3 -> if a = b || (b = c && c = d) then _
2+
3+
let _ = function
4+
| _ when x = 2 && y = 3 -> begin if a = b || (b = c && c = d) then _ end
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
let f = function
2-
| zoo ->
2+
| zoo -> begin
33
foo;
44
bar
5+
end
56

67
let g = function
78
| zoo ->
89
foo;
910
bar
1011

11-
let () = match foo with Bar -> snoo
12+
let () =
13+
begin match foo with Bar -> snoo
14+
end

test/passing/refs.default/js_pattern.ml.ref

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ let f = function _ -> 0
22
let f x = match x with _ -> 0
33
let f = function _ -> 0
44
let f x = match x with _ -> 0
5-
let f x = match x with _ -> 0
5+
6+
let f x =
7+
begin match x with _ -> 0
8+
end
69

710
let check_price t = function
811
| { Exec.trade_at_settlement = None | Some false } -> ()

test/passing/refs.default/reformat_string.ml.ref

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@ let _ = 'a'
22
let _ = 'a'
33
let _ = (* test *) "asd"
44
let _ = "asd"
5-
let _ = (* te""st *) "asd"
6-
let _ = "asd"
5+
6+
let _ =
7+
begin
8+
(* te""st *) "asd"
9+
end
10+
11+
let _ =
12+
begin
13+
"asd"
14+
end
15+
716
let _ = 'a'
817
let _ = 'a'
918
let _ = function 'a' .. 'z' -> ()

test/passing/refs.default/sequence-preserve.ml.ref

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
let read_traces filename =
22
let ic = open_in_bin filename in
3-
read_hashtable ~t:[%t: contracts_trace] 0 40 ic tbl1;
4-
read_hashtable ~t:[%t: variables_trace] 40 70 ic tbl2;
5-
read_hashtable ~t:[%t: expressions_trace] 70 100 ic tbl3;
3+
begin
4+
read_hashtable ~t:[%t: contracts_trace] 0 40 ic tbl1;
5+
read_hashtable ~t:[%t: variables_trace] 40 70 ic tbl2;
6+
read_hashtable ~t:[%t: expressions_trace] 70 100 ic tbl3
7+
end;
68
close_in ic
79

810
let foo x y =

0 commit comments

Comments
 (0)