Skip to content

ind updates #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 6, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions indent/javascript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
" Language: Javascript
" Maintainer: vim-javascript community
" URL: https://github.com/pangloss/vim-javascript
" Last Change: August 2, 2016
" Last Change: August 6, 2016

" Only load this indent file when no other was loaded.
if exists("b:did_indent")
Expand Down Expand Up @@ -88,7 +88,7 @@ endfunction

" Check if the character at lnum:col is inside a string, comment, or is ascii.
function s:IsSyn(lnum, col, reg)
return synIDattr(synID(a:lnum, a:col, 1), 'name') =~? (a:reg != '' ? a:reg : s:syng_strcom)
return synIDattr(synID(a:lnum, a:col, 0), 'name') =~? (a:reg != '' ? a:reg : s:syng_strcom)
endfunction

" Find line above 'lnum' that isn't empty, in a comment, or in a string.
Expand All @@ -104,7 +104,7 @@ function s:PrevCodeLine(lnum)
endfunction

" Check if line 'lnum' has more opening brackets than closing ones.
function s:LineHasOpeningBrackets(lnum)
function s:Balanced(lnum)
let open_0 = 0
let open_2 = 0
let open_4 = 0
Expand All @@ -121,8 +121,7 @@ function s:LineHasOpeningBrackets(lnum)
endif
let pos = match(line, '[][(){}]', pos + 1)
endwhile
return (open_0 > 0 ? 1 : (open_0 == 0 ? 0 : 2)) . (open_2 > 0 ? 1 : (open_2 == 0 ? 0 : 2)) .
\ (open_4 > 0 ? 1 : (open_4 == 0 ? 0 : 2))
return (!open_4 + !open_2 + !open_0) - 2
endfunction
" }}}

Expand Down Expand Up @@ -160,19 +159,16 @@ function GetJavascriptIndent()
" the containing paren, bracket, curly. Memoize, last lineNr either has the
" same scope or starts a new one, unless if it closed a scope.
call cursor(v:lnum,1)
let pcounts = [0]
if b:js_cache[0] >= lnum && b:js_cache[0] <= v:lnum && b:js_cache[0] &&
\ (b:js_cache[0] > lnum || map(pcounts,'s:LineHasOpeningBrackets(lnum)')[0] !~ '2')
let num = pcounts[0] =~ '1' ? s:lookForParens('[({[]','[])}]','bW',2000) : b:js_cache[1]
else
\ (b:js_cache[0] > lnum || s:Balanced(lnum) > 0)
let num = b:js_cache[1]
elseif line[0] =~ '\s'
let syns = synIDattr(synID(v:lnum, 1, 1), 'name')
if line[0] =~ '\s' && syns != ''
let pattern = syns =~? 'funcblock' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : syns =~? 'jsbracket'? ['\[','\]'] :
\ ['[({[]','[])}]']
let num = s:lookForParens(pattern[0],pattern[1],'bW',2000)
else
let num = s:lookForParens('[({[]','[])}]','bW',2000)
endif
let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] :
\ syns =~? 'jsbracket'? ['\[','\]'] : ['[({[]','[])}]']
let num = s:lookForParens(pattern[0],pattern[1],'bW',2000)
else
let num = s:lookForParens('[({[]','[])}]','bW',2000)
endif
let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')]

Expand Down