@@ -45,7 +45,7 @@ let s:line_pre = '^\s*\%(\/\*.*\*\/\s*\)*'
45
45
let s: js_keywords = s: line_pre . ' \%(break\|import\|export\|catch\|const\|continue\|debugger\|delete\|do\|else\|finally\|for\|function\|if\|in\|instanceof\|let\|new\|return\|switch\|this\|throw\|try\|typeof\|var\|void\|while\|with\)\>\C'
46
46
let s: expr_case = s: line_pre . ' \%(case\s\+[^\:]*\|default\)\s*:\s*\C'
47
47
" Regex of syntax group names that are or delimit string or are comments.
48
- let s: syng_strcom = ' \%(string\|regex\|special\|comment\|template\)\c'
48
+ let s: syng_strcom = ' \%(string\|regex\|special\|doc\| comment\|template\)\c'
49
49
50
50
" Regex of syntax group names that are strings.
51
51
let s: syng_string = ' regex\c'
@@ -347,22 +347,29 @@ function GetJavascriptIndent()
347
347
endif
348
348
349
349
" If we got a closing bracket on an empty line, find its match and indent
350
- " according to it. For parentheses we indent to its column - 1, for the
351
- " others we indent to the containing line's MSL's level. Return -1 if fail.
352
- let col = matchend (line , s: line_pre . ' []})]' )
353
- if col > 0 && ! s: IsInStringOrComment (v: lnum , col )
354
- call cursor (v: lnum , col )
355
- let parlnum = s: lookForParens (' (\|{\|\[' , ' )\|}\|\]' , ' nbW' , 0 )
356
- if parlnum > 0
357
- let ind = s: InMultiVarStatement (parlnum, 0 , 0 ) ? indent (parlnum) : indent (s: GetMSL (parlnum, 0 ))
358
- endif
350
+ " according to it.
351
+ let col = s: Match (v: lnum , s: line_pre . ' []})]' )
352
+ if col > 0
353
+ let parlnum = v: lnum
354
+ while col
355
+ call cursor (parlnum, 1 )
356
+ let parlnum = s: lookForParens (' (\|{\|\[' , ' )\|}\|\]' , ' nbW' , 0 )
357
+ let col = s: Match (parlnum, s: line_pre . ' []})]' )
358
+ if col
359
+ continue
360
+ end
361
+ if parlnum > 0
362
+ let ind = s: InMultiVarStatement (parlnum, 0 , 0 )|| s: LineHasOpeningBrackets (parlnum) !~ ' 2'
363
+ \ ? indent (parlnum) : indent (s: GetMSL (parlnum, 0 ))
364
+ endif
365
+ endwhile
359
366
return ind
360
367
endif
361
368
362
369
363
370
" If line starts with an operator...
364
371
if (line = ~ s: operator_first )
365
- if (s: Match (lnum, s: operator_first ))
372
+ if (s: Match (lnum, s: operator_first ) || s: Match (lnum, s: line_pre . ' [])}] ' ) )
366
373
" and so does previous line, don't indent
367
374
return indent (lnum)
368
375
end
@@ -421,30 +428,39 @@ function GetJavascriptIndent()
421
428
return 0
422
429
endif
423
430
431
+ " foo('foo',
432
+ " bar('bar', function() {
433
+ " hi();
434
+ " })
435
+ " );
424
436
437
+ " function (a, b, c, d,
438
+ " e, f, g) {
439
+ " console.log('inner');
440
+ " }
425
441
" If the previous line ended with a block opening, add a level of indent.
426
442
if s: Match (lnum, s: block_regex )
427
- return s: InMultiVarStatement (lnum, 0 , 0 ) ? indent (lnum) + s: sw () : indent (s: GetMSL (lnum, 0 )) + s: sw ()
443
+ return s: InMultiVarStatement (lnum, 0 , 0 ) || s: LineHasOpeningBrackets (lnum) !~ ' 2' ?
444
+ \ indent (lnum) + s: sw () : indent (s: GetMSL (lnum, 0 )) + s: sw ()
428
445
endif
429
446
430
447
" Set up variables for current line.
431
448
let line = getline (lnum)
432
449
let ind = indent (lnum)
433
450
" If the previous line contained an opening bracket, and we are still in it,
434
451
" add indent depending on the bracket type.
435
- if s: Match (lnum, ' [[({} )\]]' )
452
+ if s: Match (lnum, ' \%( [[({]\)\|\%([^\t \])}][} )\]]\) ' )
436
453
let counts = s: LineHasOpeningBrackets (lnum)
437
454
if counts = ~ ' 2'
438
- call cursor (lnum, 1 )
439
- " Search for the opening tag
440
- let parlnum = s: lookForParens (' (\|{\|\[' , ' )\|}\|\]' , ' nbW' , 0 )
441
- if parlnum > 0 && ! s: InMultiVarStatement (parlnum,0 ,0 )
442
- return indent (s: GetMSL (parlnum, 0 ))
455
+ call cursor (lnum,matchend (s: RemoveTrailingComments (line ), ' .\+\zs[])}]' ))
456
+ while s: lookForParens (' (\|{\|\[' , ' )\|}\|\]' , ' bW' , 0 ) == lnum
457
+ call cursor (lnum, matchend (s: RemoveTrailingComments (strpart (line ,0 ,col (' .' ))), ' .*\zs[])}]' ))
458
+ endwhile
459
+ if line (' .' ) < lnum && ! s: InMultiVarStatement (line (' .' ),0 ,0 )
460
+ return indent (s: GetMSL (line (' .' ), 0 ))
443
461
end
444
462
elseif counts = ~ ' 1' || s: Onescope (lnum)
445
463
return ind + s: sw ()
446
- else
447
- call cursor (v: lnum , vcol)
448
464
end
449
465
end
450
466
0 commit comments