15
15
'punctuation.section.group.end.cfml'
16
16
]
17
17
18
+ non_indent_regions = [
19
+ 'embedding.cfml -source.cfml.script' ,
20
+ 'comment.block.cfml -punctuation.definition.comment.cfml' ,
21
+ 'meta.string -punctuation.definition.string.begin'
22
+ ]
23
+
24
+ switch_block_end = 'meta.switch.cfml meta.block.cfml punctuation.section.block.end.cfml'
25
+
18
26
19
27
def indent_region (cfml_format ):
20
28
start_indent_selector = ',' .join (start_indent_selectors )
21
29
end_indent_selector = ',' .join (end_indent_selectors )
22
30
accessor_selector = 'punctuation.accessor.cfml'
23
31
24
- non_cfscript_regions = cfml_format .view .find_by_selector ('embedding.cfml -source.cfml.script' )
32
+ non_cfscript_regions = cfml_format .view .find_by_selector (',' . join ( non_indent_regions ) )
25
33
non_cfscript_lines = []
26
34
for r in non_cfscript_regions :
27
35
non_cfscript_lines .extend (cfml_format .view .split_by_newlines (r ))
@@ -32,13 +40,14 @@ def indent_region(cfml_format):
32
40
33
41
indent_level = 0
34
42
leading_comma_flag = False
43
+ switch_case_flag = None
35
44
replacements = []
36
45
37
46
if lines [0 ].begin () < cfml_format .region_to_format .begin ():
38
47
first_line_str = cfml_format .view .substr (lines [0 ])
39
48
first_line_stripped = first_line_str .rstrip ()
40
49
if first_line_stripped [- 1 ] in ['{' , '(' , '[' ]:
41
- last_char_pt = lines [0 ].begin () + len (first_line_stripped . rstrip () ) - 1
50
+ last_char_pt = lines [0 ].begin () + len (first_line_stripped ) - 1
42
51
if cfml_format .view .match_selector (last_char_pt , start_indent_selector ):
43
52
indent_level += 1
44
53
lines = lines [1 :]
@@ -57,11 +66,25 @@ def indent_region(cfml_format):
57
66
first_line_char = stripped_line_str [0 ]
58
67
59
68
if first_line_char in ['}' , ')' , ']' , ',' , '.' ]:
60
- first_char_pt = l .begin () + full_line_str .index (stripped_line_str [ 0 ] )
69
+ first_char_pt = l .begin () + full_line_str .index (first_line_char )
61
70
62
71
if first_line_char in ['}' , ')' , ']' ] and cfml_format .view .match_selector (first_char_pt , end_indent_selector ):
63
72
indent_level -= 1
64
73
74
+ if first_line_char == '}' and switch_case_flag == 'case_block' :
75
+ scope_name = cfml_format .view .scope_name (first_char_pt )
76
+ if scope_name .strip ().endswith (switch_block_end ):
77
+ switch_case_flag = None
78
+ indent_level -= 1
79
+
80
+ if stripped_line_str [- 1 ] == ':' :
81
+ last_char_pt = l .begin () + len (full_line_str .rstrip ()) - 1
82
+ scope_name = cfml_format .view .scope_name (last_char_pt )
83
+ if scope_name .strip ().endswith ('meta.switch.cfml meta.block.cfml punctuation.separator.cfml' ):
84
+ if switch_case_flag == 'case_block' :
85
+ indent_level -= 1
86
+ switch_case_flag = 'case_start'
87
+
65
88
indent_columns = base_indent_column + (cfml_format .tab_size * indent_level )
66
89
67
90
# leading comma alignment
@@ -90,6 +113,10 @@ def indent_region(cfml_format):
90
113
if cfml_format .view .match_selector (last_char_pt , start_indent_selector ):
91
114
indent_level += 1
92
115
116
+ if switch_case_flag == 'case_start' :
117
+ indent_level += 1
118
+ switch_case_flag = 'case_block'
119
+
93
120
replacement_str = '\n ' .join (replacements )
94
121
95
122
return [(sublime .Region (lines [0 ].begin (), lines [- 1 ].end ()), replacement_str )]
0 commit comments