@@ -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,31 @@ 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
+ " If line starts with operator...
384
+ if (s: Match (v: lnum , s: operator_first ))
385
+ if (s: Match (prevline, s: operator_first ))
386
+ " and so does previous line, don't indent
383
387
return indent (prevline)
384
- else
388
+ end
389
+ let counts = s: LineHasOpeningBrackets (prevline)
390
+ if counts[0 ] == ' 2'
391
+ call cursor (prevline, 1 )
392
+ " Search for the opening tag
393
+ let mnum = searchpair (' (' , ' ' , ' )' , ' bW' , s: skip_expr )
394
+ if mnum > 0 && s: Match (mnum, s: operator_first )
395
+ return indent (mnum)
396
+ end
397
+ elseif counts[0 ] != ' 1' && counts[1 ] != ' 1' && counts[2 ] != ' 1'
398
+ " otherwise, indent 1 level
385
399
return indent (prevline) + s: sw ()
386
- endif
387
- endif
400
+ end
401
+ " If previous line starts with a operator...
402
+ elseif s: Match (prevline, s: operator_first ) && ! s: Match (prevline, s: comma_last )
403
+ let countscur = s: LineHasOpeningBrackets (v: lnum )
404
+ if countscur[0 ] != ' 2'
405
+ return indent (prevline) - s: sw ()
406
+ end
407
+ end
388
408
389
409
" If we are in a multi-line comment, cindent does the right thing.
390
410
if s: IsInMultilineComment (v: lnum , 1 ) && ! s: IsLineComment (v: lnum , 1 )
@@ -448,7 +468,19 @@ function GetJavascriptIndent()
448
468
else
449
469
call cursor (v: lnum , vcol)
450
470
end
451
- endif
471
+ elseif line = ~ ' )' || line = ~ s: comma_last
472
+ let counts = s: LineHasOpeningBrackets (lnum)
473
+ if counts[0 ] == ' 2'
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 !~ s: var_stmt
481
+ return indent (prevline)
482
+ end
483
+ end
452
484
453
485
" 3.4. Work on the MSL line. {{{2
454
486
" --------------------------
0 commit comments