@@ -360,7 +360,7 @@ function GetJavascriptIndent()
360
360
if line [col - 1 ]== ' )' && col (' .' ) != col (' $' ) - 1
361
361
let ind = virtcol (' .' )-1
362
362
else
363
- let ind = indent (s: GetMSL (line (' .' ), 0 ))
363
+ let ind = s: InMultiVarStatement ( line ( ' . ' )) ? indent ( line ( ' . ' )) : indent (s: GetMSL (line (' .' ), 0 ))
364
364
endif
365
365
endif
366
366
return ind
@@ -369,7 +369,9 @@ function GetJavascriptIndent()
369
369
" If the line is comma first, dedent 1 level
370
370
if (getline (prevline) = ~ s: comma_first )
371
371
return indent (prevline) - s: sw ()
372
- endif
372
+ elseif getline (s: PrevNonBlankNonString (prevline - 1 )) = ~ ' [])}]' . s: comma_last && getline (prevline) !~ s: comma_last && getline (prevline) !~ s: block_regex
373
+ return indent (prevline) - s: sw ()
374
+ end
373
375
374
376
" If line starts with an operator...
375
377
if (s: Match (v: lnum , s: operator_first ))
@@ -390,17 +392,26 @@ function GetJavascriptIndent()
390
392
return indent (prevline) + s: sw ()
391
393
end
392
394
" If previous line starts with an operator...
393
- elseif s: Match (prevline, s: operator_first ) && ! s: Match (prevline, s: comma_last ) && ! s: Match (prevline, ' };\=' . s: line_term )
395
+ elseif ( s: Match (prevline, s: operator_first ) && ! s: Match (prevline, s: comma_last ) && ! s: Match (prevline, ' };\= ' . s: line_term )) || s: Match (prevline, ' ) ;\=' . s: line_term )
394
396
let counts = s: LineHasOpeningBrackets (prevline)
395
- if counts[0 ] == ' 2' && counts[ 1 ] == ' 1 '
397
+ if counts[0 ] == ' 2' && ! s: Match (prevline, s: operator_first )
396
398
call cursor (prevline, 1 )
397
399
" Search for the opening tag
398
400
let mnum = searchpair (' (' , ' ' , ' )' , ' bW' , s: skip_expr )
399
- if mnum > 0 && ! s: Match (mnum, s: operator_first )
400
- return indent (mnum) + s: sw ()
401
+ if mnum > 0 && s: Match (mnum, s: operator_first )
402
+ return indent (mnum) - s: sw ()
403
+ end
404
+ elseif s: Match (prevline, s: operator_first )
405
+ if counts[0 ] == ' 2' && counts[1 ] == ' 1'
406
+ call cursor (prevline, 1 )
407
+ " Search for the opening tag
408
+ let mnum = searchpair (' (' , ' ' , ' )' , ' bW' , s: skip_expr )
409
+ if mnum > 0 && ! s: Match (mnum, s: operator_first )
410
+ return indent (mnum) + s: sw ()
411
+ end
412
+ elseif counts[0 ] != ' 1' && counts[1 ] != ' 1' && counts[2 ] != ' 1'
413
+ return indent (prevline) - s: sw ()
401
414
end
402
- elseif counts[0 ] != ' 1' && counts[1 ] != ' 1' && counts[2 ] != ' 1'
403
- return indent (prevline) - s: sw ()
404
415
end
405
416
end
406
417
@@ -449,45 +460,33 @@ function GetJavascriptIndent()
449
460
450
461
" If the previous line ended with a block opening, add a level of indent.
451
462
if s: Match (lnum, s: block_regex )
452
- return indent (s: GetMSL (lnum, 0 )) + s: sw ()
463
+ return s: InMultiVarStatement (lnum) ? indent (lnum) + s: sw () : indent (s: GetMSL (lnum, 0 )) + s: sw ()
453
464
endif
454
465
455
466
" Set up variables for current line.
456
467
let line = getline (lnum)
457
468
let ind = indent (lnum)
458
469
" If the previous line contained an opening bracket, and we are still in it,
459
470
" add indent depending on the bracket type.
460
- if line = ~ ' [[({]'
471
+ if line = ~ ' [[({})\] ]'
461
472
let counts = s: LineHasOpeningBrackets (lnum)
462
473
if counts[0 ] == ' 1' && searchpair (' (' , ' ' , ' )' , ' bW' , s: skip_expr ) > 0
463
474
if col (' .' ) + 1 == col (' $' ) || line = ~ s: one_line_scope_regex
464
475
return ind + s: sw ()
465
476
else
466
477
return virtcol (' .' )
467
478
endif
468
- elseif counts[1 ] == ' 1' || counts[2 ] == ' 1' && counts[0 ] != ' 2'
469
- return ind + s: sw ()
470
- else
471
- call cursor (v: lnum , vcol)
472
- end
473
- elseif line = ~ ' .\+};\=' . s: line_term
474
- call cursor (lnum, 1 )
475
- " Search for the opening tag
476
- let mnum = searchpair (' {' , ' ' , ' }' , ' bW' , s: skip_expr )
477
- if mnum > 0
478
- return indent (s: GetMSL (mnum, 0 ))
479
- end
480
- elseif line = ~ ' .\+);\=' || line = ~ s: comma_last
481
- let counts = s: LineHasOpeningBrackets (lnum)
482
- if counts[0 ] == ' 2'
479
+ elseif counts[0 ] == ' 2'
483
480
call cursor (lnum, 1 )
484
481
" Search for the opening tag
485
482
let mnum = searchpair (' (' , ' ' , ' )' , ' bW' , s: skip_expr )
486
483
if mnum > 0
487
484
return indent (s: GetMSL (mnum, 0 ))
488
485
end
489
- elseif line !~ s: var_stmt
490
- return indent (prevline)
486
+ elseif counts[1 ] == ' 1' || counts[2 ] == ' 1' && counts[0 ] != ' 2'
487
+ return ind + s: sw ()
488
+ else
489
+ call cursor (v: lnum , vcol)
491
490
end
492
491
end
493
492
0 commit comments