@@ -69,6 +69,7 @@ fn rust_printer(ioivec::writer writer) -> ps {
69
69
}
70
70
71
71
const uint indent_unit = 4 u ;
72
+ const uint alt_indent_unit = 2 u;
72
73
73
74
const uint default_columns = 78 u;
74
75
@@ -165,12 +166,14 @@ fn bopen(&ps s) {
165
166
166
167
}
167
168
168
- fn bclose ( & ps s, codemap:: span span) {
169
+ fn bclose_ ( & ps s, codemap:: span span, uint indented ) {
169
170
maybe_print_comment ( s, span. hi ) ;
170
- break_offset ( s. s , 1 u, -( indent_unit as int ) ) ;
171
+ break_offset ( s. s , 1 u, -( indented as int ) ) ;
171
172
word ( s. s , "}" ) ;
172
173
end ( s) ; // close the outer-box
173
-
174
+ }
175
+ fn bclose ( & ps s, codemap:: span span) {
176
+ bclose_ ( s, span, indent_unit) ;
174
177
}
175
178
176
179
fn hardbreak_if_not_bol ( & ps s) {
@@ -572,10 +575,11 @@ fn print_stmt(&ps s, &ast::stmt st) {
572
575
}
573
576
574
577
fn print_block ( & ps s, & ast:: block blk) {
575
- print_possibly_embedded_block ( s, blk, false ) ;
578
+ print_possibly_embedded_block ( s, blk, false , indent_unit ) ;
576
579
}
577
580
578
- fn print_possibly_embedded_block ( & ps s, & ast:: block blk, bool embedded ) {
581
+ fn print_possibly_embedded_block ( & ps s, & ast:: block blk, bool embedded ,
582
+ uint indented ) {
579
583
maybe_print_comment ( s, blk. span . lo ) ;
580
584
auto ann_node = node_block ( s, blk) ;
581
585
s. ann . pre ( ann_node) ;
@@ -593,7 +597,7 @@ fn print_possibly_embedded_block(&ps s, &ast::block blk, bool embedded) {
593
597
}
594
598
case ( _) { }
595
599
}
596
- bclose ( s, blk. span ) ;
600
+ bclose_ ( s, blk. span , indented ) ;
597
601
s. ann . post ( ann_node) ;
598
602
}
599
603
@@ -603,9 +607,7 @@ fn print_if(&ps s, &@ast::expr test, &ast::block block,
603
607
if ( chk) {
604
608
word_nbsp ( s, "check" ) ;
605
609
}
606
- popen ( s) ;
607
610
print_expr ( s, test) ;
608
- pclose ( s) ;
609
611
space ( s. s ) ;
610
612
print_block ( s, block) ;
611
613
fn do_else ( & ps s, option:: t[ @ast:: expr ] els) {
@@ -658,7 +660,7 @@ fn print_mac(&ps s, &ast::mac m) {
658
660
word ( s. s , ">" ) ;
659
661
}
660
662
case ( ast:: mac_embed_block ( ?blk) ) {
661
- print_possibly_embedded_block ( s, blk, true ) ;
663
+ print_possibly_embedded_block ( s, blk, true , indent_unit ) ;
662
664
}
663
665
case ( ast:: mac_ellipsis) {
664
666
word ( s. s , "..." ) ;
@@ -788,9 +790,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
788
790
}
789
791
case ( ast:: expr_while ( ?test, ?block) ) {
790
792
head ( s, "while" ) ;
791
- popen ( s) ;
792
793
print_expr ( s, test) ;
793
- pclose ( s) ;
794
794
space ( s. s ) ;
795
795
print_block ( s, block) ;
796
796
}
@@ -822,30 +822,30 @@ fn print_expr(&ps s, &@ast::expr expr) {
822
822
print_block ( s, block) ;
823
823
space ( s. s ) ;
824
824
word_space ( s, "while" ) ;
825
- popen ( s) ;
826
825
print_expr ( s, expr) ;
827
- pclose ( s) ;
828
826
}
829
827
case ( ast:: expr_alt ( ?expr, ?arms) ) {
830
- head ( s, "alt" ) ;
831
- popen ( s) ;
828
+ cbox ( s, alt_indent_unit) ;
829
+ ibox ( s, 4 u) ;
830
+ word_nbsp ( s, "alt" ) ;
832
831
print_expr ( s, expr) ;
833
- pclose ( s) ;
834
832
space ( s. s ) ;
835
833
bopen ( s) ;
836
834
for ( ast:: arm arm in arms) {
837
835
space ( s. s ) ;
838
- head ( s, "case" ) ;
836
+ cbox ( s, alt_indent_unit) ;
837
+ ibox ( s, 0 u) ;
839
838
auto first = true ;
840
839
for ( @ast:: pat p in arm. pats) {
841
840
if ( first) { first = false ; }
842
841
else { space ( s. s ) ; word_space ( s, "|" ) ; }
843
842
print_pat ( s, p) ;
844
843
}
845
844
space ( s. s ) ;
846
- print_block ( s, arm. block ) ;
845
+ print_possibly_embedded_block ( s, arm. block , false ,
846
+ alt_indent_unit) ;
847
847
}
848
- bclose ( s, expr. span ) ;
848
+ bclose_ ( s, expr. span , alt_indent_unit ) ;
849
849
}
850
850
case ( ast:: expr_fn ( ?f) ) {
851
851
head ( s, proto_to_str ( f. proto ) ) ;
0 commit comments