Skip to content

Commit b5841cd

Browse files
authored
recursive matching
#469 (comment)
1 parent 9e5b60a commit b5841cd

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

indent/javascript.vim

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,21 @@ function GetJavascriptIndent()
347347
endif
348348

349349
" 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) ? indent(parlnum) : indent(s:GetMSL(parlnum, 0))
363+
endif
364+
endwhile
359365
return ind
360366
endif
361367

@@ -424,7 +430,8 @@ function GetJavascriptIndent()
424430

425431
" If the previous line ended with a block opening, add a level of indent.
426432
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()
433+
return s:InMultiVarStatement(lnum, 0, 0) || s:Match(lnum, s:line_pre . '[]})]') ?
434+
\ indent(lnum) + s:sw() : indent(s:GetMSL(lnum, 0)) + s:sw()
428435
endif
429436

430437
" Set up variables for current line.

0 commit comments

Comments
 (0)