Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ profile. This started with version 0.26.0.
`@@ match` can now also be on one line.
(#2694, @EmileTrotignon)

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

### Highlight
Expand Down
12 changes: 6 additions & 6 deletions lib/Conf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ let conventional_profile from =
; doc_comments_padding= elt 2
; doc_comments_tag_only= elt `Default
; dock_collection_brackets= elt true
; exp_grouping= elt `Parens
; exp_grouping= elt `Preserve
; extension_indent= elt 2
; field_space= elt `Loose
; function_indent= elt 2
Expand Down Expand Up @@ -139,7 +139,7 @@ let ocamlformat_profile from =
; doc_comments_padding= elt 2
; doc_comments_tag_only= elt `Default
; dock_collection_brackets= elt false
; exp_grouping= elt `Parens
; exp_grouping= elt `Preserve
; extension_indent= elt 2
; field_space= elt `Tight
; function_indent= elt 2
Expand Down Expand Up @@ -742,11 +742,11 @@ module Formatting = struct
let doc = "Style of expression grouping." in
let names = ["exp-grouping"] in
let all =
[ Decl.Value.make ~name:"parens" `Parens
"$(b,parens) groups expressions using parentheses."
; Decl.Value.make ~name:"preserve" `Preserve
[ Decl.Value.make ~name:"preserve" `Preserve
"$(b,preserve) preserves the original grouping syntax \
(parentheses or $(i,begin)/$(i,end))." ]
(parentheses or $(i,begin)/$(i,end))."
; Decl.Value.make ~name:"parens" `Parens
"$(b,parens) groups expressions using parentheses." ]
in
Decl.choice ~names ~all ~default ~doc ~kind ~allow_inline:false
(fun conf elt -> update conf ~f:(fun f -> {f with exp_grouping= elt}))
Expand Down
6 changes: 3 additions & 3 deletions test/cli/print_config.t
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ No redundant values:
doc-comments-padding=2 (profile conventional (file .ocamlformat:1))
doc-comments-tag-only=default (profile conventional (file .ocamlformat:1))
dock-collection-brackets=true (profile conventional (file .ocamlformat:1))
exp-grouping=parens (profile conventional (file .ocamlformat:1))
exp-grouping=preserve (profile conventional (file .ocamlformat:1))
extension-indent=2 (profile conventional (file .ocamlformat:1))
field-space=tight (file .ocamlformat:2)
function-indent=2 (profile conventional (file .ocamlformat:1))
Expand Down Expand Up @@ -121,7 +121,7 @@ Redundant values from the conventional profile:
doc-comments-padding=2 (profile conventional (file .ocamlformat:1))
doc-comments-tag-only=default (profile conventional (file .ocamlformat:1))
dock-collection-brackets=true (profile conventional (file .ocamlformat:1))
exp-grouping=parens (profile conventional (file .ocamlformat:1))
exp-grouping=preserve (profile conventional (file .ocamlformat:1))
extension-indent=2 (profile conventional (file .ocamlformat:1))
field-space=loose (profile conventional (file .ocamlformat:1))
function-indent=2 (profile conventional (file .ocamlformat:1))
Expand Down Expand Up @@ -200,7 +200,7 @@ Redundant values from the ocamlformat profile:
doc-comments-padding=2 (profile ocamlformat (file .ocamlformat:1))
doc-comments-tag-only=default (profile ocamlformat (file .ocamlformat:1))
dock-collection-brackets=false (profile ocamlformat (file .ocamlformat:1))
exp-grouping=parens (profile ocamlformat (file .ocamlformat:1))
exp-grouping=preserve (profile ocamlformat (file .ocamlformat:1))
extension-indent=2 (profile ocamlformat (file .ocamlformat:1))
field-space=tight (profile ocamlformat (file .ocamlformat:1))
function-indent=2 (profile ocamlformat (file .ocamlformat:1))
Expand Down
8 changes: 5 additions & 3 deletions test/passing/refs.default/effects.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ let run (main : unit -> unit) : unit =
in
let dequeue () =
if Queue.is_empty run_q then () (* done *)
else
else begin
let task = Queue.pop run_q in
task ()
end
in
let rec spawn (f : unit -> unit) : unit =
match f () with
Expand All @@ -32,15 +33,16 @@ let run (main : unit -> unit) : unit =
| effect Fork f, k ->
enqueue k ();
spawn f
| effect Xchg n, k -> (
| effect Xchg n, k -> begin
match !exchanger with
| Some (n', k') ->
exchanger := None;
enqueue k' n;
continue k n'
| None ->
exchanger := Some (n, k);
dequeue ())
dequeue ()
end
in
spawn main

Expand Down
4 changes: 3 additions & 1 deletion test/passing/refs.default/ifand.ml.ref
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
let _ = if cond1 && cond2 then _
let _ = function _ when x = 2 && y = 3 -> if a = b || (b = c && c = d) then _

let _ = function
| _ when x = 2 && y = 3 -> begin if a = b || (b = c && c = d) then _ end
7 changes: 5 additions & 2 deletions test/passing/refs.default/js_begin.ml.ref
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
let f = function
| zoo ->
| zoo -> begin
foo;
bar
end

let g = function
| zoo ->
foo;
bar

let () = match foo with Bar -> snoo
let () =
begin match foo with Bar -> snoo
end
5 changes: 4 additions & 1 deletion test/passing/refs.default/js_pattern.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ 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 = match x with _ -> 0

let f x =
begin match x with _ -> 0
end

let check_price t = function
| { Exec.trade_at_settlement = None | Some false } -> ()
Expand Down
13 changes: 11 additions & 2 deletions test/passing/refs.default/reformat_string.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ let _ = 'a'
let _ = 'a'
let _ = (* test *) "asd"
let _ = "asd"
let _ = (* te""st *) "asd"
let _ = "asd"

let _ =
begin
(* te""st *) "asd"
end

let _ =
begin
"asd"
end

let _ = 'a'
let _ = 'a'
let _ = function 'a' .. 'z' -> ()
Expand Down
8 changes: 5 additions & 3 deletions test/passing/refs.default/sequence-preserve.ml.ref
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
let read_traces filename =
let ic = open_in_bin filename in
read_hashtable ~t:[%t: contracts_trace] 0 40 ic tbl1;
read_hashtable ~t:[%t: variables_trace] 40 70 ic tbl2;
read_hashtable ~t:[%t: expressions_trace] 70 100 ic tbl3;
begin
read_hashtable ~t:[%t: contracts_trace] 0 40 ic tbl1;
read_hashtable ~t:[%t: variables_trace] 40 70 ic tbl2;
read_hashtable ~t:[%t: expressions_trace] 70 100 ic tbl3
end;
close_in ic

let foo x y =
Expand Down
8 changes: 5 additions & 3 deletions test/passing/refs.default/sequence.ml.ref
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
let read_traces filename =
let ic = open_in_bin filename in
read_hashtable ~t:[%t: contracts_trace] 0 40 ic tbl1;
read_hashtable ~t:[%t: variables_trace] 40 70 ic tbl2;
read_hashtable ~t:[%t: expressions_trace] 70 100 ic tbl3;
begin
read_hashtable ~t:[%t: contracts_trace] 0 40 ic tbl1;
read_hashtable ~t:[%t: variables_trace] 40 70 ic tbl2;
read_hashtable ~t:[%t: expressions_trace] 70 100 ic tbl3
end;
close_in ic

let foo x y =
Expand Down
4 changes: 2 additions & 2 deletions test/passing/refs.default/source.ml.err
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Warning: source.ml:919 exceeds the margin
Warning: source.ml:994 exceeds the margin
Warning: source.ml:6616 exceeds the margin
Warning: source.ml:7074 exceeds the margin
Warning: source.ml:6640 exceeds the margin
Warning: source.ml:7099 exceeds the margin
Loading
Loading