5
5
" Last Change: August 7, 2016
6
6
7
7
" Only load this indent file when no other was loaded.
8
- if exists (" b:did_indent" )
8
+ if exists (' b:did_indent' )
9
9
finish
10
10
endif
11
11
let b: did_indent = 1
@@ -19,7 +19,7 @@ setlocal cinoptions+=j1,J1
19
19
let b: undo_indent = ' setlocal indentexpr< indentkeys< cinoptions<'
20
20
21
21
" Only define the function once.
22
- if exists (" *GetJavascriptIndent" )
22
+ if exists (' *GetJavascriptIndent' )
23
23
finish
24
24
endif
25
25
@@ -76,7 +76,7 @@ function s:Onescope(lnum,text,add)
76
76
\ s: lookForParens (' (' , ' )' , ' cbW' , 100 ) > 0 && search ((a: add ?
77
77
\ ' \%(function\*\|[[:lower:][:upper:]_$][[:digit:][:lower:][:upper:]_$]*\)' :
78
78
\ ' \<\%(for\%(\s\+each\)\=\|if\|let\|w\%(hile\|ith\)\)' ) . ' \_s*\%#\C' ,' bW' ) &&
79
- \ (a: add || (expand (" <cword>" ) == # ' while' ? ! s: lookForParens (' \<do\>\C' , ' \<while\>\C' ,' bW' ,100 ) : 1 ))
79
+ \ (a: add || (expand (' <cword>' ) == # ' while' ? ! s: lookForParens (' \<do\>\C' , ' \<while\>\C' ,' bW' ,100 ) : 1 ))
80
80
endfunction
81
81
82
82
" Auxiliary Functions {{{2
@@ -88,33 +88,33 @@ endfunction
88
88
89
89
" Find line above 'lnum' that isn't empty, in a comment, or in a string.
90
90
function s: PrevCodeLine (lnum)
91
- let lnum = prevnonblank (a: lnum )
92
- while lnum > 0
93
- if synIDattr (synID (lnum,matchend (getline (lnum), ' ^\s*[^'' "]' ),0 ),' name' ) !~? s: syng_strcom
91
+ let l: lnum = prevnonblank (a: lnum )
92
+ while l: lnum > 0
93
+ if synIDattr (synID (l: lnum ,matchend (getline (l: lnum ), ' ^\s*[^'' "]' ),0 ),' name' ) !~? s: syng_strcom
94
94
break
95
95
endif
96
- let lnum = prevnonblank (lnum - 1 )
96
+ let l: lnum = prevnonblank (l: lnum - 1 )
97
97
endwhile
98
- return lnum
98
+ return l: lnum
99
99
endfunction
100
100
101
101
" Check if line 'lnum' has a balanced amount of parentheses.
102
102
function s: Balanced (lnum)
103
103
let open_0 = 0
104
104
let open_2 = 0
105
105
let open_4 = 0
106
- let line = getline (a: lnum )
107
- let pos = match (line , ' [][(){}]' , 0 )
106
+ let l: line = getline (a: lnum )
107
+ let pos = match (l: line , ' [][(){}]' , 0 )
108
108
while pos != -1
109
109
if synIDattr (synID (a: lnum ,pos + 1 ,0 ),' name' ) !~? s: syng_strcom
110
- let idx = stridx (' (){}[]' , line [pos])
110
+ let idx = stridx (' (){}[]' , l: line [pos])
111
111
if idx % 2 == 0
112
112
let open_{idx} = open_{idx} + 1
113
113
else
114
114
let open_{idx - 1 } = open_{idx - 1 } - 1
115
115
endif
116
116
endif
117
- let pos = match (line , ' [][(){}]' , pos + 1 )
117
+ let pos = match (l: line , ' [][(){}]' , pos + 1 )
118
118
endwhile
119
119
return (! open_4 + ! open_2 + ! open_0) - 2
120
120
endfunction
@@ -125,23 +125,23 @@ function GetJavascriptIndent()
125
125
let b: js_cache = [0 ,0 ,0 ]
126
126
endif
127
127
" Get the current line.
128
- let line = getline (v: lnum )
128
+ let l: line = getline (v: lnum )
129
129
let syns = synIDattr (synID (v: lnum , 1 , 0 ), ' name' )
130
130
131
131
" start with strings,comments,etc.{{{2
132
- if (line !~ ' ^['' "`]' && syns = ~? ' string\|template' ) ||
133
- \ (line !~ ' ^\s*[/*]' && syns = ~? s: syng_comment )
132
+ if (l: line !~ ' ^['' "`]' && syns = ~? ' string\|template' ) ||
133
+ \ (l: line !~ ' ^\s*[/*]' && syns = ~? s: syng_comment )
134
134
return -1
135
135
endif
136
- if line !~ ' ^\%(\/\*\|\s*\/\/\)' && syns = ~? s: syng_comment
136
+ if l: line !~ ' ^\%(\/\*\|\s*\/\/\)' && syns = ~? s: syng_comment
137
137
return cindent (v: lnum )
138
138
endif
139
- let lnum = s: PrevCodeLine (v: lnum - 1 )
140
- if lnum == 0
139
+ let l: lnum = s: PrevCodeLine (v: lnum - 1 )
140
+ if l: lnum == 0
141
141
return 0
142
142
endif
143
143
144
- if (line = ~# s: expr_case )
144
+ if (l: line = ~# s: expr_case )
145
145
let cpo_switch = &cpo
146
146
set cpo += %
147
147
let ind = cindent (v: lnum )
@@ -153,10 +153,10 @@ function GetJavascriptIndent()
153
153
" the containing paren, bracket, curly. Memoize, last lineNr either has the
154
154
" same scope or starts a new one, unless if it closed a scope.
155
155
call cursor (v: lnum ,1 )
156
- if b: js_cache [0 ] >= lnum && b: js_cache [0 ] <= v: lnum && b: js_cache [0 ] &&
157
- \ (b: js_cache [0 ] > lnum || s: Balanced (lnum) > 0 )
156
+ if b: js_cache [0 ] >= l: lnum && b: js_cache [0 ] <= v: lnum && b: js_cache [0 ] &&
157
+ \ (b: js_cache [0 ] > l: lnum || s: Balanced (l: lnum ) > 0 )
158
158
let num = b: js_cache [1 ]
159
- elseif syns != ' ' && line [0 ] = ~ ' \s'
159
+ elseif syns != ' ' && l: line [0 ] = ~ ' \s'
160
160
let pattern = syns = ~? ' block' ? [' {' ,' }' ] : syns = ~? ' jsparen' ? [' (' ,' )' ] :
161
161
\ syns = ~? ' jsbracket' ? [' \[' ,' \]' ] : [' [({[]' ,' [])}]' ]
162
162
let num = s: lookForParens (pattern[0 ],pattern[1 ],' bW' ,2000 )
@@ -165,21 +165,21 @@ function GetJavascriptIndent()
165
165
endif
166
166
let b: js_cache = [v: lnum ,num,line (' .' ) == v: lnum ? b: js_cache [2 ] : col (' .' )]
167
167
168
- if line = ~ s: line_pre . ' [])}]'
168
+ if l: line = ~ s: line_pre . ' [])}]'
169
169
return indent (num)
170
170
endif
171
171
172
- let pline = s: StripLine (getline (lnum))
172
+ let pline = s: StripLine (getline (l: lnum ))
173
173
let inb = num == 0 ? 1 : (s: Onescope (num, s: StripLine (strpart (getline (num),0 ,b: js_cache [2 ] - 1 )),1 ) ||
174
- \ (line !~ s: line_pre . ' ,' && pline !~ ' ,' . s: line_term )) && num < lnum
174
+ \ (l: line !~ s: line_pre . ' ,' && pline !~ ' ,' . s: line_term )) && num < l: lnum
175
175
let switch_offset = (! inb || num == 0 ) || expand (" <cword>" ) !=# ' switch' ? 0 : &cino !~ ' :' || ! has (' float' ) ? s: sw () :
176
176
\ float2nr (str2float (matchstr (&cino ,' .*:\zs[-0-9.]*' )) * (&cino = ~# ' .*:[^,]*s' ? s: sw () : 1 ))
177
177
178
178
" most significant, find the indent amount
179
- if (inb && (line = ~# g: javascript_opfirst ||
180
- \ (pline = ~# g: javascript_continuation && pline !~# s: expr_case && (pline !~ ' :' . s: line_term || line !~#
179
+ if (inb && (l: line = ~# g: javascript_opfirst ||
180
+ \ (pline = ~# g: javascript_continuation && pline !~# s: expr_case && (pline !~ ' :' . s: line_term || l: line !~#
181
181
\ s: line_pre . ' \%(d\%(o\|ebugger\)\|else\|f\%(or\|inally\)\|if\|let\|switch\|t\%(hrow\|ry\)\|w\%(hile\|ith\)\)\>' )))) ||
182
- \ (num < lnum && s: Onescope (lnum,pline,0 ) && line !~ s: line_pre . ' {' )
182
+ \ (num < l: lnum && s: Onescope (l: lnum ,pline,0 ) && l: line !~ s: line_pre . ' {' )
183
183
return (num > 0 ? indent (num) : - s: sw ()) + (s: sw () * 2 ) + switch_offset
184
184
elseif num > 0
185
185
return indent (num) + s: sw () + switch_offset
0 commit comments