@@ -17,7 +17,7 @@ setlocal nosmartindent
17
17
setlocal indentexpr = GetJavascriptIndent ()
18
18
setlocal formatexpr = Fixedgq (v: lnum ,v: count )
19
19
setlocal indentkeys = 0 {,0 },0 ),0 ],0 \, :,! ^F,o ,O,e
20
- setl cino += b0
20
+
21
21
" Only define the function once.
22
22
if exists (" *GetJavascriptIndent" )
23
23
finish
41
41
" ============
42
42
43
43
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\)'
44
- let s: expr_case = ' ^\s*\(case\s\+[^\:]*\|default\)\s*:\s*\|^\s*break\> '
44
+ let s: expr_case = ' ^\s*\(case\s\+[^\:]*\|default\)\s*:\s*'
45
45
" Regex of syntax group names that are or delimit string or are comments.
46
46
let s: syng_strcom = ' \%(\%(template\)\@<!string\|regex\|comment\)\c'
47
47
@@ -65,10 +65,6 @@ let s:line_term = '\s*\%(\%(\/\/\).*\)\=$'
65
65
" Regex that defines continuation lines, not including (, {, or [.
66
66
let s: continuation_regex = ' \%([\\*/.:]\|+\@<!+\|-\@<!-\|\%(<%\)\@<!=\|\W[|&?]\|||\|&&\|[^=]=[^=>].*,\)' . s: line_term
67
67
68
- " Regex that defines continuation lines.
69
- " TODO: this needs to deal with if ...: and so on
70
- let s: msl_regex = s: continuation_regex .' \|' .s: expr_case
71
-
72
68
let s: one_line_scope_regex = ' \%(\%(\<else\>\|\<\%(if\|for\|while\)\>\s*(\%([^()]*\|[^()]*(\%([^()]*\|[^()]*(\%([^()]*\|[^()]*([^()]*)[^()]*\))[^()]*\))[^()]*\))\)\|=>\)' . s: line_term
73
69
74
70
" Regex that defines blocks.
@@ -81,8 +77,8 @@ let s:var_stmt = '^\s*\%(const\|let\|var\)'
81
77
let s: comma_first = ' ^\s*,'
82
78
let s: comma_last = ' ,\s*$'
83
79
84
- " " 2. Auxiliary Functions {{{1
85
- " " ======================
80
+ " 2. Auxiliary Functions {{{1
81
+ " ======================
86
82
87
83
" Check if the character at lnum:col is inside a string, comment, or is ascii.
88
84
function s: IsInStringOrComment (lnum, col )
@@ -142,10 +138,10 @@ function s:GetMSL(lnum, in_one_line_scope)
142
138
" If we have a continuation line, or we're in a string, use line as MSL.
143
139
" Otherwise, terminate search as we have found our MSL already.
144
140
let line = getline (lnum)
145
- let col = match (line , s: msl_regex ) + 1
141
+ let col = match (line , s: continuation_regex ) + 1
146
142
let line2 = getline (msl)
147
143
let col2 = matchend (line2, ' )' )
148
- if (col > 0 && ! s: IsInStringOrComment (lnum, col )) || s: IsInString (lnum, strlen (line ))
144
+ if (col > 0 && ! s: IsInStringOrComment (lnum, col ) && ! s: Match (lnum, s: expr_case ) ) || s: IsInString (lnum, strlen (line ))
149
145
let msl = lnum
150
146
151
147
" if there are more closing brackets, continue from the line which has the matching opening bracket
@@ -317,7 +313,6 @@ endfunction
317
313
function GetJavascriptIndent ()
318
314
" 3.1. Setup {{{2
319
315
" ----------
320
-
321
316
" Set up variables for restoring position in file. Could use v:lnum here.
322
317
let vcol = col (' .' )
323
318
@@ -331,13 +326,7 @@ function GetJavascriptIndent()
331
326
let prevline = prevnonblank (v: lnum - 1 )
332
327
333
328
if (line = ~ s: expr_case )
334
- if (getline (prevline) = ~ s: expr_case )
335
- return cindent (line )
336
- else
337
- if (getline (prevline) !~ s: block_regex )
338
- return cindent (line )
339
- endif
340
- endif
329
+ return cindent (v: lnum )
341
330
endif
342
331
" If we got a closing bracket on an empty line, find its match and indent
343
332
" according to it. For parentheses we indent to its column - 1, for the
@@ -382,7 +371,7 @@ function GetJavascriptIndent()
382
371
return indent (prevline) - s: sw ()
383
372
endif
384
373
if (getline (prevline) = ~ s: expr_case )
385
- return cindent (line )
374
+ return cindent (v: lnum )
386
375
endif
387
376
388
377
" If line starts with an operator...
0 commit comments