@@ -16,7 +16,7 @@ setlocal nosmartindent
16
16
" Now, set up our indentation expression and keys that trigger it.
17
17
setlocal indentexpr = GetJavascriptIndent ()
18
18
setlocal formatexpr = Fixedgq (v: lnum ,v: count )
19
- setlocal indentkeys = 0 {,0 },0 ),0 ],0 \, ,! ^F,o ,O,e
19
+ setlocal indentkeys = 0 {,0 },0 ),0 ],0 \, : ,! ^F,o ,O,e
20
20
21
21
" Only define the function once.
22
22
if exists (" *GetJavascriptIndent" )
@@ -29,8 +29,8 @@ set cpo&vim
29
29
" 1. Variables {{{1
30
30
" ============
31
31
32
- let s: js_keywords = ' ^\s*\(break\|case\| catch\|const\|continue\|debugger\|default \|delete\|do\|else\|finally\|for\|function\|if\|in\|instanceof\|let\|new\|return\|switch\|this\|throw\|try\|typeof\|var\|void\|while\|with\)'
33
-
32
+ let s: js_keywords = ' ^\s*\(break\|catch\|const\|continue\|debugger\|delete\|do\|else\|finally\|for\|function\|if\|in\|instanceof\|let\|new\|return\|switch\|this\|throw\|try\|typeof\|var\|void\|while\|with\)'
33
+ let s: expr_case = ' ^\s*\(case\s\+[^\:]*\|default\)\s*:\s* '
34
34
" Regex of syntax group names that are or delimit string or are comments.
35
35
let s: syng_strcom = ' string\|regex\|comment\c'
36
36
@@ -53,7 +53,7 @@ let s:continuation_regex = '\%([\\*+/.:]\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\|[^=]
53
53
54
54
" Regex that defines continuation lines.
55
55
" TODO: this needs to deal with if ...: and so on
56
- let s: msl_regex = s: continuation_regex
56
+ let s: msl_regex = s: continuation_regex. ' | ' . s: expr_case
57
57
58
58
let s: one_line_scope_regex = ' \<\%(if\|else\|for\|while\)\>[^{;]*' . s: line_term
59
59
@@ -300,6 +300,17 @@ function GetJavascriptIndent()
300
300
" previous nonblank line number
301
301
let prevline = prevnonblank (v: lnum - 1 )
302
302
303
+ if (line = ~ s: expr_case )
304
+ if (getline (prevline) = ~ s: expr_case )
305
+ return indent (prevline)
306
+ else
307
+ if (getline (prevline) = ~ s: block_regex )
308
+ return indent (prevline) + &sw /2
309
+ else
310
+ return indent (prevline) - &sw /2
311
+ endif
312
+ endif
313
+ endif
303
314
" If we got a closing bracket on an empty line, find its match and indent
304
315
" according to it. For parentheses we indent to its column - 1, for the
305
316
" others we indent to the containing line's MSL's level. Return -1 if fail.
@@ -342,6 +353,9 @@ function GetJavascriptIndent()
342
353
if (getline (prevline) = ~ s: comma_first )
343
354
return indent (prevline) - &sw
344
355
endif
356
+ if (getline (prevline) = ~ s: expr_case )
357
+ return indent (prevline) + &sw /2
358
+ endif
345
359
346
360
if (line = ~ s: ternary )
347
361
if (getline (prevline) = ~ s: ternary_q )
@@ -385,15 +399,19 @@ function GetJavascriptIndent()
385
399
return 0
386
400
endif
387
401
388
- " Set up variables for current line.
389
- let line = getline (lnum)
390
- let ind = indent (lnum)
391
402
392
403
" If the previous line ended with a block opening, add a level of indent.
393
404
if s: Match (lnum, s: block_regex )
394
- return indent (s: GetMSL (lnum, 0 )) + &sw
405
+ if (line = ~ s: expr_case )
406
+ return indent (s: GetMSL (lnum, 0 )) + &sw /2
407
+ else
408
+ return indent (s: GetMSL (lnum, 0 )) + &sw
409
+ endif
395
410
endif
396
411
412
+ " Set up variables for current line.
413
+ let line = getline (lnum)
414
+ let ind = indent (lnum)
397
415
" If the previous line contained an opening bracket, and we are still in it,
398
416
" add indent depending on the bracket type.
399
417
if line = ~ ' [[({]'
0 commit comments