Skip to content

Commit bf7d4b6

Browse files
authored
remove switch syn check (#571)
* remove switch syn check #177 (comment)
1 parent ab5d96b commit bf7d4b6

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

indent/javascript.vim

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function s:Onescope(lnum,text,add)
7676
\ cursor(line('.'),match( ' ' . strpart(getline(line('.')),0,col('.') - 1),
7777
\ (a:add ? '\K\k*' :
7878
\ '\<\%(else\|for\%(\s+each\)\=\|function\*\=\%(\s\+\K\k*\)\=\|if\|let\|switch\|while\|with\)\C') . s:line_term)) > -1) &&
79-
\ (a:add || (expand("<cword>") =~ 'while\C' ? !s:lookForParens('\<do\>\C', '\<while\>\C','bW',100) : 1))
79+
\ (a:add || (expand("<cword>") == 'while' ? !s:lookForParens('\<do\>\C', '\<while\>\C','bW',100) : 1))
8080
endfunction
8181

8282
" Auxiliary Functions {{{2
@@ -183,16 +183,12 @@ function GetJavascriptIndent()
183183
if line =~ s:line_pre . '[])}]'
184184
return indent(num)
185185
end
186-
let switch_offset = 0
187-
if index(map(synstack(v:lnum, 1), 'synIDattr( v:val, "name")'),'jsSwitchBlock') > -1
188-
let bnum = search('\<switch\s*(','nbW')
189-
let switch_offset = bnum < num || bnum == lnum ? 0 : &cino !~ ':' || !has('float') ? s:sw() :
190-
\ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (match(&cino,'.*:\zs[^,]*s') ? s:sw() : 1))
191-
endif
186+
let inb = num == 0 ? 1 : s:Onescope(num, strpart(getline(num),0,b:js_cache[2] - 1),1)
187+
let switch_offset = (!inb || num == 0) || expand("<cword>") != 'switch' ? 0 : &cino !~ ':' || !has('float') ? s:sw() :
188+
\ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (match(&cino,'.*:\zs[^,]*s') ? s:sw() : 1))
192189
if ((line =~ g:javascript_opfirst ||
193190
\ (getline(lnum) =~ g:javascript_continuation && getline(lnum) !~ s:expr_case)) &&
194-
\ (num == 0 || s:Onescope(num, strpart(getline(num),0,b:js_cache[2] - 1),1))) ||
195-
\ (s:Onescope(lnum,getline(lnum),0) && line !~ s:line_pre . '{')
191+
\ inb) || (s:Onescope(lnum,getline(lnum),0) && line !~ s:line_pre . '{')
196192
return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset
197193
elseif num > 0
198194
return indent(num) + s:sw() + switch_offset

0 commit comments

Comments
 (0)