@@ -69,9 +69,11 @@ let s:msl_regex = s:continuation_regex.'\|'.s:expr_case
69
69
let s: one_line_scope_regex = ' \%(\%(\<else\>\|\<\%(if\|for\|while\)\>\s*(.*)\)\|=>\)' . s: line_term
70
70
71
71
" Regex that defines blocks.
72
- let s: block_regex = ' \%([{[]\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s: line_term
72
+ let s: block_regex = ' \%([{( []\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s: line_term
73
73
74
- let s: var_stmt = ' ^\s*(const\|let\|var)'
74
+ let s: operator_first = ' ^\s*\%([-*/+.:?]\|||\|&&\)'
75
+
76
+ let s: var_stmt = ' ^\s*\%(const\|let\|var\)'
75
77
76
78
let s: comma_first = ' ^\s*,'
77
79
let s: comma_last = ' ,\s*$'
@@ -240,7 +242,7 @@ function s:LineHasOpeningBrackets(lnum)
240
242
endif
241
243
let pos = match (line , ' [][(){}]' , pos + 1 )
242
244
endwhile
243
- return (open_0 > 0 ) . (open_2 > 0 ) . (open_4 > 0 )
245
+ return (open_0 > 0 ? 1 : (open_0 == 0 ? 0 : 2 ) ) . (open_2 > 0 ) . (open_4 > 0 )
244
246
endfunction
245
247
246
248
function s: Match (lnum, regex)
@@ -378,13 +380,33 @@ function GetJavascriptIndent()
378
380
return indent (prevline) + s: case_indent_after
379
381
endif
380
382
381
- if (line = ~ s: ternary )
382
- if (getline (prevline) = ~ s: ternary_q )
383
+
384
+ " If line starts with operator...
385
+
386
+ if (s: Match (v: lnum , s: operator_first ))
387
+ if (s: Match (prevline, s: operator_first ))
388
+ " and so does previous line, don't indent
383
389
return indent (prevline)
384
- else
390
+ end
391
+ let counts = s: LineHasOpeningBrackets (prevline)
392
+ if counts[0 ] == ' 2'
393
+ call cursor (prevline, 1 )
394
+ " Search for the opening tag
395
+ let mnum = searchpair (' (' , ' ' , ' )' , ' bW' , s: skip_expr )
396
+ if mnum > 0 && s: Match (mnum, s: operator_first )
397
+ return indent (mnum)
398
+ end
399
+ elseif counts[0 ] != ' 1' && counts[1 ] != ' 1' && counts[2 ] != ' 1'
400
+ " otherwise, indent 1 level
385
401
return indent (prevline) + s: sw ()
386
- endif
387
- endif
402
+ end
403
+ " If previous line starts with a operator...
404
+ elseif s: Match (prevline, s: operator_first ) && ! s: Match (prevline, s: comma_last )
405
+ let countscur = s: LineHasOpeningBrackets (v: lnum )
406
+ if countscur[0 ] != ' 2'
407
+ return indent (prevline) - s: sw ()
408
+ end
409
+ end
388
410
389
411
" If we are in a multi-line comment, cindent does the right thing.
390
412
if s: IsInMultilineComment (v: lnum , 1 ) && ! s: IsLineComment (v: lnum , 1 )
@@ -448,7 +470,19 @@ function GetJavascriptIndent()
448
470
else
449
471
call cursor (v: lnum , vcol)
450
472
end
451
- endif
473
+ elseif line = ~ ' )' || line = ~ s: comma_last
474
+ let counts = s: LineHasOpeningBrackets (lnum)
475
+ if counts[0 ] == ' 2'
476
+ call cursor (lnum, 1 )
477
+ " Search for the opening tag
478
+ let mnum = searchpair (' (' , ' ' , ' )' , ' bW' , s: skip_expr )
479
+ if mnum > 0
480
+ return indent (s: GetMSL (mnum, 0 ))
481
+ end
482
+ elseif line !~ s: var_stmt
483
+ return indent (prevline)
484
+ end
485
+ end
452
486
453
487
" 3.4. Work on the MSL line. {{{2
454
488
" --------------------------
0 commit comments