@@ -54,6 +54,9 @@ let s:one_line_scope_regex = '\<\%(if\|else\|for\|while\)\>[^{;]*' . s:line_term
5454" Regex that defines blocks.
5555let s: block_regex = ' \%({\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s: line_term
5656
57+ " Var string
58+ let s: var_regex = ' \s*var\s[^;]\+$'
59+
5760" 2. Auxiliary Functions {{{1
5861" ======================
5962
@@ -125,6 +128,49 @@ function s:GetMSL(lnum, in_one_line_scope)
125128 return msl
126129endfunction
127130
131+ " Find if the string is inside var statement (but not the first string)
132+ function s: InVarStatement (lnum)
133+ let lnum = s: PrevNonBlankNonString (a: lnum - 1 )
134+
135+ while lnum > 0
136+ let line = getline (lnum)
137+
138+ " if line has var statement, return it's number
139+ if ( line = ~ s: var_regex )
140+ return lnum
141+ endif
142+
143+ " if line has brackets or semi-colon, return 0
144+ if ( line = ~ ' [{};]' )
145+ return 0
146+ endif
147+
148+ let lnum = s: PrevNonBlankNonString (lnum - 1 )
149+ endwhile
150+
151+ return 0
152+ endfunction
153+
154+ " Find line above with beginning of the var statement or returns 0 if it's not
155+ " this statement
156+ function s: GetVarIndent (lnum)
157+ let lvar = s: InVarStatement (a: lnum )
158+ let prev_lnum = s: PrevNonBlankNonString (a: lnum - 1 )
159+ let prev_lvar = s: InVarStatement (prev_lnum)
160+
161+ if ( lvar )
162+ return indent (lvar) + &sw
163+ endif
164+
165+ if ( prev_lvar )
166+ return indent (prev_lvar)
167+ endif
168+
169+ return ' null'
170+
171+ endfunction
172+
173+
128174" Check if line 'lnum' has more opening brackets than closing ones.
129175function s: LineHasOpeningBrackets (lnum)
130176 let open_0 = 0
@@ -244,6 +290,12 @@ function GetJavascriptIndent()
244290 return cindent (v: lnum )
245291 endif
246292
293+ " Work with var statements' blocks
294+ let var_indent = s: GetVarIndent (v: lnum )
295+ if var_indent != ' null'
296+ return var_indent
297+ endif
298+
247299 " 3.3. Work on the previous line. {{{2
248300 " -------------------------------
249301
0 commit comments