@@ -360,7 +360,7 @@ function GetJavascriptIndent()
360360 if line [col - 1 ]== ' )' && col (' .' ) != col (' $' ) - 1
361361 let ind = virtcol (' .' )-1
362362 else
363- let ind = indent (s: GetMSL (line (' .' ), 0 ))
363+ let ind = s: InMultiVarStatement ( line ( ' . ' )) ? indent ( line ( ' . ' )) : indent (s: GetMSL (line (' .' ), 0 ))
364364 endif
365365 endif
366366 return ind
@@ -369,7 +369,9 @@ function GetJavascriptIndent()
369369 " If the line is comma first, dedent 1 level
370370 if (getline (prevline) = ~ s: comma_first )
371371 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
373375
374376 " If line starts with an operator...
375377 if (s: Match (v: lnum , s: operator_first ))
@@ -390,17 +392,26 @@ function GetJavascriptIndent()
390392 return indent (prevline) + s: sw ()
391393 end
392394 " 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 )
394396 let counts = s: LineHasOpeningBrackets (prevline)
395- if counts[0 ] == ' 2' && counts[ 1 ] == ' 1 '
397+ if counts[0 ] == ' 2' && ! s: Match (prevline, s: operator_first )
396398 call cursor (prevline, 1 )
397399 " Search for the opening tag
398400 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 ()
401414 end
402- elseif counts[0 ] != ' 1' && counts[1 ] != ' 1' && counts[2 ] != ' 1'
403- return indent (prevline) - s: sw ()
404415 end
405416 end
406417
@@ -449,45 +460,33 @@ function GetJavascriptIndent()
449460
450461 " If the previous line ended with a block opening, add a level of indent.
451462 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 ()
453464 endif
454465
455466 " Set up variables for current line.
456467 let line = getline (lnum)
457468 let ind = indent (lnum)
458469 " If the previous line contained an opening bracket, and we are still in it,
459470 " add indent depending on the bracket type.
460- if line = ~ ' [[({]'
471+ if line = ~ ' [[({})\] ]'
461472 let counts = s: LineHasOpeningBrackets (lnum)
462473 if counts[0 ] == ' 1' && searchpair (' (' , ' ' , ' )' , ' bW' , s: skip_expr ) > 0
463474 if col (' .' ) + 1 == col (' $' ) || line = ~ s: one_line_scope_regex
464475 return ind + s: sw ()
465476 else
466477 return virtcol (' .' )
467478 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'
483480 call cursor (lnum, 1 )
484481 " Search for the opening tag
485482 let mnum = searchpair (' (' , ' ' , ' )' , ' bW' , s: skip_expr )
486483 if mnum > 0
487484 return indent (s: GetMSL (mnum, 0 ))
488485 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)
491490 end
492491 end
493492
0 commit comments