2
2
" Language: Javascript
3
3
" Maintainer: vim-javascript community
4
4
" URL: https://github.com/pangloss/vim-javascript
5
- " Last Change: August 2 , 2016
5
+ " Last Change: August 6 , 2016
6
6
7
7
" Only load this indent file when no other was loaded.
8
8
if exists (" b:did_indent" )
@@ -88,7 +88,7 @@ endfunction
88
88
89
89
" Check if the character at lnum:col is inside a string, comment, or is ascii.
90
90
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 )
92
92
endfunction
93
93
94
94
" Find line above 'lnum' that isn't empty, in a comment, or in a string.
@@ -104,7 +104,7 @@ function s:PrevCodeLine(lnum)
104
104
endfunction
105
105
106
106
" Check if line 'lnum' has more opening brackets than closing ones.
107
- function s: LineHasOpeningBrackets (lnum)
107
+ function s: Balanced (lnum)
108
108
let open_0 = 0
109
109
let open_2 = 0
110
110
let open_4 = 0
@@ -121,8 +121,7 @@ function s:LineHasOpeningBrackets(lnum)
121
121
endif
122
122
let pos = match (line , ' [][(){}]' , pos + 1 )
123
123
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
126
125
endfunction
127
126
" }}}
128
127
@@ -160,19 +159,16 @@ function GetJavascriptIndent()
160
159
" the containing paren, bracket, curly. Memoize, last lineNr either has the
161
160
" same scope or starts a new one, unless if it closed a scope.
162
161
call cursor (v: lnum ,1 )
163
- let pcounts = [0 ]
164
162
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 '
168
166
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 )
176
172
endif
177
173
let b: js_cache = [v: lnum ,num,line (' .' ) == v: lnum ? b: js_cache [2 ] : col (' .' )]
178
174
0 commit comments