@@ -41,16 +41,17 @@ endif
41
41
" 1. Variables {{{1
42
42
" ============
43
43
44
- let s: js_keywords = ' ^\s*\%(break\|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'
45
- let s: expr_case = ' ^\s*\%(case\s\+[^\:]*\|default\)\s*:\s*\C'
44
+ let s: line_pre = ' ^\s*\%(\/\*.*\*\/\s*\)*'
45
+ let s: js_keywords = s: line_pre . ' \%(break\|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
+ let s: expr_case = s: line_pre . ' \%(case\s\+[^\:]*\|default\)\s*:\s*\C'
46
47
" Regex of syntax group names that are or delimit string or are comments.
47
48
let s: syng_strcom = ' \%(string\|regex\|comment\|template\)\c'
48
49
49
50
" Regex of syntax group names that are strings.
50
51
let s: syng_string = ' regex\c'
51
52
52
53
" Regex of syntax group names that are strings or documentation.
53
- let s: syng_multiline = ' comment\c'
54
+ let s: syng_multiline = ' \%( comment\|doc\) \c'
54
55
55
56
" Regex of syntax group names that are line comment.
56
57
let s: syng_linecom = ' linecomment\c'
@@ -61,7 +62,7 @@ let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_st
61
62
let s: line_term = ' \s*\%(\%(\/\/.*\)\=\|\%(\/\*.*\*\/\s*\)*\)$'
62
63
63
64
" Regex that defines continuation lines, not including (, {, or [.
64
- let s: continuation_regex = ' \%([\\*/ .?:]\|+\@<!+\|-\@<!-\|=\|||\|&&\)' . s: line_term
65
+ let s: continuation_regex = ' \%([* .?:]\|+\@<!+\|-\@<!-\|\*\@<!\/ \|=\|||\|&&\)' . s: line_term
65
66
66
67
let s: one_line_scope_regex = ' \%(\<else\>\|=>\)\C' . s: line_term
67
68
@@ -83,11 +84,11 @@ endfunction
83
84
" Regex that defines blocks.
84
85
let s: block_regex = ' [{([]' . s: line_term
85
86
86
- let s: operator_first = ' ^\s*\ %([* .:?]\|\([-/+]\)\1 \@!\|||\|&&\)'
87
+ let s: operator_first = s: line_pre . ' \ %([.:?]\|\([-/+* ]\)\%(\1\|\*\|\/\) \@!\|||\|&&\)'
87
88
88
- let s: var_stmt = ' ^\s* \%(const\|let\|var\)\s\+\C'
89
+ let s: var_stmt = s: line_pre . ' \%(const\|let\|var\)\s\+\C'
89
90
90
- let s: comma_first = ' ^\s* ,'
91
+ let s: comma_first = s: line_pre . ' ,'
91
92
let s: comma_last = ' ,' . s: line_term
92
93
93
94
" 2. Auxiliary Functions {{{1
@@ -121,15 +122,15 @@ function s:PrevNonBlankNonString(lnum)
121
122
" Go in and out of blocks comments as necessary.
122
123
" If the line isn't empty (with opt. comment) or in a string, end search.
123
124
let line = getline (lnum)
124
- if s: IsInMultilineComment (lnum, matchend (line , ' /\*' ) - 1 )
125
+ if s: IsInMultilineComment (lnum, matchend (line , ' ^\s* /\*' ) - 1 ) && line !~ s: line_pre . ' $ '
125
126
if in_block
126
127
let in_block = 0
127
128
else
128
129
break
129
130
endif
130
- elseif ! in_block && s: IsInMultilineComment (lnum, matchend (line , ' \*/' ) - 1 )
131
+ elseif ! in_block && s: IsInMultilineComment (lnum, match (line , ' \*/\s*$ ' ) + 1 ) && line !~ s: line_pre . ' $ '
131
132
let in_block = 1
132
- elseif ! in_block && line !~ ' ^\s* \%(//\).*$' && ! (s: IsInStringOrComment (lnum, 1 ) && s: IsInStringOrComment (lnum, strlen (line )))
133
+ elseif ! in_block && line !~ s: line_pre . ' \%(//\).*$' && ! (s: IsInStringOrComment (lnum, 1 ) && s: IsInStringOrComment (lnum, strlen (line )))
133
134
break
134
135
endif
135
136
let lnum = prevnonblank (lnum - 1 )
@@ -191,7 +192,7 @@ function s:InMultiVarStatement(lnum, cont, prev)
191
192
" let type = synIDattr(synID(lnum, indent(lnum) + 1, 0), 'name')
192
193
193
194
" loop through previous expressions to find a var statement
194
- while lnum > 0 && (s: Match (lnum, s: comma_last ) || (a: cont && getline (lnum) = ~ ' ^\s* }' ) || (a: prev && s: Match (a: prev , s: comma_last )))
195
+ while lnum > 0 && (s: Match (lnum, s: comma_last ) || (a: cont && getline (lnum) = ~ s: line_pre . ' }' ) || (a: prev && s: Match (a: prev , s: comma_last )))
195
196
" if the line is a js keyword
196
197
if a: cont
197
198
call cursor (lnum,1 )
@@ -341,17 +342,18 @@ function GetJavascriptIndent()
341
342
let prevline = prevnonblank (v: lnum - 1 )
342
343
343
344
" to not change multiline string values
344
- if synIDattr (synID (v: lnum , 1 , 1 ), ' name' ) = ~? ' string\|template' && line !~ ' ^\s* ['' "`]'
345
+ if synIDattr (synID (v: lnum , 1 , 1 ), ' name' ) = ~? ' string\|template' && line !~ s: line_pre . ' ['' "`]'
345
346
return indent (v: lnum )
346
347
endif
347
348
348
349
" If we are in a multi-line comment, cindent does the right thing.
349
- if s: IsInMultilineComment (v: lnum , 1 ) && ! s: IsLineComment (v: lnum , 1 )
350
+ if s: IsInMultilineComment (v: lnum , 1 ) && ! s: IsLineComment (v: lnum , 1 ) &&
351
+ \ s: IsInMultilineComment (v: lnum , match (line , ' \s*$' ))
350
352
return cindent (v: lnum )
351
353
endif
352
354
353
355
" single opening bracket will assume you want a c style of indenting
354
- if s: Match (v: lnum , ' ^\s* {' . s: line_term )
356
+ if s: Match (v: lnum , s: line_pre . ' {' . s: line_term )
355
357
return cindent (v: lnum )
356
358
endif
357
359
@@ -370,7 +372,7 @@ function GetJavascriptIndent()
370
372
" If we got a closing bracket on an empty line, find its match and indent
371
373
" according to it. For parentheses we indent to its column - 1, for the
372
374
" others we indent to the containing line's MSL's level. Return -1 if fail.
373
- let col = matchend (line , ' ^\s* [],})]' )
375
+ let col = matchend (line , s: line_pre . ' [],})]' )
374
376
if col > 0 && ! s: IsInStringOrComment (v: lnum , col )
375
377
call cursor (v: lnum , col )
376
378
@@ -489,13 +491,13 @@ function GetJavascriptIndent()
489
491
if searchpair (' (' , ' ' , ' )' , ' bW' , s: skip_expr ) > 0
490
492
return indent (s: GetMSL (line (' .' ), 0 ))
491
493
end
492
- elseif counts[1 ] == ' 2' && ! s: Match (lnum, ' ^\s* }' )
494
+ elseif counts[1 ] == ' 2' && ! s: Match (lnum, s: line_pre . ' }' )
493
495
call cursor (lnum, 1 )
494
496
" Search for the opening tag
495
497
if searchpair (' {' , ' ' , ' }' , ' bW' , s: skip_expr ) > 0
496
498
return indent (s: GetMSL (line (' .' ), 0 ))
497
499
end
498
- elseif counts[2 ] == ' 2' && ! s: Match (lnum, ' ^\s* ]' )
500
+ elseif counts[2 ] == ' 2' && ! s: Match (lnum, s: line_pre . ' ]' )
499
501
call cursor (lnum, 1 )
500
502
" Search for the opening tag
501
503
if searchpair (' \[' , ' ' , ' \]' , ' bW' , s: skip_expr ) > 0
0 commit comments