Skip to content

Commit 5cbbdd4

Browse files
committed
Case indent: use cinoptions : and = values
:N Place case labels N characters from the indent of the switch(). (default 'shiftwidth'). =N Place statements occurring after a case label N characters from the indent of the label. (default 'shiftwidth'). (Same as default cindent)
1 parent 487e0c6 commit 5cbbdd4

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

indent/javascript.vim

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ let s:comma_last = ',\s*$'
6868
let s:ternary = '^\s\+[?|:]'
6969
let s:ternary_q = '^\s\+?'
7070

71+
let s:case_indent = &sw
72+
let s:case_indent_after = &sw
73+
let m = matchlist(&cinoptions, ':\(.\)')
74+
if (len(m) > 2)
75+
let s:case_indent = m[1]
76+
endif
77+
let m = matchlist(&cinoptions, '=\(.\)')
78+
if (len(m) > 2)
79+
let s:case_indent_after = m[1]
80+
endif
7181
" 2. Auxiliary Functions {{{1
7282
" ======================
7383

@@ -305,9 +315,9 @@ function GetJavascriptIndent()
305315
return indent(prevline)
306316
else
307317
if (getline(prevline) =~ s:block_regex)
308-
return indent(prevline) + &sw/2
318+
return indent(prevline) + s:case_indent
309319
else
310-
return indent(prevline) - &sw/2
320+
return indent(prevline) - s:case_indent_after
311321
endif
312322
endif
313323
endif
@@ -354,7 +364,7 @@ function GetJavascriptIndent()
354364
return indent(prevline) - &sw
355365
endif
356366
if (getline(prevline) =~ s:expr_case)
357-
return indent(prevline) + &sw/2
367+
return indent(prevline) + s:case_indent_after
358368
endif
359369

360370
if (line =~ s:ternary)

0 commit comments

Comments
 (0)