@@ -117,21 +117,17 @@ endfunction
117
117
118
118
" Find line above 'lnum' that isn't empty, in a comment, or in a string.
119
119
function s: PrevNonBlankNonString (lnum)
120
- let in_block = 0
121
120
let lnum = prevnonblank (a: lnum )
122
121
while lnum > 0
123
- " Go in and out of blocks comments as necessary.
124
- " If the line isn't empty (with opt. comment) or in a string, end search.
125
122
let line = getline (lnum)
126
- if s: IsInMultilineComment (lnum, matchend (line , ' ^\s*/\*' ) - 1 ) && line !~ s: line_pre . ' $'
127
- if in_block
128
- let in_block = 0
129
- else
130
- break
131
- endif
132
- elseif ! in_block && s: IsInMultilineComment (lnum, match (line , ' \*/\s*$' ) + 1 ) && line !~ s: line_pre . ' $'
133
- let in_block = 1
134
- elseif ! in_block && line !~ s: line_pre . ' \%(//\).*$' && ! (s: IsInStringOrComment (lnum, 1 ) && s: IsInStringOrComment (lnum, strlen (line )))
123
+ let com = match (line , ' \*\/' ) + 1
124
+ if s: IsInMultilineComment (lnum, com )
125
+ call cursor (lnum, com )
126
+ let parlnum = search (' \/\*' , ' nbW' )
127
+ if parlnum > 0
128
+ let lnum = parlnum
129
+ end
130
+ elseif line !~ ' ^' . s: line_term
135
131
break
136
132
endif
137
133
let lnum = prevnonblank (lnum - 1 )
@@ -148,11 +144,9 @@ function s:GetMSL(lnum, in_one_line_scope)
148
144
" If we have a continuation line, or we're in a string, use line as MSL.
149
145
" Otherwise, terminate search as we have found our MSL already.
150
146
let line = getline (lnum)
151
- let col = match (line , s: continuation_regex ) + 1
152
- let coal = match (line , s: comma_last ) + 1
153
147
let line2 = getline (msl)
154
148
let col2 = matchend (line2, ' )' )
155
- if ((col > 0 && ! s: IsInStringOrComment (lnum, col ) || coal > 0 && ! s: IsInStringOrComment (lnum,coal )) &&
149
+ if ((s: Match (lnum,s: continuation_regex ) || s: Match (lnum, s: comma_last )) &&
156
150
\ ! s: Match (lnum, s: expr_case )) || s: IsInString (lnum, strlen (line ))
157
151
let msl = lnum
158
152
@@ -201,8 +195,9 @@ function s:InMultiVarStatement(lnum, cont, prev)
201
195
" if the line is a js keyword
202
196
if a: cont
203
197
call cursor (lnum,1 )
204
- if searchpair (' {' , ' ' , ' }' , ' bW' , s: skip_expr ) > 0
205
- let lnum = line (' .' )
198
+ let parlnum = searchpair (' (\|{\|\[' , ' ' , ' )\|}\|\]' , ' nbW' , s: skip_expr )
199
+ if parlnum > 0
200
+ let lnum = parlnum
206
201
end
207
202
end
208
203
if s: Match (lnum, s: js_keywords )
@@ -225,27 +220,6 @@ function s:InMultiVarStatement(lnum, cont, prev)
225
220
return 0
226
221
endfunction
227
222
228
- " Find line above with beginning of the var statement or returns 0 if it's not"{{{2
229
- " this statement
230
- " function s:GetVarIndent(lnum)
231
- " let lvar = s:InMultiVarStatement(a:lnum, 0,0)
232
- " let prev_lnum = s:PrevNonBlankNonString(a:lnum - 1)
233
-
234
- " if lvar
235
- " let line = s:RemoveTrailingComments(getline(prev_lnum))
236
-
237
- " " if the previous line doesn't end in a comma, return to regular indent
238
- " if (line !~ s:comma_last)
239
- " return indent(prev_lnum) - s:sw()
240
- " else
241
- " return indent(lvar) + s:sw()
242
- " endif
243
- " endif
244
-
245
- " return -1
246
- " endfunction"}}}
247
-
248
-
249
223
" Check if line 'lnum' has more opening brackets than closing ones.
250
224
function s: LineHasOpeningBrackets (lnum)
251
225
let open_0 = 0
@@ -345,15 +319,14 @@ function GetJavascriptIndent()
345
319
let line = getline (v: lnum )
346
320
" previous nonblank line number
347
321
let prevline = prevnonblank (v: lnum - 1 )
348
-
322
+
349
323
" to not change multiline string values
350
- if synIDattr (synID (v: lnum , 1 , 1 ), ' name' ) = ~? ' string\|template' && line !~ s: line_pre . ' [ '' "`] '
351
- return indent ( v: lnum )
324
+ if line !~ ' ^[ '' "`] ' && synIDattr (synID (v: lnum , 1 , 1 ), ' name' ) = ~? ' string\|template'
325
+ return -1
352
326
endif
353
327
354
328
" If we are in a multi-line comment, cindent does the right thing.
355
- if s: IsInMultilineComment (v: lnum , 1 ) && ! s: IsLineComment (v: lnum , 1 ) &&
356
- \ s: IsInMultilineComment (v: lnum , match (line , ' \s*$' )) && line !~ ' ^\/\*'
329
+ if s: IsInMultilineComment (v: lnum , 1 ) && line !~ ' ^\/\*'
357
330
return cindent (v: lnum )
358
331
endif
359
332
@@ -375,45 +348,47 @@ function GetJavascriptIndent()
375
348
call cursor (v: lnum , col )
376
349
377
350
378
- let bs = strpart (' (){}[] ' , stridx ( ' )} ]' , line [ col - 1 ]) * 2 , 2 )
379
- if searchpair ( escape ( bs [ 0 ], ' \[ ' ), ' ' , bs [ 1 ], ' bW ' , s: skip_expr ) > 0
380
- let ind = s: InMultiVarStatement (line ( ' . ' ) , 0 , 0 ) ? indent (line ( ' . ' )) : indent (s: GetMSL (line ( ' . ' ) , 0 ))
351
+ let parlnum = searchpair (' (\|{\|\[ ' , ' ' , ' )\|}\|\ ]' , ' nbW ' , s: skip_expr )
352
+ if parlnum > 0
353
+ let ind = s: InMultiVarStatement (parlnum , 0 , 0 ) ? indent (parlnum) : indent (s: GetMSL (parlnum , 0 ))
381
354
endif
382
355
return ind
383
356
endif
384
357
358
+ let lnum = s: PrevNonBlankNonString (v: lnum - 1 )
359
+
385
360
" If line starts with an operator...
386
361
if (line = ~ s: operator_first )
387
- if (s: Match (prevline , s: operator_first ))
362
+ if (s: Match (lnum , s: operator_first ))
388
363
" and so does previous line, don't indent
389
- return indent (prevline )
364
+ return indent (lnum )
390
365
end
391
- let counts = s: LineHasOpeningBrackets (prevline )
366
+ let counts = s: LineHasOpeningBrackets (lnum )
392
367
if counts[0 ] == ' 2' || counts[1 ] == ' 2' || counts[2 ] == ' 2'
393
- call cursor (prevline , 1 )
368
+ call cursor (lnum , 1 )
394
369
" Search for the opening tag
395
- let bs = strpart (' (){}[] ' , stridx ( ' )} ]' , line [ col - 1 ]) * 2 , 2 )
396
- if searchpair ( escape ( bs [ 0 ], ' \[ ' ), ' ' , bs [ 1 ], ' bW ' , s: skip_expr ) > 0 && s: Match (line ( ' . ' ) , s: operator_first )
397
- return indent (line ( ' . ' ) )
370
+ let parlnum = searchpair (' (\|{\|\[ ' , ' ' , ' )\|}\|\ ]' , ' nbW ' , s: skip_expr )
371
+ if parlnum > 0 && s: Match (parlnum , s: operator_first )
372
+ return indent (parlnum )
398
373
end
399
374
elseif counts[0 ] != ' 1' && counts[1 ] != ' 1' && counts[2 ] != ' 1'
400
375
" otherwise, indent 1 level
401
- return indent (prevline ) + s: sw ()
376
+ return indent (lnum ) + s: sw ()
402
377
end
403
378
404
379
" If previous line starts with an operator...
405
- elseif (s: Match (prevline , s: operator_first ) && ! s: Match (prevline ,s: continuation_regex ))|| getline (prevline ) = ~ ' );\=' . s: line_term
406
- let counts = s: LineHasOpeningBrackets (prevline )
407
- if counts[0 ] == ' 2' && ! s: Match (prevline , s: operator_first )
408
- call cursor (prevline , 1 )
380
+ elseif (s: Match (lnum , s: operator_first ) && ! s: Match (lnum ,s: continuation_regex ))|| getline (lnum ) = ~ ' );\=' . s: line_term
381
+ let counts = s: LineHasOpeningBrackets (lnum )
382
+ if counts[0 ] == ' 2' && ! s: Match (lnum , s: operator_first )
383
+ call cursor (lnum , 1 )
409
384
" Search for the opening tag
410
- let mnum = searchpair (' (' , ' ' , ' )' , ' bW ' , s: skip_expr )
385
+ let mnum = searchpair (' (' , ' ' , ' )' , ' nbW ' , s: skip_expr )
411
386
if mnum > 0 && s: Match (mnum, s: operator_first )
412
387
return indent (mnum) - s: sw ()
413
388
end
414
- elseif s: Match (prevline , s: operator_first )
389
+ elseif s: Match (lnum , s: operator_first )
415
390
if counts[0 ] != ' 1' && counts[1 ] != ' 1' && counts[2 ] != ' 1'
416
- return indent (prevline ) - s: sw ()
391
+ return indent (lnum ) - s: sw ()
417
392
end
418
393
end
419
394
end
@@ -429,7 +404,6 @@ function GetJavascriptIndent()
429
404
endif
430
405
431
406
" Find a non-blank, non-multi-line string line above the current line.
432
- let lnum = s: PrevNonBlankNonString (v: lnum - 1 )
433
407
434
408
" If the line is empty and inside a string, use the previous line.
435
409
if line = ~ ' ^\s*$' && lnum != prevline
@@ -454,23 +428,13 @@ function GetJavascriptIndent()
454
428
" add indent depending on the bracket type.
455
429
if s: Match (lnum, ' [[({})\]]' )
456
430
let counts = s: LineHasOpeningBrackets (lnum)
457
- if counts[0 ] == ' 2'
458
- call cursor (lnum, 1 )
459
- " Search for the opening tag
460
- if searchpair (' (' , ' ' , ' )' , ' bW' , s: skip_expr ) > 0
461
- return indent (s: GetMSL (line (' .' ), 0 ))
462
- end
463
- elseif counts[1 ] == ' 2' && ! s: Match (lnum, s: line_pre . ' }' )
464
- call cursor (lnum, 1 )
465
- " Search for the opening tag
466
- if searchpair (' {' , ' ' , ' }' , ' bW' , s: skip_expr ) > 0
467
- return indent (s: GetMSL (line (' .' ), 0 ))
468
- end
469
- elseif counts[2 ] == ' 2' && ! s: Match (lnum, s: line_pre . ' ]' )
431
+ if counts[0 ] == ' 2' || (counts[1 ] == ' 2' && ! s: Match (lnum, s: line_pre . ' }' )) ||
432
+ \ (counts[2 ] == ' 2' && ! s: Match (lnum, s: line_pre . ' ]' ))
470
433
call cursor (lnum, 1 )
471
434
" Search for the opening tag
472
- if searchpair (' \[' , ' ' , ' \]' , ' bW' , s: skip_expr ) > 0
473
- return indent (s: GetMSL (line (' .' ), 0 ))
435
+ let parlnum = searchpair (' (\|{\|\[' , ' ' , ' )\|}\|\]' , ' nbW' , s: skip_expr )
436
+ if parlnum > 0
437
+ return indent (s: GetMSL (parlnum, 0 ))
474
438
end
475
439
elseif counts[1 ] == ' 1' || counts[2 ] == ' 1' || counts[0 ] == ' 1' || s: Onescope (lnum)
476
440
return ind + s: sw ()
0 commit comments