Skip to content

Commit 2a85b3c

Browse files
authored
ind updates (#593)
1 parent 5632438 commit 2a85b3c

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

indent/javascript.vim

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Language: Javascript
33
" Maintainer: vim-javascript community
44
" URL: https://github.com/pangloss/vim-javascript
5-
" Last Change: August 2, 2016
5+
" Last Change: August 6, 2016
66

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

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

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

106106
" Check if line 'lnum' has more opening brackets than closing ones.
107-
function s:LineHasOpeningBrackets(lnum)
107+
function s:Balanced(lnum)
108108
let open_0 = 0
109109
let open_2 = 0
110110
let open_4 = 0
@@ -121,8 +121,7 @@ function s:LineHasOpeningBrackets(lnum)
121121
endif
122122
let pos = match(line, '[][(){}]', pos + 1)
123123
endwhile
124-
return (open_0 > 0 ? 1 : (open_0 == 0 ? 0 : 2)) . (open_2 > 0 ? 1 : (open_2 == 0 ? 0 : 2)) .
125-
\ (open_4 > 0 ? 1 : (open_4 == 0 ? 0 : 2))
124+
return (!open_4 + !open_2 + !open_0) - 2
126125
endfunction
127126
" }}}
128127

@@ -160,19 +159,16 @@ function GetJavascriptIndent()
160159
" the containing paren, bracket, curly. Memoize, last lineNr either has the
161160
" same scope or starts a new one, unless if it closed a scope.
162161
call cursor(v:lnum,1)
163-
let pcounts = [0]
164162
if b:js_cache[0] >= lnum && b:js_cache[0] <= v:lnum && b:js_cache[0] &&
165-
\ (b:js_cache[0] > lnum || map(pcounts,'s:LineHasOpeningBrackets(lnum)')[0] !~ '2')
166-
let num = pcounts[0] =~ '1' ? s:lookForParens('[({[]','[])}]','bW',2000) : b:js_cache[1]
167-
else
163+
\ (b:js_cache[0] > lnum || s:Balanced(lnum) > 0)
164+
let num = b:js_cache[1]
165+
elseif line[0] =~ '\s'
168166
let syns = synIDattr(synID(v:lnum, 1, 1), 'name')
169-
if line[0] =~ '\s' && syns != ''
170-
let pattern = syns =~? 'funcblock' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : syns =~? 'jsbracket'? ['\[','\]'] :
171-
\ ['[({[]','[])}]']
172-
let num = s:lookForParens(pattern[0],pattern[1],'bW',2000)
173-
else
174-
let num = s:lookForParens('[({[]','[])}]','bW',2000)
175-
endif
167+
let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] :
168+
\ syns =~? 'jsbracket'? ['\[','\]'] : ['[({[]','[])}]']
169+
let num = s:lookForParens(pattern[0],pattern[1],'bW',2000)
170+
else
171+
let num = s:lookForParens('[({[]','[])}]','bW',2000)
176172
endif
177173
let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')]
178174

0 commit comments

Comments
 (0)