@@ -72,7 +72,9 @@ function s:Onescope(lnum)
72
72
end
73
73
let mypos = col (' .' )
74
74
call cursor (a: lnum , 1 )
75
- if search (' \<\%(while\|for\|if\)\>\s*(\C' , ' ce' , a: lnum ) > 0 && searchpair (' (' , ' ' , ' )' , ' W' , s: skip_expr , a: lnum ) > 0 && col (' .' ) == strlen (s: RemoveTrailingComments (getline (a: lnum )))
75
+ if search (' \<\%(while\|for\|if\)\>\s*(\C' , ' ce' , a: lnum ) > 0 &&
76
+ \ searchpair (' (' , ' ' , ' )' , ' W' , s: skip_expr , a: lnum ) > 0 &&
77
+ \ col (' .' ) == strlen (s: RemoveTrailingComments (getline (a: lnum )))
76
78
call cursor (a: lnum , mypos)
77
79
return 1
78
80
else
@@ -84,11 +86,10 @@ endfunction
84
86
" Regex that defines blocks.
85
87
let s: block_regex = ' [{([]' . s: line_term
86
88
87
- let s: operator_first = s: line_pre . ' \%([.:?]\|\([-/+*]\)\%(\1\|\*\|\/\)\@!\|||\|&&\)'
89
+ let s: operator_first = s: line_pre . ' \%([., :?]\|\([-/+*]\)\%(\1\|\*\|\/\)\@!\|||\|&&\)'
88
90
89
91
let s: var_stmt = s: line_pre . ' \%(const\|let\|var\)\s\+\C'
90
92
91
- let s: comma_first = s: line_pre . ' ,'
92
93
let s: comma_last = ' ,' . s: line_term
93
94
94
95
" 2. Auxiliary Functions {{{1
@@ -148,9 +149,11 @@ function s:GetMSL(lnum, in_one_line_scope)
148
149
" Otherwise, terminate search as we have found our MSL already.
149
150
let line = getline (lnum)
150
151
let col = match (line , s: continuation_regex ) + 1
152
+ let coal = match (line , s: comma_last ) + 1
151
153
let line2 = getline (msl)
152
154
let col2 = matchend (line2, ' )' )
153
- if (col > 0 && ! s: IsInStringOrComment (lnum, col ) && ! s: Match (lnum, s: expr_case )) || s: IsInString (lnum, strlen (line ))
155
+ if ((col > 0 && ! s: IsInStringOrComment (lnum, col ) || coal > 0 && ! s: IsInStringOrComment (lnum,coal)) &&
156
+ \ ! s: Match (lnum, s: expr_case )) || s: IsInString (lnum, strlen (line ))
154
157
let msl = lnum
155
158
156
159
" if there are more closing brackets, continue from the line which has the matching opening bracket
@@ -192,7 +195,9 @@ function s:InMultiVarStatement(lnum, cont, prev)
192
195
" let type = synIDattr(synID(lnum, indent(lnum) + 1, 0), 'name')
193
196
194
197
" loop through previous expressions to find a var statement
195
- while lnum > 0 && (s: Match (lnum, s: comma_last ) || (a: cont && getline (lnum) = ~ s: line_pre . ' }' ) || (a: prev && s: Match (a: prev , s: comma_last )))
198
+ while lnum > 0 && (s: Match (lnum, s: comma_last ) || (a: cont && getline (lnum) = ~ s: line_pre . ' }' ) ||
199
+ \ s: Match (lnum,s: continuation_regex )) || (a: prev && (s: Match (a: prev , s: comma_last ) ||
200
+ \ s: Match (a: prev ,s: continuation_regex )))
196
201
" if the line is a js keyword
197
202
if a: cont
198
203
call cursor (lnum,1 )
@@ -204,12 +209,12 @@ function s:InMultiVarStatement(lnum, cont, prev)
204
209
" check if the line is a var stmt
205
210
" if the line has a comma first or comma last then we can assume that we
206
211
" are in a multiple var statement
207
- if s: Match (lnum, s: var_stmt ) && s: Match (lnum, s: comma_last )
212
+ if s: Match (lnum, s: var_stmt ) && ( s: Match (lnum, s: comma_last) || s: Match (lnum, s: continuation_regex ) )
208
213
return lnum
209
214
endif
210
215
211
216
" other js keywords, not a var
212
- if ! s: Match (lnum, s: comma_last )
217
+ if ! s: Match (lnum, s: comma_last )|| ! s: Match (lnum, s: continuation_regex )
213
218
return 0
214
219
end
215
220
endif
@@ -348,7 +353,7 @@ function GetJavascriptIndent()
348
353
349
354
" If we are in a multi-line comment, cindent does the right thing.
350
355
if s: IsInMultilineComment (v: lnum , 1 ) && ! s: IsLineComment (v: lnum , 1 ) &&
351
- \ s: IsInMultilineComment (v: lnum , match (line , ' \s*$' )) && line !~ ' ^\/\*'
356
+ \ s: IsInMultilineComment (v: lnum , match (line , ' \s*$' )) && line !~ ' ^\/\*'
352
357
return cindent (v: lnum )
353
358
endif
354
359
@@ -362,38 +367,13 @@ function GetJavascriptIndent()
362
367
return cindent (v: lnum )
363
368
endif
364
369
365
- " the part first where we deal with comma first
366
- if line = ~ s: comma_first
367
- let counts = s: LineHasOpeningBrackets (prevline)
368
- if (s: Match (prevline, s: var_stmt ) || counts[0 ] == ' 1' || counts[1 ] == ' 1' || counts[2 ] == ' 1' )
369
- return indent (prevline) + s: sw ()
370
- end
371
- end
372
370
" If we got a closing bracket on an empty line, find its match and indent
373
371
" according to it. For parentheses we indent to its column - 1, for the
374
372
" others we indent to the containing line's MSL's level. Return -1 if fail.
375
- let col = matchend (line , s: line_pre . ' [], })]' )
373
+ let col = matchend (line , s: line_pre . ' []})]' )
376
374
if col > 0 && ! s: IsInStringOrComment (v: lnum , col )
377
375
call cursor (v: lnum , col )
378
376
379
- let lvar = s: InMultiVarStatement (v: lnum , 0 , 0 ) || line = ~ s: comma_first
380
- if lvar || line = ~ s: comma_first
381
-
382
- " check for comma first
383
- if (line [col - 1 ] = ~ ' ,' )
384
- " if the previous line ends in comma or semicolon don't indent
385
- if (getline (prevline) = ~ ' [;,]' . s: line_term )
386
- return indent (s: GetMSL (line (' .' ), 0 ))
387
- " get previous line indent, if it's comma first return prevline indent
388
- elseif s: Match (prevline, s: comma_first )
389
- return indent (prevline)
390
- " otherwise we indent 1 level
391
- else
392
- return indent (lvar) + s: sw ()
393
- endif
394
- endif
395
- endif
396
-
397
377
398
378
let bs = strpart (' (){}[]' , stridx (' )}]' , line [col - 1 ]) * 2 , 2 )
399
379
if searchpair (escape (bs [0 ], ' \[' ), ' ' , bs [1 ], ' bW' , s: skip_expr ) > 0
@@ -402,31 +382,27 @@ function GetJavascriptIndent()
402
382
return ind
403
383
endif
404
384
405
- " If the line is comma first, dedent 1 level
406
- if s: Match (prevline, s: comma_first )
407
- return indent (prevline) - s: sw ()
408
- end
409
-
410
385
" If line starts with an operator...
411
386
if (line = ~ s: operator_first )
412
387
if (s: Match (prevline, s: operator_first ))
413
388
" and so does previous line, don't indent
414
389
return indent (prevline)
415
390
end
416
391
let counts = s: LineHasOpeningBrackets (prevline)
417
- if counts[0 ] == ' 2'
392
+ if counts[0 ] == ' 2' || counts[ 1 ] == ' 2 ' || counts[ 2 ] == ' 2 '
418
393
call cursor (prevline, 1 )
419
394
" Search for the opening tag
420
- let mnum = searchpair (' (' , ' ' , ' ) ' , ' bW ' , s: skip_expr )
421
- if mnum > 0 && s: Match (mnum , s: operator_first )
422
- return indent (mnum )
395
+ let bs = strpart (' (){}[] ' , stridx ( ' )}] ' , line [ col - 1 ]) * 2 , 2 )
396
+ if searchpair ( escape ( bs [ 0 ], ' \[ ' ), ' ' , bs [ 1 ], ' bW ' , s: skip_expr ) > 0 && s: Match (line ( ' . ' ) , s: operator_first )
397
+ return indent (line ( ' . ' ) )
423
398
end
424
399
elseif counts[0 ] != ' 1' && counts[1 ] != ' 1' && counts[2 ] != ' 1'
425
400
" otherwise, indent 1 level
426
401
return indent (prevline) + s: sw ()
427
402
end
403
+
428
404
" If previous line starts with an operator...
429
- elseif (s: Match (prevline, s: operator_first ) && getline (prevline) !~ s: comma_last && getline (prevline) !~ ' };\= ' . s: line_term ) || getline (prevline) = ~ ' );\=' . s: line_term
405
+ elseif (s: Match (prevline, s: operator_first ) && ! s: Match (prevline, s: continuation_regex )) || getline (prevline) = ~ ' );\=' . s: line_term
430
406
let counts = s: LineHasOpeningBrackets (prevline)
431
407
if counts[0 ] == ' 2' && ! s: Match (prevline, s: operator_first )
432
408
call cursor (prevline, 1 )
@@ -436,14 +412,7 @@ function GetJavascriptIndent()
436
412
return indent (mnum) - s: sw ()
437
413
end
438
414
elseif s: Match (prevline, s: operator_first )
439
- if counts[0 ] == ' 2' && counts[1 ] == ' 1'
440
- call cursor (prevline, 1 )
441
- " Search for the opening tag
442
- let mnum = searchpair (' (' , ' ' , ' )' , ' bW' , s: skip_expr )
443
- if mnum > 0 && ! s: Match (mnum, s: operator_first )
444
- return indent (mnum) + s: sw ()
445
- end
446
- elseif counts[0 ] != ' 1' && counts[1 ] != ' 1' && counts[2 ] != ' 1'
415
+ if counts[0 ] != ' 1' && counts[1 ] != ' 1' && counts[2 ] != ' 1'
447
416
return indent (prevline) - s: sw ()
448
417
end
449
418
end
0 commit comments