Skip to content

Commit d6e174b

Browse files
committed
limiting for slow function and operator fix (#455)
* prevent repeated calls of searchpair ``` var magicWords = ['abracadabra', 'gesundheit', 'ventrilo'], spells = { 'fireball': function() { setOnFire() }, 'water': function() { putOut() } }, a = 1, b = 'abc', etc, somethingElse someFunc(param1, param2, param3, param4) ``` at the line which starts with a curly brace followed by a comment this was added for traversing the comma less property lines, however this only needs to be called once.this improves performance when using the endline operator style an operator would previously create an unnecessary indent when following a line which was the first of a list of block enclosed items, e.g. a array, function call, or object before: ``` vardefaultModules = { 'http:': http ,'https:': https } ``` after: ``` vardefaultModules = { 'http:': http ,'https:': https } ```
1 parent 5962584 commit d6e174b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

indent/javascript.vim

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,18 @@ endfunction
193193
" Find if the string is inside var statement (but not the first string)
194194
function s:InMultiVarStatement(lnum, cont, prev)
195195
let lnum = s:PrevNonBlankNonString(a:lnum - 1)
196+
let cont = a:cont
196197
let prev = a:prev
197198

198199
" let type = synIDattr(synID(lnum, indent(lnum) + 1, 0), 'name')
199200

200201
" loop through previous expressions to find a var statement
201-
while lnum > 0 && (s:Match(lnum, s:comma_last) ||(a:cont && getline(lnum) =~ s:line_pre . '}') ||
202+
while lnum > 0 && (s:Match(lnum, s:comma_last) ||(cont && getline(lnum) =~ s:line_pre . '[]})]') ||
202203
\ s:Match(lnum,s:continuation_regex)) || (prev && (s:Match(prev, s:comma_last) ||
203204
\ s:Match(prev,s:continuation_regex)))
204205
" if the line is a js keyword
205-
if a:cont
206+
if cont
207+
let cont = 0
206208
call cursor(lnum,1)
207209
let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0)
208210
if parlnum > 0
@@ -381,7 +383,9 @@ function GetJavascriptIndent()
381383
if parlnum > 0 && s:Match(parlnum, s:operator_first)
382384
return indent(parlnum)
383385
end
384-
elseif counts[0] != '1' && counts[1] != '1' && counts[2] != '1'
386+
elseif (counts[0] != '1' && counts[1] != '1' && counts[2] != '1') &&
387+
\ (!s:Match(s:PrevNonBlankNonString(lnum - 1), s:block_regex) ||
388+
\ s:Match(lnum, s:var_stmt))
385389
" otherwise, indent 1 level
386390
return indent(lnum) + s:sw()
387391
end

0 commit comments

Comments
 (0)