42
42
" ============
43
43
44
44
let s: line_pre = ' ^\s*\%(\/\*.*\*\/\s*\)*'
45
- let s: js_keywords = s: line_pre . ' \%(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\)\>\C'
45
+ let s: js_keywords = s: line_pre . ' \%(break\|import\|export\| 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\)\>\C'
46
46
let s: expr_case = s: line_pre . ' \%(case\s\+[^\:]*\|default\)\s*:\s*\C'
47
47
" Regex of syntax group names that are or delimit string or are comments.
48
48
let s: syng_strcom = ' \%(string\|regex\|comment\|template\)\c'
@@ -59,6 +59,14 @@ let s:syng_linecom = 'linecomment\c'
59
59
" Expression used to check whether we should skip a match with searchpair().
60
60
let s: skip_expr = " synIDattr(synID(line('.'),col('.'),1),'name') =~ '" .s: syng_strcom ." '"
61
61
62
+ func s: lookForParens (start ,end ,flags,stop )
63
+ try
64
+ return searchpair (a: start ,' ' ,a: end ,a: flags ,s: skip_expr ,a: stop ,300 )
65
+ catch /E118/
66
+ return searchpair (a: start ,' ' ,a: end ,a: flags ,0 ,a: stop )
67
+ endtry
68
+ endfunc
69
+
62
70
let s: line_term = ' \s*\%(\%(\/\/.*\)\=\|\%(\/\*.*\*\/\s*\)*\)$'
63
71
64
72
" Regex that defines continuation lines, not including (, {, or [.
@@ -73,7 +81,7 @@ function s:Onescope(lnum)
73
81
let mypos = col (' .' )
74
82
call cursor (a: lnum , 1 )
75
83
if search (' \<\%(while\|for\|if\)\>\s*(\C' , ' ce' , a: lnum ) > 0 &&
76
- \ searchpair (' (' , ' ' , ' )' , ' W' , s: skip_expr , a: lnum ) > 0 &&
84
+ \ s: lookForParens (' (' , ' )' , ' W' , a: lnum ) > 0 &&
77
85
\ col (' .' ) == strlen (s: RemoveTrailingComments (getline (a: lnum )))
78
86
call cursor (a: lnum , mypos)
79
87
return 1
@@ -153,7 +161,7 @@ function s:GetMSL(lnum, in_one_line_scope)
153
161
" if there are more closing brackets, continue from the line which has the matching opening bracket
154
162
elseif col2 > 0 && ! s: IsInStringOrComment (msl, col2) && s: LineHasOpeningBrackets (msl)[0 ] == ' 2' && ! a: in_one_line_scope
155
163
call cursor (msl, 1 )
156
- if searchpair (' (' , ' ' , ' )' , ' bW' , s: skip_expr ) > 0
164
+ if s: lookForParens (' (' , ' )' , ' bW' , 0 ) > 0
157
165
let lnum = line (' .' )
158
166
let msl = lnum
159
167
endif
@@ -185,17 +193,18 @@ endfunction
185
193
" Find if the string is inside var statement (but not the first string)
186
194
function s: InMultiVarStatement (lnum, cont, prev )
187
195
let lnum = s: PrevNonBlankNonString (a: lnum - 1 )
196
+ let prev = a: prev
188
197
189
198
" let type = synIDattr(synID(lnum, indent(lnum) + 1, 0), 'name')
190
199
191
200
" loop through previous expressions to find a var statement
192
201
while lnum > 0 && (s: Match (lnum, s: comma_last ) || (a: cont && getline (lnum) = ~ s: line_pre . ' }' ) ||
193
- \ s: Match (lnum,s: continuation_regex )) || (a: prev && (s: Match (a: prev , s: comma_last ) ||
194
- \ s: Match (a: prev ,s: continuation_regex )))
202
+ \ s: Match (lnum,s: continuation_regex )) || (prev && (s: Match (prev , s: comma_last ) ||
203
+ \ s: Match (prev ,s: continuation_regex )))
195
204
" if the line is a js keyword
196
205
if a: cont
197
206
call cursor (lnum,1 )
198
- let parlnum = searchpair (' (\|{\|\[' , ' ' , ' )\|}\|\]' , ' nbW' , s: skip_expr )
207
+ let parlnum = s: lookForParens (' (\|{\|\[' , ' )\|}\|\]' , ' nbW' , 0 )
199
208
if parlnum > 0
200
209
let lnum = parlnum
201
210
end
@@ -214,6 +223,7 @@ function s:InMultiVarStatement(lnum, cont, prev)
214
223
end
215
224
endif
216
225
let lnum = s: PrevNonBlankNonString (lnum - 1 )
226
+ let prev = prev && lnum > 0 ? prev : 0
217
227
endwhile
218
228
219
229
" beginning of program, not a var
@@ -348,7 +358,7 @@ function GetJavascriptIndent()
348
358
call cursor (v: lnum , col )
349
359
350
360
351
- let parlnum = searchpair (' (\|{\|\[' , ' ' , ' )\|}\|\]' , ' nbW' , s: skip_expr )
361
+ let parlnum = s: lookForParens (' (\|{\|\[' , ' )\|}\|\]' , ' nbW' , 0 )
352
362
if parlnum > 0
353
363
let ind = s: InMultiVarStatement (parlnum, 0 , 0 ) ? indent (parlnum) : indent (s: GetMSL (parlnum, 0 ))
354
364
endif
@@ -367,7 +377,7 @@ function GetJavascriptIndent()
367
377
if counts[0 ] == ' 2' || counts[1 ] == ' 2' || counts[2 ] == ' 2'
368
378
call cursor (lnum, 1 )
369
379
" Search for the opening tag
370
- let parlnum = searchpair (' (\|{\|\[' , ' ' , ' )\|}\|\]' , ' nbW' , s: skip_expr )
380
+ let parlnum = s: lookForParens (' (\|{\|\[' , ' )\|}\|\]' , ' nbW' , 0 )
371
381
if parlnum > 0 && s: Match (parlnum, s: operator_first )
372
382
return indent (parlnum)
373
383
end
@@ -382,7 +392,7 @@ function GetJavascriptIndent()
382
392
if counts[0 ] == ' 2' && ! s: Match (lnum, s: operator_first )
383
393
call cursor (lnum, 1 )
384
394
" Search for the opening tag
385
- let mnum = searchpair (' (' , ' ' , ' )' , ' nbW' , s: skip_expr )
395
+ let mnum = s: lookForParens (' (' , ' )' , ' nbW' , 0 )
386
396
if mnum > 0 && s: Match (mnum, s: operator_first )
387
397
return indent (mnum) - s: sw ()
388
398
end
@@ -432,7 +442,7 @@ function GetJavascriptIndent()
432
442
\ (counts[2 ] == ' 2' && ! s: Match (lnum, s: line_pre . ' ]' ))
433
443
call cursor (lnum, 1 )
434
444
" Search for the opening tag
435
- let parlnum = searchpair (' (\|{\|\[' , ' ' , ' )\|}\|\]' , ' nbW' , s: skip_expr )
445
+ let parlnum = s: lookForParens (' (\|{\|\[' , ' )\|}\|\]' , ' nbW' , 0 )
436
446
if parlnum > 0
437
447
return indent (s: GetMSL (parlnum, 0 ))
438
448
end
0 commit comments