Skip to content

Commit 560b4fd

Browse files
authored
Improvements for one line scope (#509)
* Improvements for one line scope * possibly not a good idea everything seems to work well though
1 parent 29e1e05 commit 560b4fd

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

indent/javascript.vim

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function s:Onescope(lnum)
7777
end
7878
let mypos = col('.')
7979
call cursor(a:lnum, 1)
80-
if search('\<\%(while\|for\|if\)\>\s*(\C', 'ce', a:lnum) > 0 &&
80+
if search('.*\zs\<\%(while\|for\|if\)\>\s*(\C', 'ce', a:lnum) > 0 &&
8181
\ s:lookForParens('(', ')', 'W', a:lnum) > 0 &&
8282
\ col('.') == strlen(s:RemoveTrailingComments(getline(a:lnum)))
8383
call cursor(a:lnum, mypos)
@@ -337,7 +337,7 @@ function GetJavascriptIndent()
337337
endif
338338

339339
" single opening bracket will assume you want a c style of indenting
340-
if line =~ s:line_pre . '{' . s:line_term && !s:Match(lnum,s:block_regex) &&
340+
if line =~ s:line_pre . '{' && !s:Match(lnum,s:block_regex) &&
341341
\ !s:Match(lnum,s:comma_last)
342342
return cindent(v:lnum)
343343
endif
@@ -395,13 +395,15 @@ function GetJavascriptIndent()
395395
end
396396

397397
" If previous line starts with an operator...
398-
elseif (s:Match(lnum, s:operator_first) && !s:Match(lnum,s:continuation_regex))||getline(lnum) =~ '[]})];\=' . s:line_term
398+
elseif (s:Match(lnum, s:operator_first) && !s:Match(lnum,s:continuation_regex)) ||
399+
\ getline(lnum) =~ '[]})];\=' . s:line_term
399400
let counts = s:LineHasOpeningBrackets(lnum)
400401
if counts =~ '2' && !s:Match(lnum, s:operator_first)
401402
call cursor(lnum, 1)
402403
" Search for the opening tag
403404
let mnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0)
404-
if mnum > 0 && s:Match(mnum, s:operator_first)
405+
if mnum > 0 && (s:Match(mnum, s:operator_first) ||
406+
\ (s:Onescope(s:PrevNonBlankNonString(mnum - 1))) && !s:Match(mnum, s:line_pre . '{'))
405407
return indent(mnum) - s:sw()
406408
end
407409
elseif s:Match(lnum, s:operator_first)
@@ -453,8 +455,7 @@ function GetJavascriptIndent()
453455
call cursor(lnum, matchend(s:RemoveTrailingComments(strpart(line,0,col('.'))), '.*\zs[])}]'))
454456
endwhile
455457
let cur = line('.')
456-
if cur < lnum && !s:InMultiVarStatement(cur,0,0) &&
457-
\ !s:Onescope(s:PrevNonBlankNonString(cur - 1))
458+
if cur < lnum && !s:InMultiVarStatement(cur,0,0)
458459
return indent(s:GetMSL(cur, 0))
459460
end
460461
elseif counts =~ '1' || s:Onescope(lnum)

0 commit comments

Comments
 (0)