Permalink
Browse files

Better indent between 'match' and 'with'

  • Loading branch information...
1 parent 6d82234 commit a91340d624f89834d4edb0f21e1ecfa5b68d0aeb @AltGr AltGr committed Mar 28, 2013
Showing with 44 additions and 12 deletions.
  1. +30 −7 src/indentBlock.ml
  2. +4 −4 tests/failing.html
  3. +1 −1 tests/passing/pattern.ml
  4. +9 −0 tests/passing/unit-expr.ml
View
@@ -570,8 +570,28 @@ let rec update_path config t stream tok =
| BEGIN -> open_paren KBegin t.path
| OBJECT -> append KObject L t.path
| VAL -> append KVal L (unwind_top t.path)
- | MATCH -> append KMatch L (fold_expr t.path)
- | TRY -> append KTry L (fold_expr t.path)
+ | MATCH ->
+ let p = fold_expr t.path in
+ if starts_line then append KMatch L p
+ else
+ let p = match p with
+ | {k=KBegin; l; t} as beg :: p
+ when t = l && config.i_strict_with <> Never ->
+ {beg with pad = 0}::p
+ | _ -> p
+ in
+ append KMatch L ~pad:(Path.pad p + config.i_base) p
+ | TRY ->
+ let p = fold_expr t.path in
+ if starts_line then append KTry L p
+ else
+ let p = match p with
+ | {k=KBegin; l; t} as beg :: p
+ when t = l && config.i_strict_with <> Never ->
+ {beg with pad = 0}::p
+ | _ -> p
+ in
+ append KTry L ~pad:(Path.pad p + config.i_base) p
| LPAREN -> open_paren KParen t.path
| LBRACKET | LBRACKETGREATER | LBRACKETLESS ->
open_paren KBracket t.path
@@ -722,16 +742,19 @@ let rec update_path config t stream tok =
| _ ->
append (KWith KBrace) L ~pad:(pad + config.i_with) path)
| {k=KVal|KType|KException as k}::_ -> replace (KWith k) L path
- | {k=KTry|KMatch} as n :: {pad;k} :: _
+ | {k=KTry|KMatch} as n :: {pad} :: _
when n.line = Region.start_line tok.region
&& n.t <> n.l
- && (config.i_strict_with = Never
- || config.i_strict_with = Auto && k <> KBegin) ->
+ && config.i_strict_with <> Always
+ ->
replace (KWith KMatch)
L ~pad:(max pad config.i_with)
path
- | {k=(KTry|KMatch as k)}::_ ->
- replace (KWith k) L ~pad:config.i_with path
+ | {k=(KTry|KMatch as k)}::p ->
+ if starts_line then
+ append (KWith k) L ~pad:config.i_with p
+ else
+ replace (KWith k) L ~pad:config.i_with path
| _ -> path)
| IF ->
View
@@ -2,7 +2,7 @@
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
- <title>Failing tests, ocp-indent version 1.1.0+9 (2013-03-28)</title>
+ <title>Failing tests, ocp-indent version 1.1.0+10 (2013-03-28)</title>
<style>
BODY { font-family: monospace; }
TABLE { border-collapse: collapse; border-spacing: 0px; margin: auto; }
@@ -22,7 +22,7 @@
</style>
</head>
<body>
-<h1>Failing tests, ocp-indent version 1.1.0+9 (2013-03-28)</h1>
+<h1>Failing tests, ocp-indent version 1.1.0+10 (2013-03-28)</h1>
<p>Left is expected result, right shows actual indentation by ocp-indent</p>
<table>
<tr><td width="70%">
@@ -370,7 +370,7 @@
</tr>
</table>
<hr/>
-<i>Generated by <b>diff2html</b> on 2013-03-28 14:01:08</i>
+<i>Generated by <b>diff2html</b> on 2013-03-28 14:01:15</i>
<table>
<tr><td width="70%">
<table>
@@ -1270,6 +1270,6 @@
</tr>
</table>
<hr/>
-<i>Generated by <b>diff2html</b> on 2013-03-28 14:01:10</i>
+<i>Generated by <b>diff2html</b> on 2013-03-28 14:01:17</i>
</body>
</html>
@@ -65,4 +65,4 @@ let fun_dep ulam = function
let _ =
(match bla
- with bli)
+ with bli)
@@ -140,6 +140,15 @@ let e =
->
true
+let e = match
+ true
+ with
+ | true ->
+ false
+ | false
+ ->
+ true
+
let e =
function
| true ->

0 comments on commit a91340d

Please sign in to comment.