Skip to content

Commit dcb4e47

Browse files
authored
cleaning, small optimization? (pangloss#1015)
* cleaning, small optimization? * comment
1 parent 7097cda commit dcb4e47

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

indent/javascript.vim

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,25 +106,28 @@ function s:ParseCino(f)
106106
return sign * str2nr(n) / max([str2nr(divider),1])
107107
endfunction
108108

109-
" Optimized {skip} expr, used only once per GetJavascriptIndent() call
109+
" Optimized {skip} expr, only callable from the search loop which
110+
" GetJavascriptIndent does to find the containing [[{(] (relies on s:vars)
110111
function s:SkipFunc()
111112
if s:top_col == 1
112113
throw 'out of bounds'
113114
endif
114-
let s:top_col = col('.')
115-
if getline('.') =~ '\%<'.s:top_col.'c\/.\{-}\/\|\%>'.s:top_col.'c[''"]\|\\$'
115+
let s:top_col = 0
116+
if s:check_in
116117
if eval(s:skip_expr)
117-
let s:top_col = 0
118+
return 1
118119
endif
119-
return !s:top_col
120-
elseif s:check_in || search('\m`\|\${\|\*\/','nW'.s:z,s:looksyn)
121-
let s:check_in = eval(s:skip_expr)
122-
if s:check_in
123-
let s:top_col = 0
120+
let s:check_in = 0
121+
elseif getline('.') =~ '\%<'.col('.').'c\/.\{-}\/\|\%>'.col('.').'c[''"]\|\\$'
122+
if eval(s:skip_expr)
123+
let s:looksyn = line('.')
124+
return 1
124125
endif
126+
elseif search('\m`\|\${\|\*\/','nW'.s:z,s:looksyn) && eval(s:skip_expr)
127+
let s:check_in = 1
128+
return 1
125129
endif
126-
let s:looksyn = line('.')
127-
return s:check_in
130+
let [s:looksyn, s:top_col] = getpos('.')[1:2]
128131
endfunction
129132

130133
function s:AlternatePair()

0 commit comments

Comments
 (0)