Skip to content

Commit a607a7d

Browse files
bouncemebounceme
authored andcommitted
spanning multiple lines detection
In progress but here are the effects so far ``` if ( a == b && c == d && e == f || g == h || i == j ) { a = b + c - d; } ``` as opposed to this which would indent everything following it: ``` if ( a == b && c == d && e == f || g == h || i == j ) { a = b + c - d; } ```
1 parent d388b88 commit a607a7d

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

indent/javascript.vim

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,21 @@ function s:GetMSL(lnum, in_one_line_scope)
145145
" Otherwise, terminate search as we have found our MSL already.
146146
let line = getline(lnum)
147147
let col = match(line, s:msl_regex) + 1
148+
let line2 = getline(msl)
149+
let col2 = matchend(line2, ')')
148150
if (col > 0 && !s:IsInStringOrComment(lnum, col)) || s:IsInString(lnum, strlen(line))
149151
let msl = lnum
152+
153+
" if there are more closing brackets, continue from the line which has the matching opening bracket
154+
elseif col2 > 0 && !s:IsInStringOrComment(msl, col2) && s:LineHasOpeningBrackets(msl)[0] == '2'
155+
call cursor(msl, 1)
156+
if searchpair('(', '', ')', 'bW', s:skip_expr) > 0
157+
let lnum = line('.')
158+
let msl = lnum
159+
endif
160+
150161
else
162+
151163
" Don't use lines that are part of a one line scope as msl unless the
152164
" flag in_one_line_scope is set to 1
153165
"
@@ -158,7 +170,7 @@ function s:GetMSL(lnum, in_one_line_scope)
158170
if msl_one_line == 0
159171
break
160172
endif
161-
endif
173+
end
162174
let lnum = s:PrevNonBlankNonString(lnum - 1)
163175
endwhile
164176
return msl
@@ -396,7 +408,7 @@ function GetJavascriptIndent()
396408
return indent(prevline) + s:sw()
397409
end
398410
" If previous line starts with an operator...
399-
elseif s:Match(prevline, s:operator_first) && !s:Match(prevline, s:comma_last)
411+
elseif s:Match(prevline, s:operator_first) && !s:Match(prevline, s:comma_last) && !s:Match(prevline, '};\=' . s:line_term)
400412
let counts = s:LineHasOpeningBrackets(prevline)
401413
if counts[0] == '2' && counts[1] == '1'
402414
call cursor(prevline, 1)
@@ -472,7 +484,14 @@ function GetJavascriptIndent()
472484
else
473485
call cursor(v:lnum, vcol)
474486
end
475-
elseif line =~ ')' || line =~ s:comma_last
487+
elseif line =~ '.\+};\=' . s:line_term
488+
call cursor(lnum, 1)
489+
" Search for the opening tag
490+
let mnum = searchpair('{', '', '}', 'bW', s:skip_expr)
491+
if mnum > 0
492+
return indent(s:GetMSL(mnum, 0))
493+
end
494+
elseif line =~ '.\+);\=' || line =~ s:comma_last
476495
let counts = s:LineHasOpeningBrackets(lnum)
477496
if counts[0] == '2'
478497
call cursor(lnum, 1)
@@ -481,7 +500,7 @@ function GetJavascriptIndent()
481500
if mnum > 0
482501
return indent(s:GetMSL(mnum, 0))
483502
end
484-
elseif line !~ s:var_stmt
503+
elseif line !~ s:var_stmt
485504
return indent(prevline)
486505
end
487506
end

0 commit comments

Comments
 (0)