Expected | Ocp-indent output | |
---|---|---|
0 | ||
1 | (* this could be fixed, but we actually want to handle the first case | (* this could be fixed, but we actually want to handle the first case |
2 | differently for when there is only one case (see next examples) *) | differently for when there is only one case (see next examples) *) |
3 | let f x = function A -> x; | let f x = function A -> x; |
4 | 2 | 2 |
5 | | B -> y; | | B -> y; |
6 | 3 | 3 |
7 | ||
8 | (* if we were to fix to the case above, the second >>= would be below the _ | (* if we were to fix to the case above, the second >>= would be below the _ |
9 | (test taken from js-fun) *) | (test taken from js-fun) *) |
10 | let _ = | let _ = |
11 | x | x |
12 | >>= fun x -> | >>= fun x -> |
13 | try x with _ -> () | try x with _ -> () |
14 | >>= fun x -> | >>= fun x -> |
15 | x | x |
16 | ||
17 | (* (and also: the some_handling here would be below Not_found) *) | (* (and also: the some_handling here would be below Not_found) *) |
18 | let _ = | let _ = |
19 | try | try |
20 | _ | _ |
21 | with Not_found -> | with Not_found -> |
22 | some_handling | some_handling |
23 | ||
24 | let f = fun x -> | let f = fun x -> |
25 | x | x |
26 | ||
27 | let f = (fun x -> | let f = (fun x -> |
28 | x | x |
29 | ) | ) |
30 | ||
31 | let f g = g @@ fun x -> | let f g = g @@ fun x -> |
32 | x | x |
33 | ||
34 | let f g = g @@ (fun x -> | let f g = g @@ (fun x -> |
35 | x | x |
36 | ) | ) |
37 | ||
38 | ||
39 | (* the above should probably be consistent with: *) | (* the above should probably be consistent with: *) |
40 | let f x y = y + match x with A -> | let f x y = y + match x with A -> |
41 | 0 | 0 |
42 | ||
43 | let f x y = y + (match x with A -> | let f x y = y + (match x with A -> |
44 | 0 | 0 |
45 | ) | ) |
46 | ||
47 | (* wich means we may over-indent even when the block is non-closable *) | (* wich means we may over-indent even when the block is non-closable *) |
48 | ||
49 | let f x y = y + match x with | let f x y = y + match x with |
50 | | A -> 0 | | A -> 0 |
51 | ||
52 | let f x y = y + (match x with | let f x y = y + (match x with |
53 | | A -> 0 | | A -> 0 |
54 | ) | ) |
55 | ||
56 | let f x y = y + match x with | let f x y = y + match x with |
57 | | A -> 0 | | A -> 0 |
58 | ||
59 | let _ = | let _ = |
60 | somefun | somefun |
61 | (fun x -> | (fun x -> |
62 | x); | x); |
63 | somefun | somefun |
64 | (if | (if |
65 | bla | bla |
66 | then | then |
67 | bli); | bli); |
68 | somefun | somefun |
69 | (if bla then | (if bla then |
70 | bli | bli |
71 | else | else |
72 | blu) | blu) |
73 | ||
74 | let _ = | let _ = |
75 | a | a |
76 | ; | ; |
77 | b | b |
78 | ||
79 | (* Surprisingly, this is the indentation correpsonding to OCaml's interpretation | (* Surprisingly, this is the indentation correpsonding to OCaml's interpretation |
80 | of this code. Indenting this accordingly may help users notice that they're | of this code. Indenting this accordingly may help users notice that they're |
81 | doing something dubious. *) | doing something dubious. *) |
82 | let b = `b | let b = `b |
83 | let d = `d | let d = `d |
84 | ;; | ;; |
85 | let a = b | let a = b |
86 | function·(_·:·[·`c·])·->·d | ····function·(_·:·[·`c·])·->·d |
87 | ;; | ;; |
Expected | Ocp-indent output | |
---|---|---|
0 | let () = | let () = |
1 | foo.bar <- | foo.bar <- |
2 | f x | f x |
3 | y z | y z |
4 | ||
5 | let should_check_can_sell_and_marking regulatory_regime = | let should_check_can_sell_and_marking regulatory_regime = |
6 | match z with | match z with |
7 | | `foo | | `foo |
8 | -> some_function | -> some_function |
9 | argument | argument |
10 | (* The above typically occurs in a multi-pattern match clause, so the clause | (* The above typically occurs in a multi-pattern match clause, so the clause |
11 | expression is on a line by itself. This is the more typical way a long | expression is on a line by itself. This is the more typical way a long |
12 | single-pattern match clause would be written: *) | single-pattern match clause would be written: *) |
13 | let should_check_can_sell_and_marking regulatory_regime = | let should_check_can_sell_and_marking regulatory_regime = |
14 | match z with | match z with |
15 | | `foo -> | | `foo -> |
16 | some_function | some_function |
17 | argument | argument |
18 | ||
19 | let f = fun x -> | let f = fun x -> |
20 | ghi | ghi |
21 | x | x |
22 | ||
23 | (* common *) | (* common *) |
24 | let x = | let x = |
25 | try x with | try x with |
26 | | a -> b | | a -> b |
27 | | c -> d | | c -> d |
28 | let x = try x with | let x = try x with |
29 | | a -> b | | a -> b |
30 | | c -> d | | c -> d |
31 | let x = | let x = |
32 | try x | try x |
33 | with | with |
34 | | a -> b | | a -> b |
35 | | c -> d | | c -> d |
36 | ||
37 | let z = | let z = |
38 | some_function | some_function |
39 | argument | argument |
40 | ||
41 | ||
42 | ||
43 | let () = | let () = |
44 | f a b ~c:c | f a b ~c:c |
45 | d | d |
46 | ||
47 | let () = | let () = |
48 | f a b ~c:1. | f a b ~c:1. |
49 | d | d |
50 | ||
51 | let () = | let () = |
52 | My_module.f a b ~c:c | My_module.f a b ~c:c |
53 | d | d |
54 | ||
55 | (* This last case is where Tuareg is inconsistent with the others. *) | (* This last case is where Tuareg is inconsistent with the others. *) |
56 | let () = | let () = |
57 | My_module.f a b ~c:1. | My_module.f a b ~c:1. |
58 | d | d |
59 | ||
60 | ||
61 | ||
62 | let () = | let () = |
63 | messages := | messages := |
64 | Message_store.create (Session_id.of_string "") | Message_store.create (Session_id.of_string "") |
65 | (* Tuareg indents these lines too far to the left. *) | (* Tuareg indents these lines too far to the left. *) |
66 | "herd-retransmitter" | "herd-retransmitter" |
67 | Message_store.Message_size.Byte | Message_store.Message_size.Byte |
68 | ||
69 | ||
70 | ||
71 | let () = | let () = |
72 | raise (Bug ("foo" | raise (Bug ("foo" |
73 | (* In this and similar cases, we want the subsequent lines to | (* In this and similar cases, we want the subsequent lines to |
74 | align with the first expression. *) | align with the first expression. *) |
75 | ^ "bar")); | ^ "bar")); |
76 | raise (Bug ("foo" ^ "quux" | raise (Bug ("foo" ^ "quux" |
77 | ^ "bar")); | ^ "bar")); |
78 | raise (Bug (foo + quux | raise (Bug (foo + quux |
79 | ^ "bar")); | ^ "bar")); |
80 | raise (Bug ((foo + quux) | raise (Bug ((foo + quux) |
81 | ^ "bar")) | ^ "bar")) |
82 | ||
83 | (* Except in specific cases, we want the argument indented relative to the | (* Except in specific cases, we want the argument indented relative to the |
84 | function being called. (Exceptions include "fun" arguments where the line | function being called. (Exceptions include "fun" arguments where the line |
85 | ends with "->" and subsequent lines beginning with operators, like above.) *) | ends with "->" and subsequent lines beginning with operators, like above.) *) |
86 | let () = | let () = |
87 | Some (Message_store.create s | Some (Message_store.create s |
88 | "herd-retransmitter" ~unlink:true Message_store.Message_size.Byte) | "herd-retransmitter" ~unlink:true Message_store.Message_size.Byte) |
89 | ||
90 | ||
91 | ||
92 | (* We like the indentation of most arguments, but want to get back towards the | (* We like the indentation of most arguments, but want to get back towards the |
93 | left margin in a few special cases: *) | left margin in a few special cases: *) |
94 | let _ = | let _ = |
95 | foo (bar (fun x -> (* special: "fun _ ->" at EOL *) | foo (bar (fun x -> (* special: "fun _ ->" at EOL *) |
96 | baz)) (* assume no more arguments to "bar" *) | baz)) (* assume no more arguments to "bar" *) |
97 | let _ = | let _ = |
98 | foo | foo |
99 | ~a_long_field_name:(check (fun bar -> | ~a_long_field_name:(check (fun bar -> |
100 | baz)) | baz)) |
101 | let _ = | let _ = |
102 | foo ~a_long_field_name:(check (fun bar -> | foo ~a_long_field_name:(check (fun bar -> |
103 | baz)) | baz)) |
104 | let _ = | let _ = |
105 | foo (bar (quux (fnord (fun x -> (* any depth *) | foo (bar (quux (fnord (fun x -> (* any depth *) |
106 | baz)))) | baz)))) |
107 | ||
108 | (* We also wanted to tweak the operator indentation, making operators like <= | (* We also wanted to tweak the operator indentation, making operators like <= |
109 | not special cases in contexts like this: *) | not special cases in contexts like this: *) |
110 | let _ = | let _ = |
111 | assert (foo (bar + baz | assert (foo (bar + baz |
112 | <= quux)) (* lined up under left argument to op, | <= quux)) (* lined up under left argument to op, |
113 | sim. to ^ above *) | sim. to ^ above *) |
114 | (* Sim. indentation of if conditions: *) | (* Sim. indentation of if conditions: *) |
115 | let _ = | let _ = |
116 | if (a | if (a |
117 | <= b) | <= b) |
118 | then () | then () |
119 | let _ = | let _ = |
120 | (* Comparisons are different than conditionals; we don't regard them as | (* Comparisons are different than conditionals; we don't regard them as |
121 | conceptually part of the [if] expression. *) | conceptually part of the [if] expression. *) |
122 | if a | if a |
123 | <= b | <= b |
124 | then () | then () |
125 | let _ = | let _ = |
126 | (* We regard the outermost condition terms as conceptually part of the [if] | (* We regard the outermost condition terms as conceptually part of the [if] |
127 | expression and indent accordingly. Whether [&&] or [||], conditionals | expression and indent accordingly. Whether [&&] or [||], conditionals |
128 | effectively state lists of conditions for [then]. *) | effectively state lists of conditions for [then]. *) |
129 | if Edge_adjustment.is_zero arb.cfg.extra_edge | if Edge_adjustment.is_zero arb.cfg.extra_edge |
130 | && 0. = sys.plugs.edge_backoff | && 0. = sys.plugs.edge_backoff |
131 | && 0. = zero_acvol_edge_backoff | && 0. = zero_acvol_edge_backoff |
132 | then 0. | then 0. |
133 | else 1. | else 1. |
134 | let _ = | let _ = |
135 | if | if |
136 | Edge_adjustment.is_zero arb.cfg.extra_edge | Edge_adjustment.is_zero arb.cfg.extra_edge |
137 | && 0. = sys.plugs.edge_backoff | && 0. = sys.plugs.edge_backoff |
138 | && 0. = zero_acvol_edge_backoff | && 0. = zero_acvol_edge_backoff |
139 | then 0. | then 0. |
140 | else 1. | else 1. |
141 | let _ = | let _ = |
142 | let entries = List.filter (Lazy.force transferstati) ~f:(fun ts -> | let entries = List.filter (Lazy.force transferstati) ~f:(fun ts -> |
143 | Pcre.pmatch ~pat ts.RQ.description | Pcre.pmatch ~pat ts.RQ.description |
144 | ) in | ) in |
145 | x | x |
146 | ||
147 | (* combination of operator at BOL and -> at EOL: *) | (* combination of operator at BOL and -> at EOL: *) |
148 | let _ = | let _ = |
149 | Shell.ssh_lines x | Shell.ssh_lines x |
150 | |! List.map ~f:(f (g (fun x -> | |! List.map ~f:(f (g (fun x -> |
151 | ·······let·name,·path·=·String.lsplit2_exn·~on:'|'·x·in | ····let·name,·path·=·String.lsplit2_exn·~on:'|'·x·in |
152 | ·······String.strip·name,·String.strip·path))) | ····String.strip·name,·String.strip·path))) |
153 | ||
154 | (* open paren ending line like begin *) | (* open paren ending line like begin *) |
155 | let _ = | let _ = |
156 | if a (p ^/ "s") [ e ] = Ok () then `S ( | if a (p ^/ "s") [ e ] = Ok () then `S ( |
157 | let label count = | let label count = |
158 | sprintf "%d s" c ^ if c = 1 then ":" else "s" | sprintf "%d s" c ^ if c = 1 then ":" else "s" |
159 | in | in |
160 | x | x |
161 | ) | ) |
Expected | Ocp-indent output | |
---|---|---|
0 | let f = function | let f = function |
1 | | zoo -> begin | | zoo -> begin |
2 | foo; | foo; |
3 | bar; | bar; |
4 | end | end |
5 | ;; | ;; |
6 | let g = function | let g = function |
7 | | zoo -> ( | | zoo -> ( |
8 | foo; | foo; |
9 | bar; | bar; |
10 | ) | ) |
11 | ;; | ;; |
12 | let () = | let () = |
13 | begin match foo with | begin match foo with |
14 | ········|·Bar·->·snoo | ··|·Bar·->·snoo |
15 | end | end |
16 | ;; | ;; |
Expected | Ocp-indent output | |
---|---|---|
0 | type t = | type t = |
1 | { last_trading : Week_date.Spec.t; | { last_trading : Week_date.Spec.t; |
2 | first_notice : Week_date.Spec.t option; | first_notice : Week_date.Spec.t option; |
3 | first_notice_exceptions : Date.t Year_month.Map.t | first_notice_exceptions : Date.t Year_month.Map.t |
4 | with default(Year_month.Map.empty); | with default(Year_month.Map.empty); |
5 | offset : Week_date.Offset.t; | offset : Week_date.Offset.t; |
6 | (* n > 0 *) | (* n > 0 *) |
7 | new_contract_expires_in_n_months : int | new_contract_expires_in_n_months : int |
8 | } | } |
9 | [@@deriving·sexp,·compare] | ··[@@deriving·sexp,·compare] |
Expected | Ocp-indent output | |
---|---|---|
0 | (* preferred list style *) | (* preferred list style *) |
1 | let z = | let z = |
2 | f | f |
3 | [ y | [ y |
4 | ; foo ~f:(fun () -> | ; foo ~f:(fun () -> |
5 | arg) | arg) |
6 | ] | ] |
7 | ;; | ;; |
8 | let z = | let z = |
9 | f | f |
10 | [ y | [ y |
11 | ; foo ~f:(fun () -> | ; foo ~f:(fun () -> |
12 | arg | arg |
13 | ) | ) |
14 | ] | ] |
15 | ;; | ;; |
16 | ||
17 | (* legacy list style *) | (* legacy list style *) |
18 | let _ = | let _ = |
19 | [ f (fun x -> | [ f (fun x -> |
20 | x); | x); |
21 | f (fun x -> | f (fun x -> |
22 | x); | x); |
23 | f (fun x -> | f (fun x -> |
24 | x); | x); |
25 | ] | ] |
26 | let _ = | let _ = |
27 | [ f (fun x -> | [ f (fun x -> |
28 | x | x |
29 | ); | ); |
30 | f (fun x -> | f (fun x -> |
31 | x | x |
32 | ); | ); |
33 | f (fun x -> | f (fun x -> |
34 | x | x |
35 | ); | ); |
36 | ] | ] |
37 | ;; | ;; |
38 | let _ = | let _ = |
39 | [f (fun x -> | [f (fun x -> |
40 | x | x |
41 | ); | ); |
42 | f (fun x -> | f (fun x -> |
43 | x | x |
44 | ); | ); |
45 | f (fun x -> | f (fun x -> |
46 | x | x |
47 | ); | ); |
48 | ] | ] |
49 | ;; | ;; |
50 | ||
51 | let _ = | let _ = |
52 | x | x |
53 | >>= fun x -> | >>= fun x -> |
54 | (try x with _ -> ()) | (try x with _ -> ()) |
55 | >>= fun x -> | >>= fun x -> |
56 | try x with _ -> () | try x with _ -> () |
57 | >>= fun x -> | >>= fun x -> |
58 | x | x |
59 | ;; | ;; |
60 | ||
61 | let () = | let () = |
62 | expr | expr |
63 | >>| function | >>| function |
64 | | x -> 3 | | x -> 3 |
65 | | y -> 4 | | y -> 4 |
66 | ;; | ;; |
67 | ||
68 | let () = | let () = |
69 | expr | expr |
70 | >>| fun z -> match z with | >>| fun z -> match z with |
71 | ···············|·x·->·3 | ··|·x·->·3 |
72 | ···············|·y·->·4 | ··|·y·->·4 |
73 | ;; | ;; |
74 | ||
75 | let () = | let () = |
76 | expr | expr |
77 | >>| fun z -> function | >>| fun z -> function |
78 | | x -> 3 | | x -> 3 |
79 | | y -> 4 | | y -> 4 |
80 | ;; | ;; |
81 | ||
82 | let () = | let () = |
83 | my_func () >>= function | my_func () >>= function |
84 | | A -> 0 | | A -> 0 |
85 | | B -> 0 | | B -> 0 |
86 | ;; | ;; |
87 | ||
88 | let () = | let () = |
89 | my_func () >>= (function | my_func () >>= (function |
90 | | A -> 0 | | A -> 0 |
91 | | B -> 0) | | B -> 0) |
92 | ;; | ;; |
93 | ||
94 | let () = | let () = |
95 | expr | expr |
96 | >>| function | >>| function |
97 | | x -> 3 | | x -> 3 |
98 | | y -> 4 | | y -> 4 |
99 | ;; | ;; |
100 | ||
101 | let () = | let () = |
102 | expr | expr |
103 | >>| (function | >>| (function |
104 | | x -> 3 | | x -> 3 |
105 | | y -> 4) | | y -> 4) |
106 | ;; | ;; |
107 | ||
108 | ||
109 | ||
110 | let f = | let f = |
111 | f >>= m (fun f -> | f >>= m (fun f -> |
112 | fun x -> | fun x -> |
113 | y); | y); |
114 | z | z |
115 | ;; | ;; |
116 | ||
117 | let f = | let f = |
118 | f | f |
119 | |> m (fun f -> | |> m (fun f -> |
120 | fun x -> | fun x -> |
121 | y | y |
122 | ); | ); |
123 | z | z |
124 | ;; | ;; |
125 | let f = | let f = |
126 | f | f |
127 | |> m (fun f -> | |> m (fun f -> |
128 | fun x -> | fun x -> |
129 | y); | y); |
130 | z | z |
131 | ;; | ;; |
Expected | Ocp-indent output | |
---|---|---|
0 | module M = | module M = |
1 | Foo (G) | Foo (G) |
2 | (H) | (H) |
3 | ||
4 | module M = | module M = |
5 | Foo | Foo |
6 | (G) | (G) |
7 | (struct | (struct |
8 | let x | let x |
9 | end) | end) |
10 | (H) | (H) |
11 | ||
12 | (* To me, this looks fine as it is. The rule seems fine as "indent arguments by | (* To me, this looks fine as it is. The rule seems fine as "indent arguments by |
13 | 2". To illustrate, with a case where the functor name is longer: *) | 2". To illustrate, with a case where the functor name is longer: *) |
14 | module M = | module M = |
15 | Functor (G) | Functor (G) |
16 | (H) | (H) |
17 | (I) | (I) |
18 | ||
19 | ||
20 | ||
21 | include Foo (struct | include Foo (struct |
22 | let x | let x |
23 | end) (struct | end) (struct |
24 | let y | let y |
25 | end) | end) |
26 | ||
27 | include | include |
28 | Foo (struct | Foo (struct |
29 | ······let·x | ····let·x |
30 | ····end)·(struct | ··end)·(struct |
31 | ······let·y | ····let·y |
32 | ····end) | ··end) |
33 | ||
34 | include | include |
35 | Foo | Foo |
36 | (struct | (struct |
37 | let x | let x |
38 | end) (struct | end) (struct |
39 | ······let·y | ····let·y |
40 | ····end) | ··end) |
41 | ||
42 | include Persistent.Make | include Persistent.Make |
43 | ··(struct·let·version·=·1·end) | ····(struct·let·version·=·1·end) |
44 | ··(Stable.Cr_soons_or_pending.V1) | ····(Stable.Cr_soons_or_pending.V1) |
45 | ||
46 | include Persistent.Make | include Persistent.Make |
47 | ··(struct | ····(struct |
48 | ····let·version·=·1 | ······let·version·=·1 |
49 | ··end) | ····end) |
50 | ··(Stable.Cr_soons_or_pending.V1) | ····(Stable.Cr_soons_or_pending.V1) |
51 | ||
52 | include | include |
53 | Persistent.Make | Persistent.Make |
54 | (struct let version = 1 end) | (struct let version = 1 end) |
55 | (Stable.Cr_soons_or_pending.V1) | (Stable.Cr_soons_or_pending.V1) |
56 | ||
57 | include | include |
58 | Persistent.Make | Persistent.Make |
59 | (struct | (struct |
60 | let version = 1 | let version = 1 |
61 | end) | end) |
62 | (Stable.Cr_soons_or_pending.V1) | (Stable.Cr_soons_or_pending.V1) |
63 | ||
64 | module M = | module M = |
65 | Foo (struct | Foo (struct |
66 | ······let·x | ····let·x |
67 | ····end)·(struct | ··end)·(struct |
68 | ······let·y | ····let·y |
69 | ····end) | ··end) |
70 | ||
71 | module M : S = | module M : S = |
72 | Make (M) | Make (M) |
73 | module M : S with type t := int = | module M : S with type t := int = |
74 | Make (M) | Make (M) |
75 | ||
76 | ||
77 | ||
78 | module Simple_command(Arg:sig | module Simple_command(Arg:sig |
79 | end) = struct end | end) = struct end |
80 | ||
81 | module Simple_command(Arg : sig | module Simple_command(Arg : sig |
82 | end) = struct end | end) = struct end |
83 | ||
84 | module Simple_command (Arg:sig | module Simple_command (Arg:sig |
85 | end) = struct end | end) = struct end |
86 | ||
87 | module Simple_command (Arg : sig | module Simple_command (Arg : sig |
88 | end) = struct end | end) = struct end |
89 | ||
90 | module Simple_command | module Simple_command |
91 | ··(Arg·:·sig | ····(Arg·:·sig |
92 | ···end)·=·struct·end | ·····end)·=·struct·end |
Expected | Ocp-indent output | |
---|---|---|
0 | let f = function | let f = function |
1 | | _ -> 0 | | _ -> 0 |
2 | ;; | ;; |
3 | ||
4 | let f x = match x with | let f x = match x with |
5 | ··········|·_·->·0 | ··|·_·->·0 |
6 | ;; | ;; |
7 | ||
8 | let f = | let f = |
9 | function | function |
10 | | _ -> 0 | | _ -> 0 |
11 | ;; | ;; |
12 | ||
13 | let f x = | let f x = |
14 | match x with | match x with |
15 | | _ -> 0 | | _ -> 0 |
16 | ;; | ;; |
17 | ||
18 | let f x = | let f x = |
19 | begin match x with | begin match x with |
20 | ········|·_·->·0 | ··|·_·->·0 |
21 | end | end |
22 | ;; | ;; |
23 | ||
24 | let check_price t = function | let check_price t = function |
25 | | { Exec. | | { Exec. |
26 | trade_at_settlement = (None | Some false); | trade_at_settlement = (None | Some false); |
27 | } -> () | } -> () |
28 | ||
29 | let check_price t = function | let check_price t = function |
30 | | simpler -> () | | simpler -> () |
31 | | other -> () | | other -> () |
32 | ||
33 | (* Sometimes we like to write big alternations like this, in which case the | (* Sometimes we like to write big alternations like this, in which case the |
34 | comment should typically align with the following clause. *) | comment should typically align with the following clause. *) |
35 | let 0 = | let 0 = |
36 | match x with | match x with |
37 | | A | | A |
38 | (* a *) | (* a *) |
39 | -> a | -> a |
40 | let 0 = | let 0 = |
41 | match x with | match x with |
42 | A | A |
43 | (* a *) | (* a *) |
44 | -> a | -> a |
45 | ||
46 | let _ = | let _ = |
47 | a | a |
48 | || match a with | || match a with |
49 | ·····|·a·->·true | ··|·a·->·true |
50 | ·····|·b·->·false | ··|·b·->·false |
Expected | Ocp-indent output | |
---|---|---|
0 | type x = | type x = |
1 | { foo : int | { foo : int |
2 | ; bar : int | ; bar : int |
3 | } | } |
4 | ||
5 | let x = | let x = |
6 | { x with | { x with |
7 | foo = 3 | foo = 3 |
8 | ; bar = 5 | ; bar = 5 |
9 | } | } |
10 | ||
11 | let x = | let x = |
12 | { (* blah blah blah *) | { (* blah blah blah *) |
13 | foo = 3 | foo = 3 |
14 | ; bar = 5 | ; bar = 5 |
15 | } | } |
16 | ;; | ;; |
17 | ||
18 | let x = | let x = |
19 | [{ x with | [{ x with |
20 | foo = 3 | foo = 3 |
21 | ; bar = 5 | ; bar = 5 |
22 | }] | }] |
23 | ||
24 | let x = | let x = |
25 | [{ (* blah blah blah *) | [{ (* blah blah blah *) |
26 | ·····foo·=·3 | ····foo·=·3 |
27 | ···;·bar·=·5 | ··;·bar·=·5 |
28 | ···}] | ··}] |
29 | ;; | ;; |
30 | ||
31 | let x = | let x = |
32 | { M.x with | { M.x with |
33 | M. | M. |
34 | foo = 3 | foo = 3 |
35 | } | } |
36 | ;; | ;; |
37 | ||
38 | let x = | let x = |
39 | { x with | { x with |
40 | M. | M. |
41 | foo = 3 | foo = 3 |
42 | } | } |
43 | ;; | ;; |
44 | ||
45 | let x = | let x = |
46 | { M. | { M. |
47 | foo = 3 | foo = 3 |
48 | } | } |
49 | ;; | ;; |
50 | ||
51 | let _ = | let _ = |
52 | { foo with | { foo with |
53 | Bar. | Bar. |
54 | field1 = value1 | field1 = value1 |
55 | ; field2 = value2 | ; field2 = value2 |
56 | } | } |
57 | ;; | ;; |
58 | let _ = | let _ = |
59 | { foo | { foo |
60 | with Bar. | with Bar. |
61 | ····field1·=·value1 | ······field1·=·value1 |
62 | ··;·field2·=·value2 | ····;·field2·=·value2 |
63 | } | } |
64 | ;; | ;; |
65 | ||
66 | (* multicomponent record module pathname *) | (* multicomponent record module pathname *) |
67 | let _ = | let _ = |
68 | { A.B. | { A.B. |
69 | a = b | a = b |
70 | ; c = d | ; c = d |
71 | } | } |
72 | ;; | ;; |
Expected | Ocp-indent output | |
---|---|---|
0 | (* s *) | (* s *) |
1 | ||
2 | let _ = | let _ = |
3 | [%raise_structural_sexp | [%raise_structural_sexp |
4 | "feature's tip is already an ancestor of new base" | "feature's tip is already an ancestor of new base" |
5 | ····{·feature_tip·=·(old_tip·:·Rev.t) | ······{·feature_tip·=·(old_tip·:·Rev.t) |
6 | ····;·new_base····=·(new_base·:·Rev.t) | ······;·new_base····=·(new_base·:·Rev.t) |
7 | ····}] | ······}] |
8 | ||
9 | let _ = | let _ = |
10 | [%raise_structural_sexp "feature's tip is already an ancestor of new base" | [%raise_structural_sexp "feature's tip is already an ancestor of new base" |
11 | ····{·feature_tip·=·(old_tip·:·Rev.t) | ····························{·feature_tip·=·(old_tip·:·Rev.t) |
12 | ····;·new_base····=·(new_base·:·Rev.t) | ····························;·new_base····=·(new_base·:·Rev.t) |
13 | ····} | ····························} |
14 | ] | ] |
Expected | Ocp-indent output | |
---|---|---|
0 | (* Indentation that Jane Street needs to think about and make precise. | (* Indentation that Jane Street needs to think about and make precise. |
1 | ||
2 | These are long term ideas, possibly even conflicting with other tests. *) | These are long term ideas, possibly even conflicting with other tests. *) |
3 | ||
4 | ||
5 | ||
6 | (* js-args *) | (* js-args *) |
7 | ||
8 | let _ = | let _ = |
9 | let min_closing_backoff = | let min_closing_backoff = |
10 | -. ( Hidden_float.expose (arb.cfg.base_edge @! Buy) | -. ( Hidden_float.expose (arb.cfg.base_edge @! Buy) |
11 | ········+.·Hidden_float.expose·(arb.cfg.base_edge·@!·Sell)) | ···········+.·Hidden_float.expose·(arb.cfg.base_edge·@!·Sell)) |
12 | in | in |
13 | 0 | 0 |
14 | ||
15 | ||
16 | ||
17 | (* js-type *) | (* js-type *) |
18 | ||
19 | (* The following tests incorporate several subtle and different indentation | (* The following tests incorporate several subtle and different indentation |
20 | ideas. Please consider this only a proposal for discussion, for now. | ideas. Please consider this only a proposal for discussion, for now. |
21 | ||
22 | First, notice the display treatment of "(,)" tuples, analogous to "[;]" | First, notice the display treatment of "(,)" tuples, analogous to "[;]" |
23 | lists. While "(,)" is an intensional combination of "()" and ",", unlike | lists. While "(,)" is an intensional combination of "()" and ",", unlike |
24 | "[;]" lists, we believe "(,)" isn't too big a departure. Value expression | "[;]" lists, we believe "(,)" isn't too big a departure. Value expression |
25 | analogies are included in js-type.ml, (meant to be) consistent with the | analogies are included in js-type.ml, (meant to be) consistent with the |
26 | proposed type indentation. | proposed type indentation. |
27 | ||
28 | Second, and more divergently, the proposed indentation of function types is | Second, and more divergently, the proposed indentation of function types is |
29 | based on the idea of aligning the arguments, even the first argument, even | based on the idea of aligning the arguments, even the first argument, even |
30 | where that means automatically inserting spaces within lines. This applies | where that means automatically inserting spaces within lines. This applies |
31 | to the extra spaces in ":__unit" and "(____Config.Network.t" below. | to the extra spaces in ":__unit" and "(____Config.Network.t" below. |
32 | ||
33 | We believe this fits into a more general incorporation of alignment into | We believe this fits into a more general incorporation of alignment into |
34 | ocp-indent, to replace our internal alignment tool with a syntax-aware one. | ocp-indent, to replace our internal alignment tool with a syntax-aware one. |
35 | We like to align things for readability, like big records, record types, | We like to align things for readability, like big records, record types, |
36 | lists used to build tables, etc. | lists used to build tables, etc. |
37 | ||
38 | The proposal also includes indenting "->" in the circumstances below relative | The proposal also includes indenting "->" in the circumstances below relative |
39 | to the enclosing "()", by two spaces. In a sense, this happens first, and | to the enclosing "()", by two spaces. In a sense, this happens first, and |
40 | then the first argument is aligned accordingly. So, there's no manual | then the first argument is aligned accordingly. So, there's no manual |
41 | indentation or spacing below. *) | indentation or spacing below. *) |
42 | ||
43 | val instances | val instances |
44 | : unit | : unit |
45 | -> ( Config.Network.t | -> ( Config.Network.t |
46 | ·······->·(App.t·*·Config.instance·*·Config.app)·list | ··········->·(App.t·*·Config.instance·*·Config.app)·list |
47 | ·······->·verbose:bool | ··········->·verbose:bool |
48 | ·······->·'m | ··········->·'m |
49 | , 'm | , 'm |
50 | ) Command.Spec.t | ) Command.Spec.t |
51 | ||
52 | val instances | val instances |
53 | : unit | : unit |
54 | -> ( Config.Network.t | -> ( Config.Network.t |
55 | ·······->·(App.t·*·Config.instance·*·Config.app)·list | ··········->·(App.t·*·Config.instance·*·Config.app)·list |
56 | ·······->·verbose:bool·->·'m | ··········->·verbose:bool·->·'m |
57 | , 'm | , 'm |
58 | ) Command.Spec.t | ) Command.Spec.t |
59 | ||
60 | (* presumed analog with stars *) | (* presumed analog with stars *) |
61 | val instances : | val instances : |
62 | unit | unit |
63 | * ( Config.Network.t | * ( Config.Network.t |
64 | ······*·(App.t·*·Config.instance·*·Config.app)·list | ········*·(App.t·*·Config.instance·*·Config.app)·list |
65 | ······*·bool | ········*·bool |
66 | ······*·'m | ········*·'m |
67 | , 'm | , 'm |
68 | ) Command.Spec.t | ) Command.Spec.t |
Expected | Ocp-indent output | |
---|---|---|
0 | let f x = | let f x = |
1 | stop | stop |
2 | (* We don't do this as a matter of style, but the indentation reveals a common | (* We don't do this as a matter of style, but the indentation reveals a common |
3 | mistake. *) | mistake. *) |
4 | >>> fun () -> don't_wait_for (close fd); | >>> fun () -> don't_wait_for (close fd); |
5 | ················bind·fd | ··bind·fd |
6 | ||
7 | let f x = | let f x = |
8 | stop | stop |
9 | (* This is what was intended, which is indented correctly, although it's bad | (* This is what was intended, which is indented correctly, although it's bad |
10 | style on my part. *) | style on my part. *) |
11 | >>> (fun () -> don't_wait_for (close fd)); | >>> (fun () -> don't_wait_for (close fd)); |
12 | bind | bind |