From 09196db074332b4eb86297e768e1f5770a6bf234 Mon Sep 17 00:00:00 2001 From: bounceme Date: Wed, 1 Jun 2016 02:06:39 -0700 Subject: [PATCH 1/4] 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 --- indent/javascript.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 85badf8a..5476a6ba 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -193,16 +193,18 @@ endfunction " Find if the string is inside var statement (but not the first string) function s:InMultiVarStatement(lnum, cont, prev) let lnum = s:PrevNonBlankNonString(a:lnum - 1) + let cont = a:cont let prev = a:prev " let type = synIDattr(synID(lnum, indent(lnum) + 1, 0), 'name') " loop through previous expressions to find a var statement - while lnum > 0 && (s:Match(lnum, s:comma_last) ||(a:cont && getline(lnum) =~ s:line_pre . '}') || + while lnum > 0 && (s:Match(lnum, s:comma_last) ||(cont && getline(lnum) =~ s:line_pre . '[]})]') || \ s:Match(lnum,s:continuation_regex)) || (prev && (s:Match(prev, s:comma_last) || \ s:Match(prev,s:continuation_regex))) " if the line is a js keyword - if a:cont + if cont + let cont = 0 call cursor(lnum,1) let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) if parlnum > 0 From 9726dbba096e8caaca06b6417df477d518cbf338 Mon Sep 17 00:00:00 2001 From: bounceme Date: Wed, 1 Jun 2016 23:57:24 -0700 Subject: [PATCH 2/4] fix for operator first 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 } ``` --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 5476a6ba..3a183fb0 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -383,7 +383,7 @@ function GetJavascriptIndent() if parlnum > 0 && s:Match(parlnum, s:operator_first) return indent(parlnum) end - elseif counts[0] != '1' && counts[1] != '1' && counts[2] != '1' + elseif (counts[0] != '1' && counts[1] != '1' && counts[2] != '1') && !s:Match(s:PrevNonBlankNonString(lnum - 1), s:block_regex) " otherwise, indent 1 level return indent(lnum) + s:sw() end From 7049a596b92646dbcdfaf7c9855cd681a8931b73 Mon Sep 17 00:00:00 2001 From: bounceme Date: Wed, 1 Jun 2016 23:59:56 -0700 Subject: [PATCH 3/4] Update javascript.vim --- indent/javascript.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 3a183fb0..c2906f11 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -383,7 +383,8 @@ function GetJavascriptIndent() if parlnum > 0 && s:Match(parlnum, s:operator_first) return indent(parlnum) end - elseif (counts[0] != '1' && counts[1] != '1' && counts[2] != '1') && !s:Match(s:PrevNonBlankNonString(lnum - 1), s:block_regex) + elseif (counts[0] != '1' && counts[1] != '1' && counts[2] != '1') && + \ !s:Match(s:PrevNonBlankNonString(lnum - 1), s:block_regex) " otherwise, indent 1 level return indent(lnum) + s:sw() end From 26d4fbb954fa059d9e9caf419a7351df332fad8e Mon Sep 17 00:00:00 2001 From: bounceme Date: Thu, 2 Jun 2016 00:25:55 -0700 Subject: [PATCH 4/4] Update javascript.vim --- indent/javascript.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index c2906f11..a76a1b89 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -383,8 +383,9 @@ function GetJavascriptIndent() if parlnum > 0 && s:Match(parlnum, s:operator_first) return indent(parlnum) end - elseif (counts[0] != '1' && counts[1] != '1' && counts[2] != '1') && - \ !s:Match(s:PrevNonBlankNonString(lnum - 1), s:block_regex) + elseif (counts[0] != '1' && counts[1] != '1' && counts[2] != '1') && + \ (!s:Match(s:PrevNonBlankNonString(lnum - 1), s:block_regex) || + \ s:Match(lnum, s:var_stmt)) " otherwise, indent 1 level return indent(lnum) + s:sw() end