From bfbc10d2fe9ffd39d9e38251aaa4a0404b1acedd Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Mon, 27 Jun 2016 15:26:35 -0700 Subject: [PATCH 01/63] Fixed jsFlowTypeObjects not being closed --- extras/flow.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extras/flow.vim b/extras/flow.vim index 3b4036da..8aa19e96 100644 --- a/extras/flow.vim +++ b/extras/flow.vim @@ -2,9 +2,9 @@ syntax region jsFlowTypeStatement start=/type/ end=/=/ onelin syntax region jsFlowDeclareBlock start=/declare/ end=/[;\n]/ oneline contains=jsFlow,jsFlowDeclareKeyword,jsFlowStorageClass syntax region jsFlow start=/:/ end=/\%(\%([),=;\n]\|{\%(.*}\)\@!\|\%({.*}\)\@<=\s*{\)\@=\|void\)/ contains=@jsFlowCluster oneline skipwhite skipempty nextgroup=jsFuncBlock syntax region jsFlowReturn contained start=/:/ end=/\%(\S\s*\%({\%(.*}\)\@!\)\@=\|\n\)/ contains=@jsFlowCluster oneline skipwhite skipempty nextgroup=jsFuncBlock keepend -syntax region jsFlowTypeObject contained start=/{/ end=/}/ contains=jsFlowTypeKey skipwhite skipempty nextgroup=jsFunctionBlock extend +syntax region jsFlowTypeObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsFlowTypeKey,jsFlowNoise skipwhite skipempty nextgroup=jsFunctionBlock extend syntax match jsFlowTypeKey contained /\<[0-9a-zA-Z_$?]*\>\(\s*:\)\@=/ skipwhite skipempty nextgroup=jsFlowTypeValue -syntax region jsFlowTypeValue contained matchgroup=jsFlowNoise start=/:/ end=/[,}]/ contains=@jsFlowCluster +syntax region jsFlowTypeValue contained matchgroup=jsFlowNoise start=/:/ end=/[,}]\@=/ contains=@jsFlowCluster syntax region jsFlowObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ oneline contains=@jsFlowCluster syntax region jsFlowArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ oneline contains=@jsFlowCluster syntax region jsFlowArrow contained matchgroup=jsFlowNoise start=/(/ end=/)\s*=>/ oneline contains=@jsFlowCluster From 4670d4fcabb3caf96e2115705d59d77dff8bb932 Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Tue, 28 Jun 2016 11:41:52 -0700 Subject: [PATCH 02/63] Fix for jsFlowTypeValue --- extras/flow.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/flow.vim b/extras/flow.vim index 8aa19e96..1548b9c2 100644 --- a/extras/flow.vim +++ b/extras/flow.vim @@ -4,7 +4,7 @@ syntax region jsFlow start=/:/ end=/\%(\%([),=;\n syntax region jsFlowReturn contained start=/:/ end=/\%(\S\s*\%({\%(.*}\)\@!\)\@=\|\n\)/ contains=@jsFlowCluster oneline skipwhite skipempty nextgroup=jsFuncBlock keepend syntax region jsFlowTypeObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsFlowTypeKey,jsFlowNoise skipwhite skipempty nextgroup=jsFunctionBlock extend syntax match jsFlowTypeKey contained /\<[0-9a-zA-Z_$?]*\>\(\s*:\)\@=/ skipwhite skipempty nextgroup=jsFlowTypeValue -syntax region jsFlowTypeValue contained matchgroup=jsFlowNoise start=/:/ end=/[,}]\@=/ contains=@jsFlowCluster +syntax region jsFlowTypeValue contained matchgroup=jsFlowNoise start=/:/ end=/[,};]\@=/ contains=@jsFlowCluster syntax region jsFlowObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ oneline contains=@jsFlowCluster syntax region jsFlowArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ oneline contains=@jsFlowCluster syntax region jsFlowArrow contained matchgroup=jsFlowNoise start=/(/ end=/)\s*=>/ oneline contains=@jsFlowCluster From 583a4948d28f22e6d078ef13db2d65005f081e65 Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Tue, 28 Jun 2016 11:42:10 -0700 Subject: [PATCH 03/63] Including jsFlow in other contexts --- extras/flow.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/flow.vim b/extras/flow.vim index 1548b9c2..a5bf8b56 100644 --- a/extras/flow.vim +++ b/extras/flow.vim @@ -1,6 +1,6 @@ syntax region jsFlowTypeStatement start=/type/ end=/=/ oneline skipwhite skipempty nextgroup=jsFlowTypeObject syntax region jsFlowDeclareBlock start=/declare/ end=/[;\n]/ oneline contains=jsFlow,jsFlowDeclareKeyword,jsFlowStorageClass -syntax region jsFlow start=/:/ end=/\%(\%([),=;\n]\|{\%(.*}\)\@!\|\%({.*}\)\@<=\s*{\)\@=\|void\)/ contains=@jsFlowCluster oneline skipwhite skipempty nextgroup=jsFuncBlock +syntax region jsFlow start=/:/ end=/\%(\%([),=;\n]\|{\%(.*}\)\@!\|\%({.*}\)\@<=\s*{\)\@=\|void\)/ contains=@jsFlowCluster containedin=jsBlock,jsClassBlock,jsFuncBlock,jsBlock,jsTryCatchBlock,jsSwitchBlock,jsParen oneline skipwhite skipempty nextgroup=jsFuncBlock syntax region jsFlowReturn contained start=/:/ end=/\%(\S\s*\%({\%(.*}\)\@!\)\@=\|\n\)/ contains=@jsFlowCluster oneline skipwhite skipempty nextgroup=jsFuncBlock keepend syntax region jsFlowTypeObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsFlowTypeKey,jsFlowNoise skipwhite skipempty nextgroup=jsFunctionBlock extend syntax match jsFlowTypeKey contained /\<[0-9a-zA-Z_$?]*\>\(\s*:\)\@=/ skipwhite skipempty nextgroup=jsFlowTypeValue From 5a699857eddb988d27cb1a74acdcc873a8b9c384 Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Tue, 28 Jun 2016 11:47:28 -0700 Subject: [PATCH 04/63] Adding bool to jsFlowType --- extras/flow.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/flow.vim b/extras/flow.vim index a5bf8b56..759d7548 100644 --- a/extras/flow.vim +++ b/extras/flow.vim @@ -9,7 +9,7 @@ syntax region jsFlowObject contained matchgroup=jsFlowNoise start=/{/ syntax region jsFlowArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ oneline contains=@jsFlowCluster syntax region jsFlowArrow contained matchgroup=jsFlowNoise start=/(/ end=/)\s*=>/ oneline contains=@jsFlowCluster syntax keyword jsFlowDeclareKeyword contained declare -syntax keyword jsFlowType contained boolean number string null void any mixed JSON array function object Array +syntax keyword jsFlowType contained boolean number string null void any mixed JSON array function object Array bool syntax match jsFlowClassProperty contained /\<[0-9a-zA-Z_$]*\>:\@=/ skipwhite skipempty nextgroup=jsFlow syntax match jsFlowNoise contained /[:;,<>]/ syntax cluster jsFlowCluster contains=jsFlowType,jsFlowArray,jsFlowObject,jsFlowNoise,jsFlowArrow From 4133fcad01ad6593d17fa77c5bd9b86d9e336887 Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Wed, 29 Jun 2016 20:32:34 -0700 Subject: [PATCH 05/63] Linking jsClassDefinition to jsFuncName They really should be linked, because jsClassDefinition is really just a function --- syntax/javascript.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index 256fe746..b8a3b422 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -300,6 +300,7 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsSwitchColon Noise HiLink jsClassMethodType Type HiLink jsObjectMethodType Type + HiLink jsClassDefinition jsFuncName HiLink jsDestructuringBraces Noise HiLink jsDestructuringProperty jsFuncArgs From ac92e1b2856ac887ff358bb64c1f9ce7caa56896 Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Thu, 7 Jul 2016 21:38:09 -0700 Subject: [PATCH 06/63] Adding do expression support --- syntax/javascript.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index b8a3b422..0349f5e4 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -98,7 +98,7 @@ syntax keyword jsStatement contained break continue with yield debugger syntax keyword jsConditional if else skipwhite skipempty nextgroup=jsParenIfElse,jsBlock syntax keyword jsConditional switch skipwhite skipempty nextgroup=jsParenSwitch syntax keyword jsRepeat while for skipwhite skipempty nextgroup=jsParenRepeat -syntax keyword jsRepeat do skipwhite skipempty nextgroup=jsBlock +syntax keyword jsDo do skipwhite skipempty nextgroup=jsBlock syntax keyword jsLabel contained case default syntax keyword jsTry try skipwhite skipempty nextgroup=jsTryCatchBlock syntax keyword jsFinally contained finally skipwhite skipempty nextgroup=jsBlock @@ -203,7 +203,7 @@ if exists("javascript_plugin_flow") runtime extras/flow.vim endif -syntax cluster jsExpression contains=jsBracket,jsParen,jsObject,jsBlock,jsTernaryIf,jsTaggedTemplate,jsTemplateString,jsString,jsRegexpString,jsNumber,jsFloat,jsOperator,jsBooleanTrue,jsBooleanFalse,jsNull,jsFunction,jsArrowFunction,jsGlobalObjects,jsExceptions,jsFutureKeys,jsDomErrNo,jsDomNodeConsts,jsHtmlEvents,jsFuncCall,jsUndefined,jsNan,jsPrototype,jsBuiltins,jsNoise,jsClassDefinition,jsArrowFunction,jsArrowFuncArgs,jsParensError,jsComment,jsArguments,jsThis,jsSuper +syntax cluster jsExpression contains=jsBracket,jsParen,jsObject,jsBlock,jsTernaryIf,jsTaggedTemplate,jsTemplateString,jsString,jsRegexpString,jsNumber,jsFloat,jsOperator,jsBooleanTrue,jsBooleanFalse,jsNull,jsFunction,jsArrowFunction,jsGlobalObjects,jsExceptions,jsFutureKeys,jsDomErrNo,jsDomNodeConsts,jsHtmlEvents,jsFuncCall,jsUndefined,jsNan,jsPrototype,jsBuiltins,jsNoise,jsClassDefinition,jsArrowFunction,jsArrowFuncArgs,jsParensError,jsComment,jsArguments,jsThis,jsSuper,jsDo syntax cluster jsAll contains=@jsExpression,jsExportContainer,jsImportContainer,jsStorageClass,jsConditional,jsRepeat,jsReturn,jsStatement,jsException,jsTry,jsAsyncKeyword " Define the default highlighting. @@ -241,6 +241,7 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsLabel Label HiLink jsReturn Statement HiLink jsRepeat Repeat + HiLink jsDo Repeat HiLink jsStatement Statement HiLink jsException Exception HiLink jsTry Exception From 3b8017ef647e181567f25964dff0cdf6a6427d01 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Sun, 10 Jul 2016 21:28:55 -0400 Subject: [PATCH 07/63] Remove jsOperator from jsClassBlock It screws up highlighting of the operators when they are used as method names: ![`delete` keyword as class method](https://dl.dropboxusercontent.com/content_link/hJYRBOhHwrBDjhoAesh3LuRS2eFPlaTSLSHLsKTq8CnfKur0FwNQ3GGo7cobYdLq/file). This doesn't happen if you're inside a normal object: ![`delete` keyword as obj method](https://dl.dropboxusercontent.com/content_link/hJYRBOhHwrBDjhoAesh3LuRS2eFPlaTSLSHLsKTq8CnfKur0FwNQ3GGo7cobYdLq/file) --- syntax/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index 0349f5e4..eb64354b 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -136,7 +136,7 @@ syntax region jsParenRepeat contained matchgroup=jsParens s syntax region jsParenSwitch contained matchgroup=jsParens start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsSwitchBlock extend fold syntax region jsParenCatch contained matchgroup=jsParens start=/(/ end=/)/ skipwhite skipempty nextgroup=jsTryCatchBlock extend fold syntax region jsFuncArgs contained matchgroup=jsFuncParens start=/(/ end=/)/ contains=jsFuncArgCommas,jsComment,jsFuncArgExpression,jsDestructuringBlock,jsRestExpression,jsFlow skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturn extend fold -syntax region jsClassBlock contained matchgroup=jsClassBraces start=/{/ end=/}/ contains=jsClassFuncName,jsClassMethodType,jsOperator,jsArrowFunction,jsArrowFuncArgs,jsComment,jsGenerator,jsDecorator,jsClassProperty,jsClassPropertyComputed,jsClassStringKey,jsNoise,jsFlowClassProperty extend fold +syntax region jsClassBlock contained matchgroup=jsClassBraces start=/{/ end=/}/ contains=jsClassFuncName,jsClassMethodType,jsArrowFunction,jsArrowFuncArgs,jsComment,jsGenerator,jsDecorator,jsClassProperty,jsClassPropertyComputed,jsClassStringKey,jsNoise,jsFlowClassProperty extend fold syntax region jsFuncBlock contained matchgroup=jsFuncBraces start=/{/ end=/}/ contains=@jsAll extend fold syntax region jsBlock contained matchgroup=jsBraces start=/{/ end=/}/ contains=@jsAll extend fold syntax region jsTryCatchBlock contained matchgroup=jsBraces start=/{/ end=/}/ contains=@jsAll skipwhite skipempty nextgroup=jsCatch,jsFinally extend fold From ac813c03a4085fe1ce3b9296a08681c888a274f3 Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Sun, 10 Jul 2016 22:02:54 -0700 Subject: [PATCH 08/63] Adding support for oddly placed comments * Functions * Classes * Conditionals * Repeat statements --- syntax/javascript.vim | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index eb64354b..dc85953d 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -95,7 +95,8 @@ exe 'syntax keyword jsSuper super contained '.(exists('g:javascript_conceal " Statement Keywords syntax keyword jsStatement contained break continue with yield debugger -syntax keyword jsConditional if else skipwhite skipempty nextgroup=jsParenIfElse,jsBlock +syntax keyword jsConditional if skipwhite skipempty nextgroup=jsParenIfElse +syntax keyword jsConditional else skipwhite skipempty nextgroup=jsCommentMisc,jsBlock syntax keyword jsConditional switch skipwhite skipempty nextgroup=jsParenSwitch syntax keyword jsRepeat while for skipwhite skipempty nextgroup=jsParenRepeat syntax keyword jsDo do skipwhite skipempty nextgroup=jsBlock @@ -131,11 +132,11 @@ syntax keyword jsHtmlEvents onblur onclick oncontextmenu ondblclick onfocus "" Code blocks syntax region jsBracket matchgroup=jsBrackets start=/\[/ end=/\]/ contains=@jsExpression extend fold syntax region jsParen matchgroup=jsParens start=/(/ end=/)/ contains=@jsAll extend fold -syntax region jsParenIfElse contained matchgroup=jsParens start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsBlock extend fold -syntax region jsParenRepeat contained matchgroup=jsParens start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsBlock extend fold +syntax region jsParenIfElse contained matchgroup=jsParens start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentMisc,jsBlock extend fold +syntax region jsParenRepeat contained matchgroup=jsParens start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentMisc,jsBlock extend fold syntax region jsParenSwitch contained matchgroup=jsParens start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsSwitchBlock extend fold syntax region jsParenCatch contained matchgroup=jsParens start=/(/ end=/)/ skipwhite skipempty nextgroup=jsTryCatchBlock extend fold -syntax region jsFuncArgs contained matchgroup=jsFuncParens start=/(/ end=/)/ contains=jsFuncArgCommas,jsComment,jsFuncArgExpression,jsDestructuringBlock,jsRestExpression,jsFlow skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturn extend fold +syntax region jsFuncArgs contained matchgroup=jsFuncParens start=/(/ end=/)/ contains=jsFuncArgCommas,jsComment,jsFuncArgExpression,jsDestructuringBlock,jsRestExpression,jsFlow skipwhite skipempty nextgroup=jsCommentFunction,jsFuncBlock,jsFlowReturn extend fold syntax region jsClassBlock contained matchgroup=jsClassBraces start=/{/ end=/}/ contains=jsClassFuncName,jsClassMethodType,jsArrowFunction,jsArrowFuncArgs,jsComment,jsGenerator,jsDecorator,jsClassProperty,jsClassPropertyComputed,jsClassStringKey,jsNoise,jsFlowClassProperty extend fold syntax region jsFuncBlock contained matchgroup=jsFuncBraces start=/{/ end=/}/ contains=@jsAll extend fold syntax region jsBlock contained matchgroup=jsBraces start=/{/ end=/}/ contains=@jsAll extend fold @@ -166,7 +167,7 @@ exe 'syntax match jsArrowFunction /=>/ skipwhite skipempty nextgroup=jsFunc syntax keyword jsClassKeywords contained extends class syntax match jsClassNoise contained /\./ syntax match jsClassMethodType contained /\%(get\|set\|static\|async\)\%( \k\+\)\@=/ skipwhite skipempty nextgroup=jsFuncName,jsClassProperty -syntax match jsClassDefinition /\\%( [a-zA-Z_$][0-9a-zA-Z_$ \n.]*\)*/ contains=jsClassKeywords,jsClassNoise skipwhite skipempty nextgroup=jsClassBlock,jsFlowClass +syntax match jsClassDefinition /\\%( [a-zA-Z_$][0-9a-zA-Z_$ \n.]*\)*/ contains=jsClassKeywords,jsClassNoise skipwhite skipempty nextgroup=jsCommentClass,jsClassBlock,jsFlowClass syntax match jsDecorator contained "@" nextgroup=jsDecoratorFunction syntax match jsDecoratorFunction contained "[a-zA-Z_][a-zA-Z0-9_.]*" syntax match jsClassProperty contained /\<[0-9a-zA-Z_$]*\>\(\s*=\)\@=/ skipwhite skipempty nextgroup=jsClassValue @@ -191,6 +192,16 @@ syntax region jsComment start=/\/\// end=/$/ contains=jsCommentTodo,@Spe syntax region jsComment start=/\/\*/ end=/\*\// contains=jsCommentTodo,@Spell fold extend keepend syntax region jsEnvComment start=/\%^#!/ end=/$/ display +" Specialized Comments - These are special comment regexes that are used in +" odd places that maintain the proper nextgroup functionality. It sucks we +" can't make jsComment a skippable type of group for nextgroup +syntax region jsCommentFunction contained start=/\/\// end=/$/ contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturn extend keepend +syntax region jsCommentFunction contained start=/\/\*/ end=/\*\// contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturn fold extend keepend +syntax region jsCommentClass contained start=/\/\// end=/$/ contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsClassBlock,jsFlowClass extend keepend +syntax region jsCommentClass contained start=/\/\*/ end=/\*\// contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsClassBlock,jsFlowClass fold extend keepend +syntax region jsCommentMisc contained start=/\/\// end=/$/ contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsBlock extend keepend +syntax region jsCommentMisc contained start=/\/\*/ end=/\*\// contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsBlock fold extend keepend + if exists("javascript_plugin_jsdoc") runtime extras/jsdoc.vim " NGDoc requires JSDoc @@ -308,6 +319,10 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsDestructuringAssignment jsObjectKey HiLink jsDestructuringNoise Noise + HiLink jsCommentFunction jsComment + HiLink jsCommentClass jsComment + HiLink jsCommentMisc jsComment + HiLink jsDomErrNo Constant HiLink jsDomNodeConsts Constant HiLink jsDomElemAttrs Label From 7982ec46fb6c16f68d6c11657950336689836ba0 Mon Sep 17 00:00:00 2001 From: Rom Grk Date: Tue, 12 Jul 2016 20:00:22 -0400 Subject: [PATCH 09/63] typo --- syntax/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index dc85953d..49fa5b86 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -42,7 +42,7 @@ syntax keyword jsModuleOperators contained from syntax keyword jsModuleOperators contained as syntax region jsModuleGroup contained matchgroup=jsBraces start=/{/ end=/}/ contains=jsModuleOperators,jsNoise,jsComment syntax match jsModuleAsterisk contained /*/ -syntax keyword jsModuleDefault contained default skipwhite kipempty nextgroup=@jsExpression +syntax keyword jsModuleDefault contained default skipwhite skipempty nextgroup=@jsExpression syntax region jsImportContainer start=/\ / end="\%(;\|$\)" contains=jsModuleKeywords,jsModuleOperators,jsComment,jsString,jsTemplateString,jsNoise,jsModuleGroup,jsModuleAsterisk syntax region jsExportContainer start=/\ / end="\%(;\|$\)" contains=jsModuleKeywords,jsModuleOperators,jsStorageClass,jsModuleDefault,@jsExpression syntax region jsExportBlock contained matchgroup=jsBraces start=/{/ end=/}/ contains=jsModuleOperators,jsNoise,jsComment From ed40c9cb625b8b679fbec4c5b55fde60ec27f58e Mon Sep 17 00:00:00 2001 From: Dmitri Vereshchagin Date: Fri, 15 Jul 2016 00:41:49 +0300 Subject: [PATCH 10/63] Tweak highlighting of numeric literals - Add highlighting for binary and octal number syntax - Highlight unary minus as operator regardless of 'iskeyword' option - Remove L from integer literals --- syntax/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index 49fa5b86..5ab10be7 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -52,9 +52,9 @@ syntax region jsString start=+"+ skip=+\\\("\|$\)+ end=+"\|$+ cont syntax region jsString start=+'+ skip=+\\\('\|$\)+ end=+'\|$+ contains=jsSpecial,@Spell extend syntax region jsTemplateString start=+`+ skip=+\\\(`\|$\)+ end=+`+ contains=jsTemplateVar,jsSpecial extend syntax match jsTaggedTemplate /\k\+\%(`\)\@=/ nextgroup=jsTemplateString -syntax match jsNumber /\<-\=\d\+\(L\|[eE][+-]\=\d\+\)\=\>\|\<0[xX]\x\+\>/ +syntax match jsNumber /\<\d\+\%([eE][+-]\=\d\+\)\=\>\|\<0[bB][01]\+\>\|\<0[oO]\o\+\>\|\<0[xX]\x\+\>/ syntax keyword jsNumber Infinity -syntax match jsFloat /\<-\=\%(\d\+\.\d\+\|\d\+\.\|\.\d\+\)\%([eE][+-]\=\d\+\)\=\>/ +syntax match jsFloat /\<\%(\d\+\.\d\+\|\d\+\.\|\.\d\+\)\%([eE][+-]\=\d\+\)\=\>/ " Regular Expressions syntax match jsSpecial contained "\v\\%(0|\\x\x\{2\}\|\\u\x\{4\}\|\c[A-Z]|.)" From 550e1e8e8375f529b039a1a81a66d8ad43421cac Mon Sep 17 00:00:00 2001 From: Dmitri Vereshchagin Date: Fri, 15 Jul 2016 01:12:07 +0300 Subject: [PATCH 11/63] Make use of syntax specific iskeyword setting It's better not to touch 'iskeyword' option from a syntax file if possible. --- syntax/javascript.vim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index 49fa5b86..73b00c9e 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -16,8 +16,12 @@ if !exists('g:javascript_conceal') let g:javascript_conceal = 0 endif -" Dollar sign is permittd anywhere in an identifier -setlocal iskeyword+=$ +" Dollar sign is permitted anywhere in an identifier +if v:version > 704 || v:version == 704 && has('patch1142') + syntax iskeyword @,48-57,_,192-255,$ +else + setlocal iskeyword+=$ +endif syntax sync fromstart " TODO: Figure out what type of casing I need From 8cf97bdc74ef1c774aaa5a67e2626dcc6d40b66a Mon Sep 17 00:00:00 2001 From: Dmitri Vereshchagin Date: Fri, 15 Jul 2016 02:13:53 +0300 Subject: [PATCH 12/63] Update filetype plugin - Add header - Replace 're' with 'regexpengine' - Simplify patch check --- ftplugin/javascript.vim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ftplugin/javascript.vim b/ftplugin/javascript.vim index 58755a4a..e11ea2e0 100644 --- a/ftplugin/javascript.vim +++ b/ftplugin/javascript.vim @@ -1,4 +1,10 @@ +" Vim filetype plugin file +" Language: JavaScript +" Maintainer: vim-javascript community +" URL: https://github.com/pangloss/vim-javascript + setlocal suffixesadd+=.js -if (v:version < 704 || (v:version == 704 && !has('patch002'))) && exists('®expengine') - set re=1 -end + +if v:version == 703 && exists('®expengine') || v:version == 704 && !has('patch2') + set regexpengine=1 +endif From 653858c18057c4f2e25494a0286933a1fe3bec77 Mon Sep 17 00:00:00 2001 From: Dmitri Vereshchagin Date: Fri, 15 Jul 2016 08:06:11 +0400 Subject: [PATCH 13/63] Make use of b:undo_indent variable (#542) It's better when effect of indent script can be undone. --- indent/javascript.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/indent/javascript.vim b/indent/javascript.vim index b35a05be..8a544459 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -19,6 +19,8 @@ setlocal formatexpr=Fixedgq(v:lnum,v:count) setlocal indentkeys=0{,0},0),0],0\,*,:,!^F,o,O,e setlocal cinoptions+=j1,J1,c1 +let b:undo_indent = 'setlocal smartindent< indentexpr< formatexpr< indentkeys< cinoptions<' + " Only define the function once. if exists("*GetJavascriptIndent") finish From 32e7c78716ec72f60c7962af22a8eadc287b579c Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 15 Jul 2016 00:48:31 -0700 Subject: [PATCH 14/63] indentation refactoring (#515) simplistic, accurate, possibly slow refactor switch case, code reduction & removing needless if's make search pair result local to buffer https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for_each...in do while fix case sensitivity --- indent/javascript.vim | 422 +++++++----------------------------------- 1 file changed, 66 insertions(+), 356 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 8a544459..a6dc1a74 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -2,9 +2,6 @@ " Language: Javascript " Acknowledgement: Based off of vim-ruby maintained by Nikolai Weibull http://vim-ruby.rubyforge.org -" 0. Initialization {{{1 -" ================= - " Only load this indent file when no other was loaded. if exists("b:did_indent") finish @@ -16,7 +13,7 @@ setlocal nosmartindent " Now, set up our indentation expression and keys that trigger it. setlocal indentexpr=GetJavascriptIndent() setlocal formatexpr=Fixedgq(v:lnum,v:count) -setlocal indentkeys=0{,0},0),0],0\,*,:,!^F,o,O,e +setlocal indentkeys=0{,0},0),0],:,!^F,o,O,e setlocal cinoptions+=j1,J1,c1 let b:undo_indent = 'setlocal smartindent< indentexpr< formatexpr< indentkeys< cinoptions<' @@ -40,66 +37,44 @@ else endfunc endif -" 1. Variables {{{1 -" ============ - let s:line_pre = '^\s*\%(\/\*.*\*\/\s*\)*' -let s:js_keywords = s:line_pre . '\%(break\|import\|export\|catch\|const\|continue\|debugger\|delete\|do\|else\|finally\|for\|function\|if\|in\|instanceof\|let\|new\|return\|switch\|this\|throw\|try\|typeof\|var\|void\|while\|with\)\>\C' let s:expr_case = s:line_pre . '\%(\%(case\>.*\)\|default\)\s*:\C' " Regex of syntax group names that are or delimit string or are comments. let s:syng_strcom = '\%(string\|regex\|special\|doc\|comment\|template\)\c' -" Regex of syntax group names that are strings. -let s:syng_string = 'regex\c' - " Regex of syntax group names that are strings or documentation. let s:syng_comment = '\%(comment\|doc\)\c' " Expression used to check whether we should skip a match with searchpair(). let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'" -func s:lookForParens(start,end,flags,stop) +func s:lookForParens(start,end,flags,time) try - return searchpair(a:start,'',a:end,a:flags,s:skip_expr,a:stop,300) + return searchpair(a:start,'',a:end,a:flags, + \ "line('.') < " . (prevnonblank(v:lnum) - 2000) . " ? dummy :" . s:skip_expr + \ ,0,a:time) catch /E118/ - return searchpair(a:start,'',a:end,a:flags,0,a:stop) + return searchpair(a:start,'',a:end,a:flags,0,0) endtry endfunc -let s:line_term = '\s*\%(\%(\/\/.*\)\=\|\%(\/\*.*\*\/\s*\)*\)$' +let s:line_term = '\s*\%(\%(:\@\|=>\)\C' . s:line_term +let s:continuation_regex = '\%([*,.?:]\|+\@\s*(\C', 'ce', a:lnum) > 0 && - \ s:lookForParens('(', ')', 'W', a:lnum) > 0 && - \ col('.') == strlen(s:RemoveTrailingComments(getline(a:lnum))) - call cursor(a:lnum, mypos) - return 1 - else - call cursor(a:lnum, mypos) - return 0 - end + return getline(a:lnum) =~ '\%(\\)\C' . s:line_term || + \ (cursor(a:lnum, match(getline(a:lnum),')' . s:line_term)) > -1 && + \ s:lookForParens('(', ')', 'cbW', 100) > 0 && + \ cursor(line('.'),match(strpart(getline(line('.')),0,col('.') - 1), + \ '\<\%(catch\|else\|finally\|for\%(\s+each\)\=\|if\|let\|try\|while\|with\)\C' . s:line_term) + 1) > -1) && + \ (expand("") =~ 'while\C' ? !s:lookForParens('\\C', '\\C','bw',100) : 1) endfunction -" Regex that defines blocks. -let s:block_regex = '[{([]' . s:line_term - let s:operator_first = s:line_pre . '\%([,:?]\|\([-/.+*]\)\%(\1\|\*\|\/\)\@!\|||\|&&\)' -let s:var_stmt = s:line_pre . '\%(const\|let\|var\)\s\+\C' - -let s:comma_last = ',' . s:line_term - -" 2. Auxiliary Functions {{{1 +" Auxiliary Functions {{{2 " ====================== " Check if the character at lnum:col is inside a string, comment, or is ascii. @@ -107,11 +82,6 @@ function s:IsInStringOrComment(lnum, col) return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_strcom endfunction -" Check if the character at lnum:col is inside a string. -function s:IsInString(lnum, col) - return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_string -endfunction - " Check if the character at lnum:col is inside a multi-line comment. function s:IsInComment(lnum, col) return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_comment @@ -121,15 +91,7 @@ endfunction function s:PrevNonBlankNonString(lnum) let lnum = prevnonblank(a:lnum) while lnum > 0 - let line = getline(lnum) - let com = match(line, '\%(\/\*.*\)\@ 0 - let lnum = parlnum - end - elseif line !~ '^' . s:line_term && !s:IsInStringOrComment(lnum,1) + if !s:IsInStringOrComment(lnum, matchend(getline(lnum), '^\s*[^''"]')) break endif let lnum = prevnonblank(lnum - 1) @@ -137,94 +99,6 @@ function s:PrevNonBlankNonString(lnum) return lnum endfunction -" Find line above 'lnum' that started the continuation 'lnum' may be part of. -function s:GetMSL(lnum, in_one_line_scope) - " Start on the line we're at and use its indent. - let msl = a:lnum - let lnum = s:PrevNonBlankNonString(a:lnum - 1) - while lnum > 0 && !s:Match(msl,s:line_pre . '[])}]') - " If we have a continuation line, or we're in a string, use line as MSL. - " Otherwise, terminate search as we have found our MSL already. - let line = getline(lnum) - let line2 = getline(msl) - if ((s:Match(lnum,s:continuation_regex) || s:Match(lnum, s:comma_last)) && - \ !s:Match(lnum, s:expr_case)) || s:IsInString(lnum, strlen(line)) - let msl = lnum - if s:Match(lnum, s:line_pre . '[]})]') && !a:in_one_line_scope - call cursor(lnum,1) - let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) - if parlnum > 0 - let lnum = parlnum - continue - end - end - - else - - " Don't use lines that are part of a one line scope as msl unless the - " flag in_one_line_scope is set to 1 - " - if a:in_one_line_scope - break - end - let msl_one_line = s:Onescope(lnum) - if msl_one_line == 0 - break - endif - end - let lnum = s:PrevNonBlankNonString(lnum - 1) - endwhile - return msl -endfunction - -function s:RemoveTrailingComments(content) - let single = '\/\/\%(.*\)\s*$' - let multi = '\/\*\%(.*\)\*\/\s*$' - return substitute(substitute(substitute(a:content, single, '', ''), multi, '', ''), '\s\+$', '', '') -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) ||(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 cont - let cont = 0 - call cursor(lnum,1) - let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) - if parlnum > 0 - let lnum = parlnum - end - end - if s:Match(lnum, s:js_keywords) - " check if the line is a var stmt - " if the line has a comma first or comma last then we can assume that we - " are in a multiple var statement - if s:Match(lnum, s:var_stmt) && (s:Match(lnum, s:comma_last)||s:Match(lnum,s:continuation_regex)) - return lnum - endif - - " other js keywords, not a var - if !s:Match(lnum, s:comma_last)||!s:Match(lnum,s:continuation_regex) - return 0 - end - endif - let lnum = s:PrevNonBlankNonString(lnum - 1) - let prev = prev && lnum > 0 ? prev : 0 - endwhile - - " beginning of program, not a var - return 0 -endfunction - " Check if line 'lnum' has more opening brackets than closing ones. function s:LineHasOpeningBrackets(lnum) let open_0 = 0 @@ -245,82 +119,14 @@ function s:LineHasOpeningBrackets(lnum) endwhile return (open_0 > 0 ? 1 : (open_0 == 0 ? 0 : 2)) . (open_2 > 0 ? 1 : (open_2 == 0 ? 0 : 2)) . (open_4 > 0 ? 1 : (open_4 == 0 ? 0 : 2)) endfunction +" }}} -function s:Match(lnum, regex) - let col = match(getline(a:lnum), a:regex) + 1 - return col > 0 && !s:IsInStringOrComment(a:lnum, col) ? col : 0 -endfunction - -function s:IndentWithContinuation(lnum, ind, width) - " Set up variables to use and search for MSL to the previous line. - let p_lnum = a:lnum - let lnum = s:GetMSL(a:lnum, 1) - let line = getline(lnum) - - " If the previous line wasn't a MSL and is continuation return its indent. - " TODO: the || s:IsInString() thing worries me a bit. - if p_lnum != lnum - if s:Match(p_lnum,s:continuation_regex)||s:IsInString(p_lnum,strlen(line)) - return a:ind - endif - endif - - " Set up more variables now that we know we aren't continuation bound. - let msl_ind = indent(lnum) - - " If the previous line ended with [*+/.-=], start a continuation that - " indents an extra level. - if s:Match(lnum, s:continuation_regex) - if lnum == p_lnum - return msl_ind + a:width - else - return msl_ind - end - elseif s:InMultiVarStatement(p_lnum, 0, s:PrevNonBlankNonString(p_lnum - 1)) - return indent(p_lnum) - s:sw() - endif - - return a:ind -endfunction - -function s:InOneLineScope(lnum) - let msl = s:GetMSL(a:lnum, 1) - if msl > 0 && s:Onescope(msl) - return msl - endif - return 0 -endfunction - -function s:ExitingOneLineScope(lnum) - let msl = s:GetMSL(a:lnum, 1) - if msl > 0 - " if the current line is in a one line scope .. - if s:Onescope(msl) - return 0 - else - let prev_msl = s:GetMSL(msl - 1, 1) - if s:Onescope(prev_msl) - return prev_msl - endif - endif - endif - return 0 -endfunction - -" 3. GetJavascriptIndent Function {{{1 +" GetJavascriptIndent Function " ========================= - function GetJavascriptIndent() - " 3.1. Setup {{{1 - " ---------- - " Set up variables for restoring position in file. Could use v:lnum here. - " Avoid use of line('.')/col('.') type functions as the curpos can change - let vcol = col('.') - - " 3.2. Work on the current line {{{1 - " ----------------------------- - - let ind = -1 + if !exists('b:js_cache') + let b:js_cache = [0,0] + end " Get the current line. let line = getline(v:lnum) " previous nonblank line number @@ -328,174 +134,78 @@ function GetJavascriptIndent() " previous line of code let lnum = s:PrevNonBlankNonString(v:lnum - 1) - " to not change multiline string values + " start with strings,comments,etc.{{{2 if line !~ '^[''"`]' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'string\|template' return -1 endif - - " If we are in a multi-line comment, cindent does the right thing. if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsInComment(v:lnum, 1) return cindent(v:lnum) endif - - " single opening bracket will assume you want a c style of indenting - if line =~ s:line_pre . '{' && !s:Match(lnum,s:block_regex) && - \ !s:Match(lnum,s:comma_last) - return cindent(v:lnum) - endif - - " cindent each line which has a switch label - if (line =~ s:expr_case) - let s:cpo_switch = &cpo - set cpo+=% - let ind = cindent(v:lnum) - let &cpo = s:cpo_switch - return ind - endif - - " If we got a closing bracket on an empty line, find its match and indent - " according to it. - let col = line =~ s:line_pre . '[]})]' - if col > 0 - let parlnum = v:lnum - while col - call cursor(parlnum, 1) - let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) - let col = s:Match(parlnum, s:line_pre . '[]})]') - if col - continue - end - if parlnum > 0 - let ind = s:InMultiVarStatement(parlnum, 0, 0)|| s:LineHasOpeningBrackets(parlnum) !~ '2' ? - \ indent(parlnum) : indent(s:GetMSL(parlnum, 0)) - endif - endwhile - return ind - endif - - - " If line starts with an operator... - if (line =~ s:operator_first) - if (s:Match(lnum, s:operator_first) || (s:Match(lnum, s:line_pre . '[])}]') && - \ !(s:Match(v:lnum,s:line_pre . '\.') && s:Match(lnum, ')' . s:line_term)))) - " and so does previous line, don't indent - return indent(lnum) - end - let counts = s:LineHasOpeningBrackets(lnum) - if counts =~ '2' - call cursor(lnum, 1) - " Search for the opening tag - let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) - if parlnum > 0 - return !s:Match(parlnum, s:operator_first) && - \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen\|jsobject' ? - \ indent(lnum) + s:sw() : indent(parlnum) - end - elseif synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen\|jsobject' - " otherwise, if not in an key/val;array item;param, indent 1 level - return indent(lnum) + s:sw() - end - - " If previous line starts with an operator... - elseif (s:Match(lnum, s:operator_first) && !s:Match(lnum,s:continuation_regex)) || - \ getline(lnum) =~ '[]})];\=' . s:line_term - let counts = s:LineHasOpeningBrackets(lnum) - if counts =~ '2' && !s:Match(lnum, s:operator_first) - call cursor(lnum, 1) - " Search for the opening tag - let mnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) - if mnum > 0 && (s:Match(mnum, s:operator_first) || - \ (s:Onescope(s:PrevNonBlankNonString(mnum - 1))) && !s:Match(mnum, s:line_pre . '{')) - return indent(mnum) - s:sw() - end - elseif s:Match(lnum, s:operator_first) - if counts !~ '1' - return indent(lnum) - s:sw() - end - end - end - - " 3.3. Work on the previous line. {{{1 - " ------------------------------- - - " If the line is empty and the previous nonblank line was a multi-line - " comment, use that comment's indent. Deduct one char to account for the - " space in ' */'. if line =~ '^\s*$' && getline(prevline) =~ '\%(\%(^\s*\/\/\|\/\*\).*\)\@= lnum && b:js_cache[0] < v:lnum && b:js_cache[0] && + \ (b:js_cache[0] > lnum || map(pcounts,'s:LineHasOpeningBrackets(lnum)')[0] !~ '2') + let num = pcounts[0] =~ '1' ? lnum : b:js_cache[1] + else + call cursor(v:lnum,1) + let syns = synIDattr(synID(v:lnum, 1, 1), 'name') + if line[1] =~ '\s' + if syns != '' + let pattern = syns =~? 'funcblock' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : syns =~? 'jsbracket'? ['\[','\]'] : + \ ['(\|{\|\[',')\|}\|\]'] + let num = s:lookForParens(pattern[0],pattern[1],'nbw',2000) + else + let num = 0 end - elseif counts =~ '1' || s:Onescope(lnum) - return ind + s:sw() + else + let num = s:lookForParens('(\|{\|\[',')\|}\|\]','nbW',2000) end end + let b:js_cache = [v:lnum, num] - " 3.4. Work on the MSL line. {{{1 - " -------------------------- - if s:Match(lnum, s:comma_last) && !s:Match(lnum, s:continuation_regex) - return s:Match(lnum, s:var_stmt) ? indent(lnum) + s:sw() : indent(lnum) - - elseif s:Match(s:PrevNonBlankNonString(lnum - 1), s:comma_last) - if !s:Match(lnum, s:comma_last) && s:InMultiVarStatement(lnum,1,0) - return indent(lnum) - s:sw() - end + " most significant part + if line =~ s:line_pre . '[])}]' + return indent(num) end - let ind_con = ind - let ind = s:IndentWithContinuation(lnum, ind_con, s:sw()) - - " }}}2 - " - " - let ols = s:InOneLineScope(lnum) - if ols > 0 - let ind = ind + s:sw() - else - let ols = s:ExitingOneLineScope(lnum) - while ols > 0 && ind > 0 - let ind = ind - s:sw() - let ols = s:InOneLineScope(ols - 1) - endwhile + let switch_offset = 0 + if synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'switch' + let num = search('\ 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset + elseif num > 0 + return indent(num) + s:sw() + switch_offset + end - return ind endfunction -" }}}1 let &cpo = s:cpo_save unlet s:cpo_save From 352bcc283c90db635321faa7ee789fd2c24327d9 Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 15 Jul 2016 01:58:44 -0700 Subject: [PATCH 15/63] try ..catch (#546) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch these need block statements --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index a6dc1a74..6b7a0b50 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -68,7 +68,7 @@ function s:Onescope(lnum) \ (cursor(a:lnum, match(getline(a:lnum),')' . s:line_term)) > -1 && \ s:lookForParens('(', ')', 'cbW', 100) > 0 && \ cursor(line('.'),match(strpart(getline(line('.')),0,col('.') - 1), - \ '\<\%(catch\|else\|finally\|for\%(\s+each\)\=\|if\|let\|try\|while\|with\)\C' . s:line_term) + 1) > -1) && + \ '\<\%(else\|for\%(\s+each\)\=\|if\|let\|while\|with\)\C' . s:line_term) + 1) > -1) && \ (expand("") =~ 'while\C' ? !s:lookForParens('\\C', '\\C','bw',100) : 1) endfunction From 25ff93778999562b69a32c092ef8f1a3beffa3ce Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Fri, 15 Jul 2016 11:03:43 -0700 Subject: [PATCH 16/63] Adding some common NodeJS globals --- syntax/javascript.vim | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index 73b00c9e..a2acaa65 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -114,6 +114,8 @@ syntax match jsSwitchColon contained /:/ skipwhite skipempty nextgro " Keywords syntax keyword jsGlobalObjects Array Boolean Date Function Iterator Number Object Symbol Map WeakMap Set RegExp String Proxy Promise Buffer ParallelArray ArrayBuffer DataView Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray JSON Math console document window Intl Collator DateTimeFormat NumberFormat +syntax keyword jsGlobalNodeObjects module exports global process +syntax match jsGlobalNodeObjects /require/ contains=jsFuncCall syntax keyword jsExceptions Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError syntax keyword jsBuiltins decodeURI decodeURIComponent encodeURI encodeURIComponent eval isFinite isNaN parseFloat parseInt uneval " DISCUSS: How imporant is this, really? Perhaps it should be linked to an error because I assume the keywords are reserved? @@ -278,7 +280,7 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsStorageClass StorageClass HiLink jsClassKeywords Structure HiLink jsThis Special - HiLink jsSuper Special + HiLink jsSuper Constant HiLink jsNan Number HiLink jsNull Type HiLink jsUndefined Type @@ -299,9 +301,10 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsSpecial Special HiLink jsTemplateVar Special HiLink jsTemplateBraces jsBraces - HiLink jsGlobalObjects Special - HiLink jsExceptions Special - HiLink jsBuiltins Special + HiLink jsGlobalObjects Constant + HiLink jsGlobalNodeObjects Constant + HiLink jsExceptions Constant + HiLink jsBuiltins Constant HiLink jsModuleKeywords Include HiLink jsModuleOperators Include HiLink jsModuleDefault Include From e41dbaaccf463dca0ea059a4b65fd6b0ad8be6b9 Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 15 Jul 2016 12:35:43 -0700 Subject: [PATCH 17/63] for 194 (#548) * for 194 --- indent/javascript.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 6b7a0b50..d2874d4d 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -135,7 +135,8 @@ function GetJavascriptIndent() let lnum = s:PrevNonBlankNonString(v:lnum - 1) " start with strings,comments,etc.{{{2 - if line !~ '^[''"`]' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'string\|template' + if (line !~ '^[''"`]' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'string\|template') || + \ (line !~ '^\s*[/*]' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'comment') return -1 endif if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsInComment(v:lnum, 1) From 2792e632433cff574805cc5f6998cdbc1bc0c75b Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 15 Jul 2016 22:08:56 -0700 Subject: [PATCH 18/63] switch offset always calculated when inside switch --- indent/javascript.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index d2874d4d..d6c163f5 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -189,10 +189,10 @@ function GetJavascriptIndent() return indent(num) end let switch_offset = 0 - if synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'switch' - let num = search('\ -1 + let bnum = search('\ Date: Fri, 15 Jul 2016 22:34:06 -0700 Subject: [PATCH 19/63] 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 d6c163f5..18fe546f 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -157,7 +157,7 @@ function GetJavascriptIndent() set cpo+=% let ind = cindent(v:lnum) let &cpo = s:cpo_switch - let b:js_cache = [v:lnum, search('\ Date: Fri, 15 Jul 2016 22:47:38 -0700 Subject: [PATCH 20/63] Update javascript.vim --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 18fe546f..0c24d937 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -157,7 +157,7 @@ function GetJavascriptIndent() set cpo+=% let ind = cindent(v:lnum) let &cpo = s:cpo_switch - let b:js_cache[1] = search('\ Date: Sat, 16 Jul 2016 12:05:10 -0700 Subject: [PATCH 21/63] possible indent revert(dev branch) (#550) I want to include whatever improvements made in the refactor attempt though --- indent/javascript.vim | 424 +++++++++++++++++++++++++++++++++++------- 1 file changed, 356 insertions(+), 68 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index d2874d4d..d2911c5b 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -2,6 +2,9 @@ " Language: Javascript " Acknowledgement: Based off of vim-ruby maintained by Nikolai Weibull http://vim-ruby.rubyforge.org +" 0. Initialization {{{1 +" ================= + " Only load this indent file when no other was loaded. if exists("b:did_indent") finish @@ -13,11 +16,9 @@ setlocal nosmartindent " Now, set up our indentation expression and keys that trigger it. setlocal indentexpr=GetJavascriptIndent() setlocal formatexpr=Fixedgq(v:lnum,v:count) -setlocal indentkeys=0{,0},0),0],:,!^F,o,O,e +setlocal indentkeys=0{,0},0),0],0\,*,:,!^F,o,O,e setlocal cinoptions+=j1,J1,c1 -let b:undo_indent = 'setlocal smartindent< indentexpr< formatexpr< indentkeys< cinoptions<' - " Only define the function once. if exists("*GetJavascriptIndent") finish @@ -37,44 +38,66 @@ else endfunc endif +" 1. Variables {{{1 +" ============ + let s:line_pre = '^\s*\%(\/\*.*\*\/\s*\)*' +let s:js_keywords = s:line_pre . '\%(break\|import\|export\|catch\|const\|continue\|debugger\|delete\|do\|else\|finally\|for\|function\|if\|in\|instanceof\|let\|new\|return\|switch\|this\|throw\|try\|typeof\|var\|void\|while\|with\)\>\C' let s:expr_case = s:line_pre . '\%(\%(case\>.*\)\|default\)\s*:\C' " Regex of syntax group names that are or delimit string or are comments. let s:syng_strcom = '\%(string\|regex\|special\|doc\|comment\|template\)\c' +" Regex of syntax group names that are strings. +let s:syng_string = 'regex\c' + " Regex of syntax group names that are strings or documentation. let s:syng_comment = '\%(comment\|doc\)\c' " Expression used to check whether we should skip a match with searchpair(). let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'" -func s:lookForParens(start,end,flags,time) +func s:lookForParens(start,end,flags,stop) try - return searchpair(a:start,'',a:end,a:flags, - \ "line('.') < " . (prevnonblank(v:lnum) - 2000) . " ? dummy :" . s:skip_expr - \ ,0,a:time) + return searchpair(a:start,'',a:end,a:flags,s:skip_expr,a:stop,300) catch /E118/ - return searchpair(a:start,'',a:end,a:flags,0,0) + return searchpair(a:start,'',a:end,a:flags,0,a:stop) endtry endfunc -let s:line_term = '\s*\%(\%(:\@\|=>\)\C' . s:line_term function s:Onescope(lnum) - return getline(a:lnum) =~ '\%(\\)\C' . s:line_term || - \ (cursor(a:lnum, match(getline(a:lnum),')' . s:line_term)) > -1 && - \ s:lookForParens('(', ')', 'cbW', 100) > 0 && - \ cursor(line('.'),match(strpart(getline(line('.')),0,col('.') - 1), - \ '\<\%(else\|for\%(\s+each\)\=\|if\|let\|while\|with\)\C' . s:line_term) + 1) > -1) && - \ (expand("") =~ 'while\C' ? !s:lookForParens('\\C', '\\C','bw',100) : 1) + if getline(a:lnum) =~ s:one_line_scope_regex + return 1 + end + let mypos = col('.') + call cursor(a:lnum, 1) + if search('.*\zs\<\%(while\|for\|if\)\>\s*(\C', 'ce', a:lnum) > 0 && + \ s:lookForParens('(', ')', 'W', a:lnum) > 0 && + \ col('.') == strlen(s:RemoveTrailingComments(getline(a:lnum))) + call cursor(a:lnum, mypos) + return 1 + else + call cursor(a:lnum, mypos) + return 0 + end endfunction +" Regex that defines blocks. +let s:block_regex = '[{([]' . s:line_term + let s:operator_first = s:line_pre . '\%([,:?]\|\([-/.+*]\)\%(\1\|\*\|\/\)\@!\|||\|&&\)' -" Auxiliary Functions {{{2 +let s:var_stmt = s:line_pre . '\%(const\|let\|var\)\s\+\C' + +let s:comma_last = ',' . s:line_term + +" 2. Auxiliary Functions {{{1 " ====================== " Check if the character at lnum:col is inside a string, comment, or is ascii. @@ -82,6 +105,11 @@ function s:IsInStringOrComment(lnum, col) return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_strcom endfunction +" Check if the character at lnum:col is inside a string. +function s:IsInString(lnum, col) + return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_string +endfunction + " Check if the character at lnum:col is inside a multi-line comment. function s:IsInComment(lnum, col) return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_comment @@ -91,7 +119,15 @@ endfunction function s:PrevNonBlankNonString(lnum) let lnum = prevnonblank(a:lnum) while lnum > 0 - if !s:IsInStringOrComment(lnum, matchend(getline(lnum), '^\s*[^''"]')) + let line = getline(lnum) + let com = match(line, '\%(\/\*.*\)\@ 0 + let lnum = parlnum + end + elseif line !~ '^' . s:line_term && !s:IsInStringOrComment(lnum,1) break endif let lnum = prevnonblank(lnum - 1) @@ -99,6 +135,94 @@ function s:PrevNonBlankNonString(lnum) return lnum endfunction +" Find line above 'lnum' that started the continuation 'lnum' may be part of. +function s:GetMSL(lnum, in_one_line_scope) + " Start on the line we're at and use its indent. + let msl = a:lnum + let lnum = s:PrevNonBlankNonString(a:lnum - 1) + while lnum > 0 && !s:Match(msl,s:line_pre . '[])}]') + " If we have a continuation line, or we're in a string, use line as MSL. + " Otherwise, terminate search as we have found our MSL already. + let line = getline(lnum) + let line2 = getline(msl) + if ((s:Match(lnum,s:continuation_regex) || s:Match(lnum, s:comma_last)) && + \ !s:Match(lnum, s:expr_case)) || s:IsInString(lnum, strlen(line)) + let msl = lnum + if s:Match(lnum, s:line_pre . '[]})]') && !a:in_one_line_scope + call cursor(lnum,1) + let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) + if parlnum > 0 + let lnum = parlnum + continue + end + end + + else + + " Don't use lines that are part of a one line scope as msl unless the + " flag in_one_line_scope is set to 1 + " + if a:in_one_line_scope + break + end + let msl_one_line = s:Onescope(lnum) + if msl_one_line == 0 + break + endif + end + let lnum = s:PrevNonBlankNonString(lnum - 1) + endwhile + return msl +endfunction + +function s:RemoveTrailingComments(content) + let single = '\/\/\%(.*\)\s*$' + let multi = '\/\*\%(.*\)\*\/\s*$' + return substitute(substitute(substitute(a:content, single, '', ''), multi, '', ''), '\s\+$', '', '') +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) ||(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 cont + let cont = 0 + call cursor(lnum,1) + let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) + if parlnum > 0 + let lnum = parlnum + end + end + if s:Match(lnum, s:js_keywords) + " check if the line is a var stmt + " if the line has a comma first or comma last then we can assume that we + " are in a multiple var statement + if s:Match(lnum, s:var_stmt) && (s:Match(lnum, s:comma_last)||s:Match(lnum,s:continuation_regex)) + return lnum + endif + + " other js keywords, not a var + if !s:Match(lnum, s:comma_last)||!s:Match(lnum,s:continuation_regex) + return 0 + end + endif + let lnum = s:PrevNonBlankNonString(lnum - 1) + let prev = prev && lnum > 0 ? prev : 0 + endwhile + + " beginning of program, not a var + return 0 +endfunction + " Check if line 'lnum' has more opening brackets than closing ones. function s:LineHasOpeningBrackets(lnum) let open_0 = 0 @@ -119,14 +243,82 @@ function s:LineHasOpeningBrackets(lnum) endwhile return (open_0 > 0 ? 1 : (open_0 == 0 ? 0 : 2)) . (open_2 > 0 ? 1 : (open_2 == 0 ? 0 : 2)) . (open_4 > 0 ? 1 : (open_4 == 0 ? 0 : 2)) endfunction -" }}} -" GetJavascriptIndent Function +function s:Match(lnum, regex) + let col = match(getline(a:lnum), a:regex) + 1 + return col > 0 && !s:IsInStringOrComment(a:lnum, col) ? col : 0 +endfunction + +function s:IndentWithContinuation(lnum, ind, width) + " Set up variables to use and search for MSL to the previous line. + let p_lnum = a:lnum + let lnum = s:GetMSL(a:lnum, 1) + let line = getline(lnum) + + " If the previous line wasn't a MSL and is continuation return its indent. + " TODO: the || s:IsInString() thing worries me a bit. + if p_lnum != lnum + if s:Match(p_lnum,s:continuation_regex)||s:IsInString(p_lnum,strlen(line)) + return a:ind + endif + endif + + " Set up more variables now that we know we aren't continuation bound. + let msl_ind = indent(lnum) + + " If the previous line ended with [*+/.-=], start a continuation that + " indents an extra level. + if s:Match(lnum, s:continuation_regex) + if lnum == p_lnum + return msl_ind + a:width + else + return msl_ind + end + elseif s:InMultiVarStatement(p_lnum, 0, s:PrevNonBlankNonString(p_lnum - 1)) + return indent(p_lnum) - s:sw() + endif + + return a:ind +endfunction + +function s:InOneLineScope(lnum) + let msl = s:GetMSL(a:lnum, 1) + if msl > 0 && s:Onescope(msl) + return msl + endif + return 0 +endfunction + +function s:ExitingOneLineScope(lnum) + let msl = s:GetMSL(a:lnum, 1) + if msl > 0 + " if the current line is in a one line scope .. + if s:Onescope(msl) + return 0 + else + let prev_msl = s:GetMSL(msl - 1, 1) + if s:Onescope(prev_msl) + return prev_msl + endif + endif + endif + return 0 +endfunction + +" 3. GetJavascriptIndent Function {{{1 " ========================= + function GetJavascriptIndent() - if !exists('b:js_cache') - let b:js_cache = [0,0] - end + " 3.1. Setup {{{1 + " ---------- + " Set up variables for restoring position in file. Could use v:lnum here. + " Avoid use of line('.')/col('.') type functions as the curpos can change + let vcol = col('.') + + " 3.2. Work on the current line {{{1 + " ----------------------------- + + let ind = -1 " Get the current line. let line = getline(v:lnum) " previous nonblank line number @@ -134,79 +326,175 @@ function GetJavascriptIndent() " previous line of code let lnum = s:PrevNonBlankNonString(v:lnum - 1) - " start with strings,comments,etc.{{{2 + " to not change multiline string values if (line !~ '^[''"`]' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'string\|template') || \ (line !~ '^\s*[/*]' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'comment') return -1 endif + + " If we are in a multi-line comment, cindent does the right thing. if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsInComment(v:lnum, 1) return cindent(v:lnum) endif + + " single opening bracket will assume you want a c style of indenting + if line =~ s:line_pre . '{' && !s:Match(lnum,s:block_regex) && + \ !s:Match(lnum,s:comma_last) + return cindent(v:lnum) + endif + + " cindent each line which has a switch label + if (line =~ s:expr_case) + let s:cpo_switch = &cpo + set cpo+=% + let ind = cindent(v:lnum) + let &cpo = s:cpo_switch + return ind + endif + + " If we got a closing bracket on an empty line, find its match and indent + " according to it. + let col = line =~ s:line_pre . '[]})]' + if col > 0 + let parlnum = v:lnum + while col + call cursor(parlnum, 1) + let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) + let col = s:Match(parlnum, s:line_pre . '[]})]') + if col + continue + end + if parlnum > 0 + let ind = s:InMultiVarStatement(parlnum, 0, 0)|| s:LineHasOpeningBrackets(parlnum) !~ '2' ? + \ indent(parlnum) : indent(s:GetMSL(parlnum, 0)) + endif + endwhile + return ind + endif + + + " If line starts with an operator... + if (line =~ s:operator_first) + if (s:Match(lnum, s:operator_first) || (s:Match(lnum, s:line_pre . '[])}]') && + \ !(s:Match(v:lnum,s:line_pre . '\.') && s:Match(lnum, ')' . s:line_term)))) + " and so does previous line, don't indent + return indent(lnum) + end + let counts = s:LineHasOpeningBrackets(lnum) + if counts =~ '2' + call cursor(lnum, 1) + " Search for the opening tag + let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) + if parlnum > 0 + return !s:Match(parlnum, s:operator_first) && + \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen\|jsobject' ? + \ indent(lnum) + s:sw() : indent(parlnum) + end + elseif synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen\|jsobject' + " otherwise, if not in an key/val;array item;param, indent 1 level + return indent(lnum) + s:sw() + end + + " If previous line starts with an operator... + elseif (s:Match(lnum, s:operator_first) && !s:Match(lnum,s:continuation_regex)) || + \ getline(lnum) =~ '[]})];\=' . s:line_term + let counts = s:LineHasOpeningBrackets(lnum) + if counts =~ '2' && !s:Match(lnum, s:operator_first) + call cursor(lnum, 1) + " Search for the opening tag + let mnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) + if mnum > 0 && (s:Match(mnum, s:operator_first) || + \ (s:Onescope(s:PrevNonBlankNonString(mnum - 1))) && !s:Match(mnum, s:line_pre . '{')) + return indent(mnum) - s:sw() + end + elseif s:Match(lnum, s:operator_first) + if counts !~ '1' + return indent(lnum) - s:sw() + end + end + end + + " 3.3. Work on the previous line. {{{1 + " ------------------------------- + + " If the line is empty and the previous nonblank line was a multi-line + " comment, use that comment's indent. Deduct one char to account for the + " space in ' */'. if line =~ '^\s*$' && getline(prevline) =~ '\%(\%(^\s*\/\/\|\/\*\).*\)\@= lnum && b:js_cache[0] < v:lnum && b:js_cache[0] && - \ (b:js_cache[0] > lnum || map(pcounts,'s:LineHasOpeningBrackets(lnum)')[0] !~ '2') - let num = pcounts[0] =~ '1' ? lnum : b:js_cache[1] - else - call cursor(v:lnum,1) - let syns = synIDattr(synID(v:lnum, 1, 1), 'name') - if line[1] =~ '\s' - if syns != '' - let pattern = syns =~? 'funcblock' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : syns =~? 'jsbracket'? ['\[','\]'] : - \ ['(\|{\|\[',')\|}\|\]'] - let num = s:lookForParens(pattern[0],pattern[1],'nbw',2000) - else - let num = 0 + " Set up variables for current line. + let line = getline(lnum) + let ind = indent(lnum) + " If the previous line contained an opening bracket, and we are still in it, + " add indent depending on the bracket type. + if s:Match(lnum, '[[({})\]]') + let counts = s:LineHasOpeningBrackets(lnum) + if counts =~ '2' + call cursor(lnum,matchend(s:RemoveTrailingComments(line), '.*\zs[])}]')) + while s:lookForParens('(\|{\|\[', ')\|}\|\]', 'bW', 0) == lnum + call cursor(lnum, matchend(s:RemoveTrailingComments(strpart(line,0,col('.'))), '.*\zs[])}]')) + endwhile + let cur = line('.') + if cur < lnum && !s:InMultiVarStatement(cur,0,0) + return indent(s:GetMSL(cur, 0)) end - else - let num = s:lookForParens('(\|{\|\[',')\|}\|\]','nbW',2000) + elseif counts =~ '1' || s:Onescope(lnum) + return ind + s:sw() end end - let b:js_cache = [v:lnum, num] - " most significant part - if line =~ s:line_pre . '[])}]' - return indent(num) + " 3.4. Work on the MSL line. {{{1 + " -------------------------- + if s:Match(lnum, s:comma_last) && !s:Match(lnum, s:continuation_regex) + return s:Match(lnum, s:var_stmt) ? indent(lnum) + s:sw() : indent(lnum) + + elseif s:Match(s:PrevNonBlankNonString(lnum - 1), s:comma_last) + if !s:Match(lnum, s:comma_last) && s:InMultiVarStatement(lnum,1,0) + return indent(lnum) - s:sw() + end end - let switch_offset = 0 - if synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'switch' - let num = search('\ 0 + let ind = ind + s:sw() + else + let ols = s:ExitingOneLineScope(lnum) + while ols > 0 && ind > 0 + let ind = ind - s:sw() + let ols = s:InOneLineScope(ols - 1) + endwhile endif - if (line =~ s:operator_first || - \ (getline(lnum) =~ s:continuation_regex && getline(lnum) !~ s:expr_case) || - \ (s:Onescope(lnum) && line !~ s:line_pre . '{')) && - \ (num != lnum && - \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsdestructuringblock\|args\|jsbracket\|jsparen\|jsobject') - return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset - elseif num > 0 - return indent(num) + s:sw() + switch_offset - end + return ind endfunction +" }}}1 let &cpo = s:cpo_save unlet s:cpo_save From 1c9a3dc4f058642c8c167293dc4d753d9f505a60 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 16 Jul 2016 12:07:02 -0700 Subject: [PATCH 22/63] undo_indent missed this --- indent/javascript.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/indent/javascript.vim b/indent/javascript.vim index d2911c5b..d9a194c6 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -19,6 +19,8 @@ setlocal formatexpr=Fixedgq(v:lnum,v:count) setlocal indentkeys=0{,0},0),0],0\,*,:,!^F,o,O,e setlocal cinoptions+=j1,J1,c1 +let b:undo_indent = 'setlocal smartindent< indentexpr< formatexpr< indentkeys< cinoptions<' + " Only define the function once. if exists("*GetJavascriptIndent") finish From 2efcfa3abd12b9b21f053d3c20eadd6e0755b8c1 Mon Sep 17 00:00:00 2001 From: Dmitri Vereshchagin Date: Sun, 17 Jul 2016 05:49:14 +0400 Subject: [PATCH 23/63] Remove 'smartindent' from indent plugin (#551) When 'indentexpr' is set, setting 'smartindent' has no effect. --- indent/javascript.vim | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index d9a194c6..d5375d9e 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -11,15 +11,13 @@ if exists("b:did_indent") endif let b:did_indent = 1 -setlocal nosmartindent - " Now, set up our indentation expression and keys that trigger it. setlocal indentexpr=GetJavascriptIndent() setlocal formatexpr=Fixedgq(v:lnum,v:count) setlocal indentkeys=0{,0},0),0],0\,*,:,!^F,o,O,e setlocal cinoptions+=j1,J1,c1 -let b:undo_indent = 'setlocal smartindent< indentexpr< formatexpr< indentkeys< cinoptions<' +let b:undo_indent = 'setlocal indentexpr< formatexpr< indentkeys< cinoptions<' " Only define the function once. if exists("*GetJavascriptIndent") From 6f82a0cec6cca718766dd88161aa62a48d35e309 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sun, 17 Jul 2016 00:25:11 -0700 Subject: [PATCH 24/63] Re revert (#554) * Revert "possible indent revert(dev branch) (#550)" This reverts commit b884680566628d85265a174f6339ca36825cb829. * fixed major issue * try ..catch and timeout --- indent/javascript.vim | 422 +++++++----------------------------------- 1 file changed, 66 insertions(+), 356 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index d5375d9e..7bd4aef2 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -2,9 +2,6 @@ " Language: Javascript " Acknowledgement: Based off of vim-ruby maintained by Nikolai Weibull http://vim-ruby.rubyforge.org -" 0. Initialization {{{1 -" ================= - " Only load this indent file when no other was loaded. if exists("b:did_indent") finish @@ -14,7 +11,7 @@ let b:did_indent = 1 " Now, set up our indentation expression and keys that trigger it. setlocal indentexpr=GetJavascriptIndent() setlocal formatexpr=Fixedgq(v:lnum,v:count) -setlocal indentkeys=0{,0},0),0],0\,*,:,!^F,o,O,e +setlocal indentkeys=0{,0},0),0],:,!^F,o,O,e setlocal cinoptions+=j1,J1,c1 let b:undo_indent = 'setlocal indentexpr< formatexpr< indentkeys< cinoptions<' @@ -38,66 +35,44 @@ else endfunc endif -" 1. Variables {{{1 -" ============ - let s:line_pre = '^\s*\%(\/\*.*\*\/\s*\)*' -let s:js_keywords = s:line_pre . '\%(break\|import\|export\|catch\|const\|continue\|debugger\|delete\|do\|else\|finally\|for\|function\|if\|in\|instanceof\|let\|new\|return\|switch\|this\|throw\|try\|typeof\|var\|void\|while\|with\)\>\C' let s:expr_case = s:line_pre . '\%(\%(case\>.*\)\|default\)\s*:\C' " Regex of syntax group names that are or delimit string or are comments. let s:syng_strcom = '\%(string\|regex\|special\|doc\|comment\|template\)\c' -" Regex of syntax group names that are strings. -let s:syng_string = 'regex\c' - " Regex of syntax group names that are strings or documentation. let s:syng_comment = '\%(comment\|doc\)\c' " Expression used to check whether we should skip a match with searchpair(). let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'" -func s:lookForParens(start,end,flags,stop) +func s:lookForParens(start,end,flags,time) try - return searchpair(a:start,'',a:end,a:flags,s:skip_expr,a:stop,300) + return searchpair(a:start,'',a:end,a:flags, + \ "line('.') < " . (prevnonblank(v:lnum) - 2000) . " ? dummy :" . s:skip_expr + \ ,0,a:time) catch /E118/ - return searchpair(a:start,'',a:end,a:flags,0,a:stop) + return searchpair(a:start,'',a:end,a:flags,0,0) endtry endfunc -let s:line_term = '\s*\%(\%(\/\/.*\)\=\|\%(\/\*.*\*\/\s*\)*\)$' +let s:line_term = '\s*\%(\%(:\@\|=>\)\C' . s:line_term +let s:continuation_regex = '\%([*,.?:]\|+\@\s*(\C', 'ce', a:lnum) > 0 && - \ s:lookForParens('(', ')', 'W', a:lnum) > 0 && - \ col('.') == strlen(s:RemoveTrailingComments(getline(a:lnum))) - call cursor(a:lnum, mypos) - return 1 - else - call cursor(a:lnum, mypos) - return 0 - end + return getline(a:lnum) =~ '\%(\\)\C' . s:line_term || + \ (cursor(a:lnum, match(getline(a:lnum),')' . s:line_term)) > -1 && + \ s:lookForParens('(', ')', 'cbW', 100) > 0 && + \ cursor(line('.'),match( ' ' . strpart(getline(line('.')),0,col('.') - 1), + \ '\<\%(else\|for\%(\s+each\)\=\|if\|let\|while\|with\)\C' . s:line_term)) > -1) && + \ (expand("") =~ 'while\C' ? !s:lookForParens('\\C', '\\C','bw',100) : 1) endfunction -" Regex that defines blocks. -let s:block_regex = '[{([]' . s:line_term - let s:operator_first = s:line_pre . '\%([,:?]\|\([-/.+*]\)\%(\1\|\*\|\/\)\@!\|||\|&&\)' -let s:var_stmt = s:line_pre . '\%(const\|let\|var\)\s\+\C' - -let s:comma_last = ',' . s:line_term - -" 2. Auxiliary Functions {{{1 +" Auxiliary Functions {{{2 " ====================== " Check if the character at lnum:col is inside a string, comment, or is ascii. @@ -105,11 +80,6 @@ function s:IsInStringOrComment(lnum, col) return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_strcom endfunction -" Check if the character at lnum:col is inside a string. -function s:IsInString(lnum, col) - return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_string -endfunction - " Check if the character at lnum:col is inside a multi-line comment. function s:IsInComment(lnum, col) return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_comment @@ -119,15 +89,7 @@ endfunction function s:PrevNonBlankNonString(lnum) let lnum = prevnonblank(a:lnum) while lnum > 0 - let line = getline(lnum) - let com = match(line, '\%(\/\*.*\)\@ 0 - let lnum = parlnum - end - elseif line !~ '^' . s:line_term && !s:IsInStringOrComment(lnum,1) + if !s:IsInStringOrComment(lnum, matchend(getline(lnum), '^\s*[^''"]')) break endif let lnum = prevnonblank(lnum - 1) @@ -135,94 +97,6 @@ function s:PrevNonBlankNonString(lnum) return lnum endfunction -" Find line above 'lnum' that started the continuation 'lnum' may be part of. -function s:GetMSL(lnum, in_one_line_scope) - " Start on the line we're at and use its indent. - let msl = a:lnum - let lnum = s:PrevNonBlankNonString(a:lnum - 1) - while lnum > 0 && !s:Match(msl,s:line_pre . '[])}]') - " If we have a continuation line, or we're in a string, use line as MSL. - " Otherwise, terminate search as we have found our MSL already. - let line = getline(lnum) - let line2 = getline(msl) - if ((s:Match(lnum,s:continuation_regex) || s:Match(lnum, s:comma_last)) && - \ !s:Match(lnum, s:expr_case)) || s:IsInString(lnum, strlen(line)) - let msl = lnum - if s:Match(lnum, s:line_pre . '[]})]') && !a:in_one_line_scope - call cursor(lnum,1) - let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) - if parlnum > 0 - let lnum = parlnum - continue - end - end - - else - - " Don't use lines that are part of a one line scope as msl unless the - " flag in_one_line_scope is set to 1 - " - if a:in_one_line_scope - break - end - let msl_one_line = s:Onescope(lnum) - if msl_one_line == 0 - break - endif - end - let lnum = s:PrevNonBlankNonString(lnum - 1) - endwhile - return msl -endfunction - -function s:RemoveTrailingComments(content) - let single = '\/\/\%(.*\)\s*$' - let multi = '\/\*\%(.*\)\*\/\s*$' - return substitute(substitute(substitute(a:content, single, '', ''), multi, '', ''), '\s\+$', '', '') -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) ||(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 cont - let cont = 0 - call cursor(lnum,1) - let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) - if parlnum > 0 - let lnum = parlnum - end - end - if s:Match(lnum, s:js_keywords) - " check if the line is a var stmt - " if the line has a comma first or comma last then we can assume that we - " are in a multiple var statement - if s:Match(lnum, s:var_stmt) && (s:Match(lnum, s:comma_last)||s:Match(lnum,s:continuation_regex)) - return lnum - endif - - " other js keywords, not a var - if !s:Match(lnum, s:comma_last)||!s:Match(lnum,s:continuation_regex) - return 0 - end - endif - let lnum = s:PrevNonBlankNonString(lnum - 1) - let prev = prev && lnum > 0 ? prev : 0 - endwhile - - " beginning of program, not a var - return 0 -endfunction - " Check if line 'lnum' has more opening brackets than closing ones. function s:LineHasOpeningBrackets(lnum) let open_0 = 0 @@ -243,82 +117,14 @@ function s:LineHasOpeningBrackets(lnum) endwhile return (open_0 > 0 ? 1 : (open_0 == 0 ? 0 : 2)) . (open_2 > 0 ? 1 : (open_2 == 0 ? 0 : 2)) . (open_4 > 0 ? 1 : (open_4 == 0 ? 0 : 2)) endfunction +" }}} -function s:Match(lnum, regex) - let col = match(getline(a:lnum), a:regex) + 1 - return col > 0 && !s:IsInStringOrComment(a:lnum, col) ? col : 0 -endfunction - -function s:IndentWithContinuation(lnum, ind, width) - " Set up variables to use and search for MSL to the previous line. - let p_lnum = a:lnum - let lnum = s:GetMSL(a:lnum, 1) - let line = getline(lnum) - - " If the previous line wasn't a MSL and is continuation return its indent. - " TODO: the || s:IsInString() thing worries me a bit. - if p_lnum != lnum - if s:Match(p_lnum,s:continuation_regex)||s:IsInString(p_lnum,strlen(line)) - return a:ind - endif - endif - - " Set up more variables now that we know we aren't continuation bound. - let msl_ind = indent(lnum) - - " If the previous line ended with [*+/.-=], start a continuation that - " indents an extra level. - if s:Match(lnum, s:continuation_regex) - if lnum == p_lnum - return msl_ind + a:width - else - return msl_ind - end - elseif s:InMultiVarStatement(p_lnum, 0, s:PrevNonBlankNonString(p_lnum - 1)) - return indent(p_lnum) - s:sw() - endif - - return a:ind -endfunction - -function s:InOneLineScope(lnum) - let msl = s:GetMSL(a:lnum, 1) - if msl > 0 && s:Onescope(msl) - return msl - endif - return 0 -endfunction - -function s:ExitingOneLineScope(lnum) - let msl = s:GetMSL(a:lnum, 1) - if msl > 0 - " if the current line is in a one line scope .. - if s:Onescope(msl) - return 0 - else - let prev_msl = s:GetMSL(msl - 1, 1) - if s:Onescope(prev_msl) - return prev_msl - endif - endif - endif - return 0 -endfunction - -" 3. GetJavascriptIndent Function {{{1 +" GetJavascriptIndent Function " ========================= - function GetJavascriptIndent() - " 3.1. Setup {{{1 - " ---------- - " Set up variables for restoring position in file. Could use v:lnum here. - " Avoid use of line('.')/col('.') type functions as the curpos can change - let vcol = col('.') - - " 3.2. Work on the current line {{{1 - " ----------------------------- - - let ind = -1 + if !exists('b:js_cache') + let b:js_cache = [0,0] + end " Get the current line. let line = getline(v:lnum) " previous nonblank line number @@ -326,175 +132,79 @@ function GetJavascriptIndent() " previous line of code let lnum = s:PrevNonBlankNonString(v:lnum - 1) - " to not change multiline string values + " start with strings,comments,etc.{{{2 if (line !~ '^[''"`]' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'string\|template') || \ (line !~ '^\s*[/*]' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'comment') return -1 endif - - " If we are in a multi-line comment, cindent does the right thing. if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsInComment(v:lnum, 1) return cindent(v:lnum) endif - - " single opening bracket will assume you want a c style of indenting - if line =~ s:line_pre . '{' && !s:Match(lnum,s:block_regex) && - \ !s:Match(lnum,s:comma_last) - return cindent(v:lnum) - endif - - " cindent each line which has a switch label - if (line =~ s:expr_case) - let s:cpo_switch = &cpo - set cpo+=% - let ind = cindent(v:lnum) - let &cpo = s:cpo_switch - return ind - endif - - " If we got a closing bracket on an empty line, find its match and indent - " according to it. - let col = line =~ s:line_pre . '[]})]' - if col > 0 - let parlnum = v:lnum - while col - call cursor(parlnum, 1) - let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) - let col = s:Match(parlnum, s:line_pre . '[]})]') - if col - continue - end - if parlnum > 0 - let ind = s:InMultiVarStatement(parlnum, 0, 0)|| s:LineHasOpeningBrackets(parlnum) !~ '2' ? - \ indent(parlnum) : indent(s:GetMSL(parlnum, 0)) - endif - endwhile - return ind - endif - - - " If line starts with an operator... - if (line =~ s:operator_first) - if (s:Match(lnum, s:operator_first) || (s:Match(lnum, s:line_pre . '[])}]') && - \ !(s:Match(v:lnum,s:line_pre . '\.') && s:Match(lnum, ')' . s:line_term)))) - " and so does previous line, don't indent - return indent(lnum) - end - let counts = s:LineHasOpeningBrackets(lnum) - if counts =~ '2' - call cursor(lnum, 1) - " Search for the opening tag - let parlnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) - if parlnum > 0 - return !s:Match(parlnum, s:operator_first) && - \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen\|jsobject' ? - \ indent(lnum) + s:sw() : indent(parlnum) - end - elseif synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsbracket\|jsparen\|jsobject' - " otherwise, if not in an key/val;array item;param, indent 1 level - return indent(lnum) + s:sw() - end - - " If previous line starts with an operator... - elseif (s:Match(lnum, s:operator_first) && !s:Match(lnum,s:continuation_regex)) || - \ getline(lnum) =~ '[]})];\=' . s:line_term - let counts = s:LineHasOpeningBrackets(lnum) - if counts =~ '2' && !s:Match(lnum, s:operator_first) - call cursor(lnum, 1) - " Search for the opening tag - let mnum = s:lookForParens('(\|{\|\[', ')\|}\|\]', 'nbW', 0) - if mnum > 0 && (s:Match(mnum, s:operator_first) || - \ (s:Onescope(s:PrevNonBlankNonString(mnum - 1))) && !s:Match(mnum, s:line_pre . '{')) - return indent(mnum) - s:sw() - end - elseif s:Match(lnum, s:operator_first) - if counts !~ '1' - return indent(lnum) - s:sw() - end - end - end - - " 3.3. Work on the previous line. {{{1 - " ------------------------------- - - " If the line is empty and the previous nonblank line was a multi-line - " comment, use that comment's indent. Deduct one char to account for the - " space in ' */'. if line =~ '^\s*$' && getline(prevline) =~ '\%(\%(^\s*\/\/\|\/\*\).*\)\@= lnum && b:js_cache[0] < v:lnum && b:js_cache[0] && + \ (b:js_cache[0] > lnum || map(pcounts,'s:LineHasOpeningBrackets(lnum)')[0] !~ '2') + let num = pcounts[0] =~ '1' ? lnum : b:js_cache[1] + else + call cursor(v:lnum,1) + let syns = synIDattr(synID(v:lnum, 1, 1), 'name') + if line[1] =~ '\s' + if syns != '' + let pattern = syns =~? 'funcblock' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : syns =~? 'jsbracket'? ['\[','\]'] : + \ ['(\|{\|\[',')\|}\|\]'] + let num = s:lookForParens(pattern[0],pattern[1],'nbw',2000) + else + let num = 0 end - elseif counts =~ '1' || s:Onescope(lnum) - return ind + s:sw() + else + let num = s:lookForParens('(\|{\|\[',')\|}\|\]','nbW',2000) end end + let b:js_cache = [v:lnum, num] - " 3.4. Work on the MSL line. {{{1 - " -------------------------- - if s:Match(lnum, s:comma_last) && !s:Match(lnum, s:continuation_regex) - return s:Match(lnum, s:var_stmt) ? indent(lnum) + s:sw() : indent(lnum) - - elseif s:Match(s:PrevNonBlankNonString(lnum - 1), s:comma_last) - if !s:Match(lnum, s:comma_last) && s:InMultiVarStatement(lnum,1,0) - return indent(lnum) - s:sw() - end + " most significant part + if line =~ s:line_pre . '[])}]' + return indent(num) end - let ind_con = ind - let ind = s:IndentWithContinuation(lnum, ind_con, s:sw()) - - " }}}2 - " - " - let ols = s:InOneLineScope(lnum) - if ols > 0 - let ind = ind + s:sw() - else - let ols = s:ExitingOneLineScope(lnum) - while ols > 0 && ind > 0 - let ind = ind - s:sw() - let ols = s:InOneLineScope(ols - 1) - endwhile + let switch_offset = 0 + if synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'switch' + let num = search('\ 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset + elseif num > 0 + return indent(num) + s:sw() + switch_offset + end - return ind endfunction -" }}}1 let &cpo = s:cpo_save unlet s:cpo_save From c2b7c0550be2d1c6b6d79b23cb54edf4d691bf34 Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Sun, 17 Jul 2016 17:09:34 -0700 Subject: [PATCH 25/63] JS Flow refactor This commit rehauls a bunch of the JS Flow features. While still not feature complete, a lot of weird edge cases should now not destroy an entire file, like it used too. --- extras/flow.vim | 85 +++++++++++++++++++++++++++++-------------- syntax/javascript.vim | 17 +++++---- 2 files changed, 67 insertions(+), 35 deletions(-) diff --git a/extras/flow.vim b/extras/flow.vim index 759d7548..fc36fdbb 100644 --- a/extras/flow.vim +++ b/extras/flow.vim @@ -1,21 +1,41 @@ -syntax region jsFlowTypeStatement start=/type/ end=/=/ oneline skipwhite skipempty nextgroup=jsFlowTypeObject -syntax region jsFlowDeclareBlock start=/declare/ end=/[;\n]/ oneline contains=jsFlow,jsFlowDeclareKeyword,jsFlowStorageClass -syntax region jsFlow start=/:/ end=/\%(\%([),=;\n]\|{\%(.*}\)\@!\|\%({.*}\)\@<=\s*{\)\@=\|void\)/ contains=@jsFlowCluster containedin=jsBlock,jsClassBlock,jsFuncBlock,jsBlock,jsTryCatchBlock,jsSwitchBlock,jsParen oneline skipwhite skipempty nextgroup=jsFuncBlock -syntax region jsFlowReturn contained start=/:/ end=/\%(\S\s*\%({\%(.*}\)\@!\)\@=\|\n\)/ contains=@jsFlowCluster oneline skipwhite skipempty nextgroup=jsFuncBlock keepend -syntax region jsFlowTypeObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsFlowTypeKey,jsFlowNoise skipwhite skipempty nextgroup=jsFunctionBlock extend -syntax match jsFlowTypeKey contained /\<[0-9a-zA-Z_$?]*\>\(\s*:\)\@=/ skipwhite skipempty nextgroup=jsFlowTypeValue -syntax region jsFlowTypeValue contained matchgroup=jsFlowNoise start=/:/ end=/[,};]\@=/ contains=@jsFlowCluster -syntax region jsFlowObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ oneline contains=@jsFlowCluster -syntax region jsFlowArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ oneline contains=@jsFlowCluster -syntax region jsFlowArrow contained matchgroup=jsFlowNoise start=/(/ end=/)\s*=>/ oneline contains=@jsFlowCluster -syntax keyword jsFlowDeclareKeyword contained declare -syntax keyword jsFlowType contained boolean number string null void any mixed JSON array function object Array bool -syntax match jsFlowClassProperty contained /\<[0-9a-zA-Z_$]*\>:\@=/ skipwhite skipempty nextgroup=jsFlow +syntax region jsFlowDefinition contained start=/:/ end=/\%(\s*[,=;)\n]\)\@=/ contains=@jsFlowCluster containedin=jsParen +syntax region jsFlowArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster +syntax region jsFlowObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster +syntax region jsFlowParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster syntax match jsFlowNoise contained /[:;,<>]/ -syntax cluster jsFlowCluster contains=jsFlowType,jsFlowArray,jsFlowObject,jsFlowNoise,jsFlowArrow -syntax keyword jsFlowStorageClass contained const var let -syntax region jsFlowParenRegion contained start=/:\s*(/ end=/)\%(\s*:\)\@=/ oneline contains=@jsFlowCluster skipwhite skipempty nextgroup=jsObjectValue -syntax region jsFlowClass contained matchgroup=jsFlowNoise start=// oneline contains=@jsFlowCluster skipwhite skipempty nextgroup=jsClassBlock +syntax keyword jsFlowType contained boolean number string null void any mixed JSON array function object array bool class +syntax keyword jsFlowTypeof contained typeof skipempty skipempty nextgroup=jsFlowTypeCustom,jsFlowType +syntax match jsFlowTypeCustom contained /\k*/ skipwhite skipempty nextgroup=jsFlowGroup +syntax region jsFlowGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster +syntax region jsFlowArrow contained matchgroup=jsFlowNoise start=/(/ end=/)\s*=>/ oneline contains=@jsFlowCluster +syntax match jsFlowMaybe contained /?/ + +syntax match jsFlowReturn contained /:\s*/ contains=jsFlowNoise skipwhite skipempty nextgroup=@jsFlowReturnCluster +syntax region jsFlowReturnObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock +syntax region jsFlowReturnArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock +syntax region jsFlowReturnParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock +syntax match jsFlowReturnKeyword contained /\k\+/ contains=jsFlowType,jsFlowTypeCustom skipwhite skipempty nextgroup=jsFlowReturnGroup,jsFuncBlock +syntax region jsFlowReturnGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock + +syntax region jsFlowFunctionGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncArgs +syntax region jsFlowClassGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster skipwhite skipempty nextgroup=jsClassBlock + +syntax region jsFlowTypeStatement start=/type/ end=/=\@=/ contains=jsFlowTypeOperator oneline skipwhite skipempty nextgroup=jsFlowTypeValue keepend +syntax region jsFlowTypeValue contained start=/=/ end=/[;\n]/ contains=@jsExpression +syntax match jsFlowTypeOperator contained /=/ +syntax keyword jsFlowTypeKeyword contained type + +syntax keyword jsFlowDeclare declare skipwhite skipempty nextgroup=jsFlowTypeStatement,jsClassDefinition,jsStorageClass,jsFlowModule,jsFlowInterface +syntax match jsFlowClassProperty contained /\<[0-9a-zA-Z_$]*\>:\@=/ skipwhite skipempty nextgroup=jsFlowDefinition containedin=jsClassBlock + +syntax region jsFlowModule contained start=/module/ end=/{\@=/ skipempty skipempty nextgroup=jsFlowDeclareBlock contains=jsString +syntax region jsFlowInterface contained start=/interface/ end=/{\@=/ skipempty skipempty nextgroup=jsFlowInterfaceBlock contains=@jsFlowCluster +syntax region jsFlowDeclareBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsFlowDeclare,jsFlowNoise + +syntax region jsFlowInterfaceBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsObjectKey,jsObjectKeyString,jsObjectKeyComputed,jsObjectSeparator,jsObjectFuncName,jsObjectMethodType,jsGenerator,jsComment,jsObjectStringKey,jsSpreadExpression,jsFlowNoise keepend + +syntax cluster jsFlowReturnCluster contains=jsFlowNoise,jsFlowReturnObject,jsFlowReturnArray,jsFlowReturnKeyword,jsFlowReturnGroup +syntax cluster jsFlowCluster contains=jsFlowArray,jsFlowObject,jsFlowNoise,jsFlowTypeof,jsFlowType,jsFlowGroup,jsFlowArrow,jsFlowMaybe,jsFlowParens if version >= 508 || !exists("did_javascript_syn_inits") if version < 508 @@ -24,19 +44,30 @@ if version >= 508 || !exists("did_javascript_syn_inits") else command -nargs=+ HiLink hi def link endif - HiLink jsFlow PreProc - HiLink jsFlowReturn PreProc + HiLink jsFlowDefinition PreProc + HiLink jsFlowType Type + HiLink jsFlowTypeCustom PreProc + HiLink jsFlowTypeof PreProc HiLink jsFlowArray PreProc - HiLink jsFlowDeclareBlock PreProc HiLink jsFlowObject PreProc - HiLink jsFlowParenRegion PreProc - HiLink jsFlowClass PreProc - HiLink jsFlowTypeObject PreProc - HiLink jsFlowTypeKey PreProc - HiLink jsFlowTypeValue PreProc + HiLink jsFlowParens PreProc + HiLink jsFlowGroup PreProc + HiLink jsFlowReturn PreProc + HiLink jsFlowReturnObject jsFlowReturn + HiLink jsFlowReturnArray jsFlowArray + HiLink jsFlowReturnParens jsFlowParens + HiLink jsFlowReturnGroup jsFlowGroup + HiLink jsFlowFunctionGroup PreProc + HiLink jsFlowClassGroup PreProc + HiLink jsFlowArrow PreProc + HiLink jsFlowTypeStatement PreProc + HiLink jsFlowTypeKeyword PreProc + HiLink jsFlowTypeOperator PreProc + HiLink jsFlowMaybe PreProc HiLink jsFlowClassProperty jsClassProperty - HiLink jsFlowType Type - HiLink jsFlowDeclareKeyword Type + HiLink jsFlowDeclare PreProc + HiLink jsFlowModule PreProc + HiLink jsFlowInterface PreProc HiLink jsFlowNoise Noise delcommand HiLink endif diff --git a/syntax/javascript.vim b/syntax/javascript.vim index 4af11275..e5d819a5 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -33,7 +33,8 @@ syntax match jsFuncCall /\k\+\%(\s*(\)\@=/ syntax match jsParensError /[)}\]]/ " Program Keywords -syntax keyword jsStorageClass const var let skipwhite skipempty nextgroup=jsDestructuringBlock,jsDestructuringArray +syntax keyword jsStorageClass const var let skipwhite skipempty nextgroup=jsDestructuringBlock,jsDestructuringArray,jsVariableDef +syntax match jsVariableDef contained /\k\+/ nextgroup=jsFlowDefinition syntax keyword jsOperator delete instanceof typeof void new in of syntax match jsOperator /[\!\|\&\+\-\<\>\=\%\/\*\~\^]\{1}/ syntax keyword jsBooleanTrue true @@ -77,7 +78,7 @@ else endif syntax cluster jsRegexpSpecial contains=jsSpecial,jsRegexpBoundary,jsRegexpBackRef,jsRegexpQuantifier,jsRegexpOr,jsRegexpMod -syntax match jsObjectKey contained /\<[0-9a-zA-Z_$]*\>\(\s*:\)\@=/ contains=jsFunctionKey skipwhite skipempty nextgroup=jsObjectValue,jsFlowParenRegion +syntax match jsObjectKey contained /\<[0-9a-zA-Z_$]*\>\(\s*:\)\@=/ contains=jsFunctionKey skipwhite skipempty nextgroup=jsObjectValue syntax region jsObjectKeyString contained start=+"+ skip=+\\\("\|$\)+ end=+"\|$+ contains=jsSpecial,@Spell skipwhite skipempty nextgroup=jsObjectValue syntax region jsObjectKeyString contained start=+'+ skip=+\\\('\|$\)+ end=+'\|$+ contains=jsSpecial,@Spell skipwhite skipempty nextgroup=jsObjectValue syntax region jsObjectKeyComputed contained matchgroup=jsBrackets start=/\[/ end=/]/ contains=@jsExpression skipwhite skipempty nextgroup=jsObjectValue,jsFuncArgs extend @@ -142,8 +143,8 @@ syntax region jsParenIfElse contained matchgroup=jsParens s syntax region jsParenRepeat contained matchgroup=jsParens start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentMisc,jsBlock extend fold syntax region jsParenSwitch contained matchgroup=jsParens start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsSwitchBlock extend fold syntax region jsParenCatch contained matchgroup=jsParens start=/(/ end=/)/ skipwhite skipempty nextgroup=jsTryCatchBlock extend fold -syntax region jsFuncArgs contained matchgroup=jsFuncParens start=/(/ end=/)/ contains=jsFuncArgCommas,jsComment,jsFuncArgExpression,jsDestructuringBlock,jsRestExpression,jsFlow skipwhite skipempty nextgroup=jsCommentFunction,jsFuncBlock,jsFlowReturn extend fold -syntax region jsClassBlock contained matchgroup=jsClassBraces start=/{/ end=/}/ contains=jsClassFuncName,jsClassMethodType,jsArrowFunction,jsArrowFuncArgs,jsComment,jsGenerator,jsDecorator,jsClassProperty,jsClassPropertyComputed,jsClassStringKey,jsNoise,jsFlowClassProperty extend fold +syntax region jsFuncArgs contained matchgroup=jsFuncParens start=/(/ end=/)/ contains=jsFuncArgCommas,jsComment,jsFuncArgExpression,jsDestructuringBlock,jsRestExpression,jsFlowDefinition skipwhite skipempty nextgroup=jsCommentFunction,jsFuncBlock,jsFlowReturn extend fold +syntax region jsClassBlock contained matchgroup=jsClassBraces start=/{/ end=/}/ contains=jsClassFuncName,jsClassMethodType,jsArrowFunction,jsArrowFuncArgs,jsComment,jsGenerator,jsDecorator,jsClassProperty,jsClassPropertyComputed,jsClassStringKey,jsNoise extend fold syntax region jsFuncBlock contained matchgroup=jsFuncBraces start=/{/ end=/}/ contains=@jsAll extend fold syntax region jsBlock contained matchgroup=jsBraces start=/{/ end=/}/ contains=@jsAll extend fold syntax region jsTryCatchBlock contained matchgroup=jsBraces start=/{/ end=/}/ contains=@jsAll skipwhite skipempty nextgroup=jsCatch,jsFinally extend fold @@ -157,7 +158,7 @@ syntax region jsRestExpression contained matchgroup=jsRestOperator s syntax region jsTernaryIf matchgroup=jsTernaryIfOperator start=/?/ end=/\%(:\|[\}]\@=\)/ contains=@jsExpression syntax match jsGenerator contained /\*/ skipwhite skipempty nextgroup=jsFuncName,jsFuncArgs -syntax match jsFuncName contained /\<[a-zA-Z_$][0-9a-zA-Z_$]*\>/ skipwhite skipempty nextgroup=jsFuncArgs +syntax match jsFuncName contained /\<[a-zA-Z_$][0-9a-zA-Z_$]*\>/ skipwhite skipempty nextgroup=jsFuncArgs,jsFlowFunctionGroup syntax region jsFuncArgExpression contained matchgroup=jsFuncArgOperator start=/=/ end=/[,)]\@=/ contains=@jsExpression extend syntax match jsFuncArgCommas contained ',' syntax keyword jsArguments contained arguments @@ -173,7 +174,7 @@ exe 'syntax match jsArrowFunction /=>/ skipwhite skipempty nextgroup=jsFunc syntax keyword jsClassKeywords contained extends class syntax match jsClassNoise contained /\./ syntax match jsClassMethodType contained /\%(get\|set\|static\|async\)\%( \k\+\)\@=/ skipwhite skipempty nextgroup=jsFuncName,jsClassProperty -syntax match jsClassDefinition /\\%( [a-zA-Z_$][0-9a-zA-Z_$ \n.]*\)*/ contains=jsClassKeywords,jsClassNoise skipwhite skipempty nextgroup=jsCommentClass,jsClassBlock,jsFlowClass +syntax match jsClassDefinition /\\%( [a-zA-Z_$][0-9a-zA-Z_$ \n.]*\)*/ contains=jsClassKeywords,jsClassNoise skipwhite skipempty nextgroup=jsCommentClass,jsClassBlock,jsFlowClassGroup syntax match jsDecorator contained "@" nextgroup=jsDecoratorFunction syntax match jsDecoratorFunction contained "[a-zA-Z_][a-zA-Z0-9_.]*" syntax match jsClassProperty contained /\<[0-9a-zA-Z_$]*\>\(\s*=\)\@=/ skipwhite skipempty nextgroup=jsClassValue @@ -203,8 +204,8 @@ syntax region jsEnvComment start=/\%^#!/ end=/$/ display " can't make jsComment a skippable type of group for nextgroup syntax region jsCommentFunction contained start=/\/\// end=/$/ contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturn extend keepend syntax region jsCommentFunction contained start=/\/\*/ end=/\*\// contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturn fold extend keepend -syntax region jsCommentClass contained start=/\/\// end=/$/ contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsClassBlock,jsFlowClass extend keepend -syntax region jsCommentClass contained start=/\/\*/ end=/\*\// contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsClassBlock,jsFlowClass fold extend keepend +syntax region jsCommentClass contained start=/\/\// end=/$/ contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsClassBlock,jsFlowClassGroup extend keepend +syntax region jsCommentClass contained start=/\/\*/ end=/\*\// contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsClassBlock,jsFlowClassGroup fold extend keepend syntax region jsCommentMisc contained start=/\/\// end=/$/ contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsBlock extend keepend syntax region jsCommentMisc contained start=/\/\*/ end=/\*\// contains=jsCommentTodo,@Spell skipwhite skipempty nextgroup=jsBlock fold extend keepend From 023f02c8dfcfca5de93289a748fbb1f8c765b609 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sun, 17 Jul 2016 19:46:53 -0700 Subject: [PATCH 26/63] Update javascript.vim --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 0c24d937..434a9353 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -203,7 +203,7 @@ function GetJavascriptIndent() \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsdestructuringblock\|args\|jsbracket\|jsparen\|jsobject') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 - return indent(num) + s:sw() + switch_offset + return indent(num) + s:sw() + (num == lnum ? 0 : switch_offset) end endfunction From e6a4f2f2d9b4f16e5f1426aa8d996ac1be8e0558 Mon Sep 17 00:00:00 2001 From: Dmitri Vereshchagin Date: Tue, 19 Jul 2016 22:12:42 +0400 Subject: [PATCH 27/63] Update ftplugin (#553) * Revert setting 'regexpengine' from filetype plugin Setting 'regexpengine' from filetype plugin without reenabling syntax doesn't fix problems described in #88 and #93. Seems like those problems are reproducible only in versions 7.4 and 7.4.1. Those few unfortunates who encounter it today will be able to find workaround by reading project issues. * Move filetype plugin to after directory - Add dollar sign to 'iskeyword' - Make use of b:undo_ftplugin variable --- {ftplugin => after/ftplugin}/javascript.vim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) rename {ftplugin => after/ftplugin}/javascript.vim (53%) diff --git a/ftplugin/javascript.vim b/after/ftplugin/javascript.vim similarity index 53% rename from ftplugin/javascript.vim rename to after/ftplugin/javascript.vim index e11ea2e0..e2d471dd 100644 --- a/ftplugin/javascript.vim +++ b/after/ftplugin/javascript.vim @@ -3,8 +3,6 @@ " Maintainer: vim-javascript community " URL: https://github.com/pangloss/vim-javascript -setlocal suffixesadd+=.js +setlocal iskeyword+=$ suffixesadd+=.js -if v:version == 703 && exists('®expengine') || v:version == 704 && !has('patch2') - set regexpengine=1 -endif +let b:undo_ftplugin .= ' | setlocal iskeyword< suffixesadd<' From 35ac627aa6884db976979f6b2ba8a527a3f1d0ab Mon Sep 17 00:00:00 2001 From: bounceme Date: Tue, 19 Jul 2016 15:57:15 -0700 Subject: [PATCH 28/63] Update javascript.vim --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 434a9353..f5b11b37 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -191,7 +191,7 @@ function GetJavascriptIndent() let switch_offset = 0 if index(map(synstack(v:lnum, 1), 'synIDattr( v:val, "name")'),'jsSwitchBlock') > -1 let bnum = search('\ 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 - return indent(num) + s:sw() + (num == lnum ? 0 : switch_offset) + return indent(num) + s:sw() + switch_offset end endfunction From 995007aea69e646016f621aafb4a2f548e27101a Mon Sep 17 00:00:00 2001 From: bounceme Date: Tue, 19 Jul 2016 19:18:08 -0700 Subject: [PATCH 29/63] Switch (#555) * switch offset always calculated when inside switch --- indent/javascript.vim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 7bd4aef2..e89a692d 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -187,10 +187,11 @@ function GetJavascriptIndent() return indent(num) end let switch_offset = 0 - if synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'switch' - let num = search('\ -1 + let bnum = search('\ Date: Tue, 19 Jul 2016 19:24:47 -0700 Subject: [PATCH 30/63] Update javascript.vim --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index f5b11b37..8433edb3 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -192,7 +192,7 @@ function GetJavascriptIndent() if index(map(synstack(v:lnum, 1), 'synIDattr( v:val, "name")'),'jsSwitchBlock') > -1 let bnum = search('\ Date: Wed, 20 Jul 2016 10:03:44 +0300 Subject: [PATCH 31/63] Remove unused g:javascript_conceal variable --- syntax/javascript.vim | 4 ---- 1 file changed, 4 deletions(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index e5d819a5..116285cc 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -12,10 +12,6 @@ if !exists("main_syntax") let main_syntax = 'javascript' endif -if !exists('g:javascript_conceal') - let g:javascript_conceal = 0 -endif - " Dollar sign is permitted anywhere in an identifier if v:version > 704 || v:version == 704 && has('patch1142') syntax iskeyword @,48-57,_,192-255,$ From c1d8d3766789024931f4353889bcac6e8fbed064 Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Mon, 18 Jul 2016 14:18:53 -0700 Subject: [PATCH 32/63] Add jsFlowReturnMaybe --- extras/flow.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extras/flow.vim b/extras/flow.vim index fc36fdbb..288c2568 100644 --- a/extras/flow.vim +++ b/extras/flow.vim @@ -15,6 +15,7 @@ syntax region jsFlowReturnObject contained matchgroup=jsFlowNoise start=/{/ syntax region jsFlowReturnArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock syntax region jsFlowReturnParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock syntax match jsFlowReturnKeyword contained /\k\+/ contains=jsFlowType,jsFlowTypeCustom skipwhite skipempty nextgroup=jsFlowReturnGroup,jsFuncBlock +syntax match jsFlowReturnMaybe contained /?/ skipwhite skipempty nextgroup=jsFlowReturnKeyword syntax region jsFlowReturnGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock syntax region jsFlowFunctionGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncArgs @@ -34,7 +35,7 @@ syntax region jsFlowDeclareBlock contained matchgroup=jsFlowNoise start=/{/ e syntax region jsFlowInterfaceBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsObjectKey,jsObjectKeyString,jsObjectKeyComputed,jsObjectSeparator,jsObjectFuncName,jsObjectMethodType,jsGenerator,jsComment,jsObjectStringKey,jsSpreadExpression,jsFlowNoise keepend -syntax cluster jsFlowReturnCluster contains=jsFlowNoise,jsFlowReturnObject,jsFlowReturnArray,jsFlowReturnKeyword,jsFlowReturnGroup +syntax cluster jsFlowReturnCluster contains=jsFlowNoise,jsFlowReturnObject,jsFlowReturnArray,jsFlowReturnKeyword,jsFlowReturnGroup,jsFlowReturnMaybe syntax cluster jsFlowCluster contains=jsFlowArray,jsFlowObject,jsFlowNoise,jsFlowTypeof,jsFlowType,jsFlowGroup,jsFlowArrow,jsFlowMaybe,jsFlowParens if version >= 508 || !exists("did_javascript_syn_inits") @@ -64,6 +65,7 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsFlowTypeKeyword PreProc HiLink jsFlowTypeOperator PreProc HiLink jsFlowMaybe PreProc + HiLink jsFlowReturnMaybe PreProc HiLink jsFlowClassProperty jsClassProperty HiLink jsFlowDeclare PreProc HiLink jsFlowModule PreProc From 215e9572b8324c713f09626b51f4a7fdc0b69232 Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Wed, 20 Jul 2016 00:45:12 -0700 Subject: [PATCH 33/63] Fix jsFlowClassDefinitions --- extras/flow.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extras/flow.vim b/extras/flow.vim index 288c2568..3a30874d 100644 --- a/extras/flow.vim +++ b/extras/flow.vim @@ -27,7 +27,8 @@ syntax match jsFlowTypeOperator contained /=/ syntax keyword jsFlowTypeKeyword contained type syntax keyword jsFlowDeclare declare skipwhite skipempty nextgroup=jsFlowTypeStatement,jsClassDefinition,jsStorageClass,jsFlowModule,jsFlowInterface -syntax match jsFlowClassProperty contained /\<[0-9a-zA-Z_$]*\>:\@=/ skipwhite skipempty nextgroup=jsFlowDefinition containedin=jsClassBlock +syntax match jsFlowClassProperty contained /\<[0-9a-zA-Z_$]*\>:\@=/ skipwhite skipempty nextgroup=jsFlowClassDef containedin=jsClassBlock +syntax region jsFlowClassDef contained start=/:/ end=/\%(\s*[,=;)\n]\)\@=/ contains=@jsFlowCluster containedin=jsParen skipwhite skipempty nextgroup=jsClassValue syntax region jsFlowModule contained start=/module/ end=/{\@=/ skipempty skipempty nextgroup=jsFlowDeclareBlock contains=jsString syntax region jsFlowInterface contained start=/interface/ end=/{\@=/ skipempty skipempty nextgroup=jsFlowInterfaceBlock contains=@jsFlowCluster @@ -46,6 +47,7 @@ if version >= 508 || !exists("did_javascript_syn_inits") command -nargs=+ HiLink hi def link endif HiLink jsFlowDefinition PreProc + HiLink jsFlowClassDef jsFlowDefinition HiLink jsFlowType Type HiLink jsFlowTypeCustom PreProc HiLink jsFlowTypeof PreProc From 125337c11897f162c749128bdd804040c76943a0 Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Wed, 20 Jul 2016 13:02:20 -0700 Subject: [PATCH 34/63] More flow improvements * Fixed a couple funky maybe cases * Improved argument definitions * Misc tweaks --- extras/flow.vim | 16 ++++++++++------ syntax/javascript.vim | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/extras/flow.vim b/extras/flow.vim index 3a30874d..dce98244 100644 --- a/extras/flow.vim +++ b/extras/flow.vim @@ -1,14 +1,16 @@ syntax region jsFlowDefinition contained start=/:/ end=/\%(\s*[,=;)\n]\)\@=/ contains=@jsFlowCluster containedin=jsParen +syntax region jsFlowArgumentDef contained start=/:/ end=/\%(\s*[,)]\)\@=/ contains=@jsFlowCluster syntax region jsFlowArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster syntax region jsFlowObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster -syntax region jsFlowParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster +syntax region jsFlowParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster syntax match jsFlowNoise contained /[:;,<>]/ syntax keyword jsFlowType contained boolean number string null void any mixed JSON array function object array bool class syntax keyword jsFlowTypeof contained typeof skipempty skipempty nextgroup=jsFlowTypeCustom,jsFlowType syntax match jsFlowTypeCustom contained /\k*/ skipwhite skipempty nextgroup=jsFlowGroup syntax region jsFlowGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster -syntax region jsFlowArrow contained matchgroup=jsFlowNoise start=/(/ end=/)\s*=>/ oneline contains=@jsFlowCluster -syntax match jsFlowMaybe contained /?/ +syntax region jsFlowArrowArguments contained matchgroup=jsFlowNoise start=/(/ end=/)\%(\s*=>\)\@=/ oneline skipwhite skipempty nextgroup=jsFlowArrow contains=@jsFlowCluster +syntax match jsFlowArrow contained /=>/ skipwhite skipempty nextgroup=jsFlowType,jsFlowTypeCustom,jsFlowParens +syntax match jsFlowMaybe contained /?/ skipwhite skipempty nextgroup=jsFlowType,jsFlowTypeCustom,jsFlowParens,jsFlowArrowArguments syntax match jsFlowReturn contained /:\s*/ contains=jsFlowNoise skipwhite skipempty nextgroup=@jsFlowReturnCluster syntax region jsFlowReturnObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock @@ -22,13 +24,13 @@ syntax region jsFlowFunctionGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster skipwhite skipempty nextgroup=jsClassBlock syntax region jsFlowTypeStatement start=/type/ end=/=\@=/ contains=jsFlowTypeOperator oneline skipwhite skipempty nextgroup=jsFlowTypeValue keepend -syntax region jsFlowTypeValue contained start=/=/ end=/[;\n]/ contains=@jsExpression +syntax region jsFlowTypeValue contained start=/=/ end=/[;\n]/ contains=@jsExpression,jsFlowGroup,jsFlowMaybe syntax match jsFlowTypeOperator contained /=/ syntax keyword jsFlowTypeKeyword contained type syntax keyword jsFlowDeclare declare skipwhite skipempty nextgroup=jsFlowTypeStatement,jsClassDefinition,jsStorageClass,jsFlowModule,jsFlowInterface syntax match jsFlowClassProperty contained /\<[0-9a-zA-Z_$]*\>:\@=/ skipwhite skipempty nextgroup=jsFlowClassDef containedin=jsClassBlock -syntax region jsFlowClassDef contained start=/:/ end=/\%(\s*[,=;)\n]\)\@=/ contains=@jsFlowCluster containedin=jsParen skipwhite skipempty nextgroup=jsClassValue +syntax region jsFlowClassDef contained start=/:/ end=/\%(\s*[,=;)\n]\)\@=/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsClassValue syntax region jsFlowModule contained start=/module/ end=/{\@=/ skipempty skipempty nextgroup=jsFlowDeclareBlock contains=jsString syntax region jsFlowInterface contained start=/interface/ end=/{\@=/ skipempty skipempty nextgroup=jsFlowInterfaceBlock contains=@jsFlowCluster @@ -37,7 +39,7 @@ syntax region jsFlowDeclareBlock contained matchgroup=jsFlowNoise start=/{/ e syntax region jsFlowInterfaceBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsObjectKey,jsObjectKeyString,jsObjectKeyComputed,jsObjectSeparator,jsObjectFuncName,jsObjectMethodType,jsGenerator,jsComment,jsObjectStringKey,jsSpreadExpression,jsFlowNoise keepend syntax cluster jsFlowReturnCluster contains=jsFlowNoise,jsFlowReturnObject,jsFlowReturnArray,jsFlowReturnKeyword,jsFlowReturnGroup,jsFlowReturnMaybe -syntax cluster jsFlowCluster contains=jsFlowArray,jsFlowObject,jsFlowNoise,jsFlowTypeof,jsFlowType,jsFlowGroup,jsFlowArrow,jsFlowMaybe,jsFlowParens +syntax cluster jsFlowCluster contains=jsFlowArray,jsFlowObject,jsFlowNoise,jsFlowTypeof,jsFlowType,jsFlowGroup,jsFlowArrowArguments,jsFlowMaybe,jsFlowParens if version >= 508 || !exists("did_javascript_syn_inits") if version < 508 @@ -48,6 +50,7 @@ if version >= 508 || !exists("did_javascript_syn_inits") endif HiLink jsFlowDefinition PreProc HiLink jsFlowClassDef jsFlowDefinition + HiLink jsFlowArgumentDef jsFlowDefinition HiLink jsFlowType Type HiLink jsFlowTypeCustom PreProc HiLink jsFlowTypeof PreProc @@ -62,6 +65,7 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsFlowReturnGroup jsFlowGroup HiLink jsFlowFunctionGroup PreProc HiLink jsFlowClassGroup PreProc + HiLink jsFlowArrowArguments PreProc HiLink jsFlowArrow PreProc HiLink jsFlowTypeStatement PreProc HiLink jsFlowTypeKeyword PreProc diff --git a/syntax/javascript.vim b/syntax/javascript.vim index 116285cc..8cf3e627 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -139,7 +139,7 @@ syntax region jsParenIfElse contained matchgroup=jsParens s syntax region jsParenRepeat contained matchgroup=jsParens start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsCommentMisc,jsBlock extend fold syntax region jsParenSwitch contained matchgroup=jsParens start=/(/ end=/)/ contains=@jsAll skipwhite skipempty nextgroup=jsSwitchBlock extend fold syntax region jsParenCatch contained matchgroup=jsParens start=/(/ end=/)/ skipwhite skipempty nextgroup=jsTryCatchBlock extend fold -syntax region jsFuncArgs contained matchgroup=jsFuncParens start=/(/ end=/)/ contains=jsFuncArgCommas,jsComment,jsFuncArgExpression,jsDestructuringBlock,jsRestExpression,jsFlowDefinition skipwhite skipempty nextgroup=jsCommentFunction,jsFuncBlock,jsFlowReturn extend fold +syntax region jsFuncArgs contained matchgroup=jsFuncParens start=/(/ end=/)/ contains=jsFuncArgCommas,jsComment,jsFuncArgExpression,jsDestructuringBlock,jsRestExpression,jsFlowArgumentDef skipwhite skipempty nextgroup=jsCommentFunction,jsFuncBlock,jsFlowReturn extend fold syntax region jsClassBlock contained matchgroup=jsClassBraces start=/{/ end=/}/ contains=jsClassFuncName,jsClassMethodType,jsArrowFunction,jsArrowFuncArgs,jsComment,jsGenerator,jsDecorator,jsClassProperty,jsClassPropertyComputed,jsClassStringKey,jsNoise extend fold syntax region jsFuncBlock contained matchgroup=jsFuncBraces start=/{/ end=/}/ contains=@jsAll extend fold syntax region jsBlock contained matchgroup=jsBraces start=/{/ end=/}/ contains=@jsAll extend fold From 178566475fdff317840365beb9271f66030f7bcd Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Wed, 20 Jul 2016 14:06:21 -0700 Subject: [PATCH 35/63] Fixed another maybe case --- extras/flow.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extras/flow.vim b/extras/flow.vim index dce98244..505ab26a 100644 --- a/extras/flow.vim +++ b/extras/flow.vim @@ -11,6 +11,7 @@ syntax region jsFlowGroup contained matchgroup=jsFlowNoise start=/\)\@=/ oneline skipwhite skipempty nextgroup=jsFlowArrow contains=@jsFlowCluster syntax match jsFlowArrow contained /=>/ skipwhite skipempty nextgroup=jsFlowType,jsFlowTypeCustom,jsFlowParens syntax match jsFlowMaybe contained /?/ skipwhite skipempty nextgroup=jsFlowType,jsFlowTypeCustom,jsFlowParens,jsFlowArrowArguments +syntax match jsFlowObjectKey contained /[0-9a-zA-Z_$?]*\(\s*:\)\@=/ contains=jsFunctionKey,jsFlowMaybe skipwhite skipempty nextgroup=jsObjectValue containedin=jsObject syntax match jsFlowReturn contained /:\s*/ contains=jsFlowNoise skipwhite skipempty nextgroup=@jsFlowReturnCluster syntax region jsFlowReturnObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock @@ -77,5 +78,6 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsFlowModule PreProc HiLink jsFlowInterface PreProc HiLink jsFlowNoise Noise + HiLink jsFlowObjectKey jsObjectKey delcommand HiLink endif From c68ecbe99aa5f20a76f31fcb09b85cdf2d64015c Mon Sep 17 00:00:00 2001 From: bounceme Date: Wed, 20 Jul 2016 19:50:46 -0700 Subject: [PATCH 36/63] removing custom formatting (#565) also adds `nolisp` setting --- indent/javascript.vim | 63 +------------------------------------------ 1 file changed, 1 insertion(+), 62 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index c372262c..e0dac792 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -10,7 +10,7 @@ let b:did_indent = 1 " Now, set up our indentation expression and keys that trigger it. setlocal indentexpr=GetJavascriptIndent() -setlocal formatexpr=Fixedgq(v:lnum,v:count) +setlocal nolisp setlocal indentkeys=0{,0},0),0],:,!^F,o,O,e setlocal cinoptions+=j1,J1,c1 @@ -209,66 +209,5 @@ endfunction let &cpo = s:cpo_save unlet s:cpo_save -" gq{{{2 -function! Fixedgq(lnum, count) - let l:tw = &tw ? &tw : 80; - let l:count = a:count - let l:first_char = indent(a:lnum) + 1 - - if mode() == 'i' " gq was not pressed, but tw was set - return 1 - endif - - " This gq is only meant to do code with strings, not comments - if s:IsInComment(a:lnum, l:first_char) - return 1 - endif - - if len(getline(a:lnum)) < l:tw && l:count == 1 " No need for gq - return 1 - endif - - " Put all the lines on one line and do normal spliting after that - if l:count > 1 - while l:count > 1 - let l:count -= 1 - normal J - endwhile - endif - - let l:winview = winsaveview() - - call cursor(a:lnum, l:tw + 1) - let orig_breakpoint = searchpairpos(' ', '', '\.', 'bcW', '', a:lnum) - call cursor(a:lnum, l:tw + 1) - let breakpoint = searchpairpos(' ', '', '\.', 'bcW', s:skip_expr, a:lnum) - - " No need for special treatment, normal gq handles edgecases better - if breakpoint[1] == orig_breakpoint[1] - call winrestview(l:winview) - return 1 - endif - - " Try breaking after string - if breakpoint[1] <= indent(a:lnum) - call cursor(a:lnum, l:tw + 1) - let breakpoint = searchpairpos('\.', '', ' ', 'cW', s:skip_expr, a:lnum) - endif - - - if breakpoint[1] != 0 - call feedkeys("r\") - else - let l:count = l:count - 1 - endif - - " run gq on new lines - if l:count == 1 - call feedkeys("gqq") - endif - - return 0 -endfunction -"}}} " vim: foldmethod=marker:foldlevel=1 From 005928682d137c049d2a9829f4be12d8b4ceb9d5 Mon Sep 17 00:00:00 2001 From: bounceme Date: Wed, 20 Jul 2016 20:13:32 -0700 Subject: [PATCH 37/63] operators & continuation (#566) * operators & continuation --- indent/javascript.vim | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index e0dac792..ec278b50 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -58,8 +58,16 @@ endfunc let s:line_term = '\s*\%(\%(:\@\)\C' . s:line_term || @@ -70,8 +78,6 @@ function s:Onescope(lnum) \ (expand("") =~ 'while\C' ? !s:lookForParens('\\C', '\\C','bw',100) : 1) endfunction -let s:operator_first = s:line_pre . '\%([,:?]\|\([-/.+*]\)\%(\1\|\*\|\/\)\@!\|||\|&&\)' - " Auxiliary Functions {{{2 " ====================== @@ -194,8 +200,8 @@ function GetJavascriptIndent() let num = max([num,bnum]) let b:js_cache[1] = num endif - if (line =~ s:operator_first || - \ (getline(lnum) =~ s:continuation_regex && getline(lnum) !~ s:expr_case) || + if (line =~ g:javascript_opfirst || + \ (getline(lnum) =~ g:javascript_continuation && getline(lnum) !~ s:expr_case) || \ (s:Onescope(lnum) && line !~ s:line_pre . '{')) && \ (num != lnum && \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsdestructuringblock\|args\|jsbracket\|jsparen\|jsobject') From 31d8b39f2640e5cbb1114455e2ee76cfab3921c7 Mon Sep 17 00:00:00 2001 From: bounceme Date: Wed, 20 Jul 2016 23:55:30 -0700 Subject: [PATCH 38/63] switch enhanced (#568) this is more accurate and allows for nested switches --- indent/javascript.vim | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index ec278b50..f5242906 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -161,7 +161,6 @@ function GetJavascriptIndent() set cpo+=% let ind = cindent(v:lnum) let &cpo = s:cpo_switch - let b:js_cache = [v:lnum, search('\ -1 let bnum = search('\ Date: Thu, 21 Jul 2016 00:12:06 -0700 Subject: [PATCH 39/63] remove whitespace and regex mistake --- indent/javascript.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index f5242906..0323b81d 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -47,7 +47,7 @@ let s:syng_comment = '\%(comment\|doc\)\c' let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'" func s:lookForParens(start,end,flags,time) - try + try return searchpair(a:start,'',a:end,a:flags, \ "line('.') < " . (prevnonblank(v:lnum) - 2000) . " ? dummy :" . s:skip_expr \ ,0,a:time) @@ -74,7 +74,7 @@ function s:Onescope(lnum) \ (cursor(a:lnum, match(getline(a:lnum),')' . s:line_term)) > -1 && \ s:lookForParens('(', ')', 'cbW', 100) > 0 && \ cursor(line('.'),match( ' ' . strpart(getline(line('.')),0,col('.') - 1), - \ '\<\%(else\|for\%(\s+each\)\=\|if\|let\|while\|with\)\C' . s:line_term)) > -1) && + \ '\<\%(else\|for\%(\s+each\)\=\|if\|let\|while\|with\)\C' . s:line_term)) > -1) && \ (expand("") =~ 'while\C' ? !s:lookForParens('\\C', '\\C','bw',100) : 1) endfunction @@ -195,7 +195,7 @@ function GetJavascriptIndent() if index(map(synstack(v:lnum, 1), 'synIDattr( v:val, "name")'),'jsSwitchBlock') > -1 let bnum = search('\ Date: Thu, 21 Jul 2016 01:02:56 -0700 Subject: [PATCH 40/63] negative and decimal switch label values (#569) allows for every possible option including: `set cino+=:-0.5s` `set cino+=:-.5s` --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 0323b81d..f9fe9ea9 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -195,7 +195,7 @@ function GetJavascriptIndent() if index(map(synstack(v:lnum, 1), 'synIDattr( v:val, "name")'),'jsSwitchBlock') > -1 let bnum = search('\ Date: Thu, 21 Jul 2016 09:37:32 -0700 Subject: [PATCH 41/63] cleaning making a very bright sheen --- indent/javascript.vim | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index f9fe9ea9..9b944556 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -12,7 +12,7 @@ let b:did_indent = 1 setlocal indentexpr=GetJavascriptIndent() setlocal nolisp setlocal indentkeys=0{,0},0),0],:,!^F,o,O,e -setlocal cinoptions+=j1,J1,c1 +setlocal cinoptions+=j1,J1 let b:undo_indent = 'setlocal indentexpr< formatexpr< indentkeys< cinoptions<' @@ -146,21 +146,14 @@ function GetJavascriptIndent() if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsInComment(v:lnum, 1) return cindent(v:lnum) endif - if line =~ '^\s*$' && getline(prevline) =~ '\%(\%(^\s*\/\/\|\/\*\).*\)\@ -1 let bnum = search('\ Date: Thu, 21 Jul 2016 09:44:10 -0700 Subject: [PATCH 42/63] more cleaning --- indent/javascript.vim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 9b944556..73d3b1a8 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -14,7 +14,7 @@ setlocal nolisp setlocal indentkeys=0{,0},0),0],:,!^F,o,O,e setlocal cinoptions+=j1,J1 -let b:undo_indent = 'setlocal indentexpr< formatexpr< indentkeys< cinoptions<' +let b:undo_indent = 'setlocal indentexpr< indentkeys< cinoptions<' " Only define the function once. if exists("*GetJavascriptIndent") @@ -137,6 +137,9 @@ function GetJavascriptIndent() let prevline = prevnonblank(v:lnum - 1) " previous line of code let lnum = s:PrevNonBlankNonString(v:lnum - 1) + if lnum == 0 + return 0 + endif " start with strings,comments,etc.{{{2 if (line !~ '^[''"`]' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'string\|template') || @@ -146,9 +149,7 @@ function GetJavascriptIndent() if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsInComment(v:lnum, 1) return cindent(v:lnum) endif - if lnum == 0 - return 0 - endif + if (line =~ s:expr_case) let cpo_switch = &cpo set cpo+=% From 0c3a3509ebcdf4710c09cfb2fd2a4a9867c93794 Mon Sep 17 00:00:00 2001 From: bounceme Date: Thu, 21 Jul 2016 20:10:38 -0700 Subject: [PATCH 43/63] add jsfunccall to not indent args --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 73d3b1a8..6cbee1fd 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -195,7 +195,7 @@ function GetJavascriptIndent() \ (getline(lnum) =~ g:javascript_continuation && getline(lnum) !~ s:expr_case) || \ (s:Onescope(lnum) && line !~ s:line_pre . '{')) && \ (num != lnum && - \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsdestructuringblock\|args\|jsbracket\|jsparen\|jsobject') + \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsfunccall\|jsdestructuringblock\|args\|jsbracket\|jsparen\|jsobject') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 return indent(num) + s:sw() + switch_offset From 96885ca809e9d579435e86d4a5d00a22b23f5a61 Mon Sep 17 00:00:00 2001 From: bounceme Date: Thu, 21 Jul 2016 21:35:25 -0700 Subject: [PATCH 44/63] small perf gain --- indent/javascript.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 6cbee1fd..8ed3f135 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -166,17 +166,17 @@ function GetJavascriptIndent() let num = pcounts[0] =~ '1' ? lnum : b:js_cache[1] else call cursor(v:lnum,1) - let syns = synIDattr(synID(v:lnum, 1, 1), 'name') - if line[1] =~ '\s' + if line[0] =~ '\s' + let syns = synIDattr(synID(v:lnum, 1, 1), 'name') if syns != '' let pattern = syns =~? 'funcblock' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : syns =~? 'jsbracket'? ['\[','\]'] : \ ['(\|{\|\[',')\|}\|\]'] let num = s:lookForParens(pattern[0],pattern[1],'nbw',2000) else - let num = 0 + let num = s:lookForParens('(\|{\|\[',')\|}\|\]','nbW',2000) end else - let num = s:lookForParens('(\|{\|\[',')\|}\|\]','nbW',2000) + let num = 0 end end let b:js_cache = [v:lnum, num] From 6c440b3ecb13abed60a6f0083764673e80a01b8f Mon Sep 17 00:00:00 2001 From: bounceme Date: Thu, 21 Jul 2016 21:41:10 -0700 Subject: [PATCH 45/63] perf continued --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 8ed3f135..7ac67b24 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -173,7 +173,7 @@ function GetJavascriptIndent() \ ['(\|{\|\[',')\|}\|\]'] let num = s:lookForParens(pattern[0],pattern[1],'nbw',2000) else - let num = s:lookForParens('(\|{\|\[',')\|}\|\]','nbW',2000) + let num = 0 end else let num = 0 From b4038a26c937524d00c75f3bbe75b46acad5e2df Mon Sep 17 00:00:00 2001 From: bounceme Date: Thu, 21 Jul 2016 22:24:06 -0700 Subject: [PATCH 46/63] addresses unindented code --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 7ac67b24..7dc16964 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -176,7 +176,7 @@ function GetJavascriptIndent() let num = 0 end else - let num = 0 + let num = s:lookForParens('(\|{\|\[',')\|}\|\]','nbW',2000) end end let b:js_cache = [v:lnum, num] From 9a6c48548eb0ce54399b69959dd27ad2fd46a41b Mon Sep 17 00:00:00 2001 From: bounceme Date: Thu, 21 Jul 2016 22:29:22 -0700 Subject: [PATCH 47/63] minor refactor --- indent/javascript.vim | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 7dc16964..65cd6132 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -166,17 +166,15 @@ function GetJavascriptIndent() let num = pcounts[0] =~ '1' ? lnum : b:js_cache[1] else call cursor(v:lnum,1) - if line[0] =~ '\s' - let syns = synIDattr(synID(v:lnum, 1, 1), 'name') - if syns != '' - let pattern = syns =~? 'funcblock' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : syns =~? 'jsbracket'? ['\[','\]'] : - \ ['(\|{\|\[',')\|}\|\]'] - let num = s:lookForParens(pattern[0],pattern[1],'nbw',2000) - else - let num = 0 - end - else + let syns = synIDattr(synID(v:lnum, 1, 1), 'name') + if line[0] =~ '\s' && syns != '' + let pattern = syns =~? 'funcblock' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : syns =~? 'jsbracket'? ['\[','\]'] : + \ ['(\|{\|\[',')\|}\|\]'] + let num = s:lookForParens(pattern[0],pattern[1],'nbw',2000) + elseif syns != '' let num = s:lookForParens('(\|{\|\[',')\|}\|\]','nbW',2000) + else + let num = 0 end end let b:js_cache = [v:lnum, num] From e895bd1629bca407721043756f5b110fa50442cb Mon Sep 17 00:00:00 2001 From: bounceme Date: Fri, 22 Jul 2016 00:18:53 -0700 Subject: [PATCH 48/63] fix syn-indent issue --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 65cd6132..4cb129ff 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -193,7 +193,7 @@ function GetJavascriptIndent() \ (getline(lnum) =~ g:javascript_continuation && getline(lnum) !~ s:expr_case) || \ (s:Onescope(lnum) && line !~ s:line_pre . '{')) && \ (num != lnum && - \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsfunccall\|jsdestructuringblock\|args\|jsbracket\|jsparen\|jsobject') + \ synIDattr(synID(v:lnum, 1, 1), 'name') !~? 'jsdestructuringblock\|args\|jsbracket\|jsparen\|jsobject') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 return indent(num) + s:sw() + switch_offset From ab5d96bbb7c0cb4cb03a65c49264527f12a34a3d Mon Sep 17 00:00:00 2001 From: bounceme Date: Sat, 23 Jul 2016 22:24:17 -0700 Subject: [PATCH 49/63] possible reuse of logic (simple lexing) (#570) reusing of logic --- indent/javascript.vim | 57 +++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 4cb129ff..4863cb1f 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -44,7 +44,7 @@ let s:syng_strcom = '\%(string\|regex\|special\|doc\|comment\|template\)\c' let s:syng_comment = '\%(comment\|doc\)\c' " Expression used to check whether we should skip a match with searchpair(). -let s:skip_expr = "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'" +let s:skip_expr = "s:IsInStringOrComment(line('.'),col('.'))" func s:lookForParens(start,end,flags,time) try @@ -69,13 +69,14 @@ if !exists('g:javascript_continuation') endif let g:javascript_continuation .= s:line_term -function s:Onescope(lnum) - return getline(a:lnum) =~ '\%(\\)\C' . s:line_term || - \ (cursor(a:lnum, match(getline(a:lnum),')' . s:line_term)) > -1 && +function s:Onescope(lnum,text,add) + return a:text =~ '\%(\' . (a:add ? '\|try\|finally' : '' ) . '\)\C' . s:line_term || + \ (cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1 && \ s:lookForParens('(', ')', 'cbW', 100) > 0 && \ cursor(line('.'),match( ' ' . strpart(getline(line('.')),0,col('.') - 1), - \ '\<\%(else\|for\%(\s+each\)\=\|if\|let\|while\|with\)\C' . s:line_term)) > -1) && - \ (expand("") =~ 'while\C' ? !s:lookForParens('\\C', '\\C','bw',100) : 1) + \ (a:add ? '\K\k*' : + \ '\<\%(else\|for\%(\s+each\)\=\|function\*\=\%(\s\+\K\k*\)\=\|if\|let\|switch\|while\|with\)\C') . s:line_term)) > -1) && + \ (a:add || (expand("") =~ 'while\C' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) endfunction " Auxiliary Functions {{{2 @@ -86,11 +87,6 @@ function s:IsInStringOrComment(lnum, col) return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_strcom endfunction -" Check if the character at lnum:col is inside a multi-line comment. -function s:IsInComment(lnum, col) - return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_comment -endfunction - " Find line above 'lnum' that isn't empty, in a comment, or in a string. function s:PrevNonBlankNonString(lnum) let lnum = prevnonblank(a:lnum) @@ -110,18 +106,21 @@ function s:LineHasOpeningBrackets(lnum) let open_4 = 0 let line = getline(a:lnum) let pos = match(line, '[][(){}]', 0) + let last = 0 while pos != -1 if !s:IsInStringOrComment(a:lnum, pos + 1) let idx = stridx('(){}[]', line[pos]) if idx % 2 == 0 let open_{idx} = open_{idx} + 1 + let last = pos else let open_{idx - 1} = open_{idx - 1} - 1 endif endif let pos = match(line, '[][(){}]', pos + 1) endwhile - return (open_0 > 0 ? 1 : (open_0 == 0 ? 0 : 2)) . (open_2 > 0 ? 1 : (open_2 == 0 ? 0 : 2)) . (open_4 > 0 ? 1 : (open_4 == 0 ? 0 : 2)) + return [(open_0 > 0 ? 1 : (open_0 == 0 ? 0 : 2)) . (open_2 > 0 ? 1 : (open_2 == 0 ? 0 : 2)) . + \ (open_4 > 0 ? 1 : (open_4 == 0 ? 0 : 2)), last] endfunction " }}} @@ -129,7 +128,7 @@ endfunction " ========================= function GetJavascriptIndent() if !exists('b:js_cache') - let b:js_cache = [0,0] + let b:js_cache = [0,0,0] end " Get the current line. let line = getline(v:lnum) @@ -143,10 +142,10 @@ function GetJavascriptIndent() " start with strings,comments,etc.{{{2 if (line !~ '^[''"`]' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'string\|template') || - \ (line !~ '^\s*[/*]' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'comment') + \ (line !~ '^\s*[/*]' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? s:syng_comment) return -1 endif - if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsInComment(v:lnum, 1) + if line !~ '^\%(\/\*\|\s*\/\/\)' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? s:syng_comment) return cindent(v:lnum) endif @@ -161,23 +160,24 @@ function GetJavascriptIndent() " the containing paren, bracket, curly let pcounts = [0] - if b:js_cache[0] >= lnum && b:js_cache[0] < v:lnum && b:js_cache[0] && - \ (b:js_cache[0] > lnum || map(pcounts,'s:LineHasOpeningBrackets(lnum)')[0] !~ '2') - let num = pcounts[0] =~ '1' ? lnum : b:js_cache[1] + if b:js_cache[0] >= lnum && b:js_cache[0] <= v:lnum && b:js_cache[0] && + \ (b:js_cache[0] > lnum || map(pcounts,'s:LineHasOpeningBrackets(lnum)')[0][0] !~ '2') + let num = pcounts[0][0] =~ '1' ? lnum : b:js_cache[1] + if pcounts[0][0] =~'1' + call cursor(lnum,pcounts[0][1]) + end else call cursor(v:lnum,1) let syns = synIDattr(synID(v:lnum, 1, 1), 'name') if line[0] =~ '\s' && syns != '' let pattern = syns =~? 'funcblock' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : syns =~? 'jsbracket'? ['\[','\]'] : \ ['(\|{\|\[',')\|}\|\]'] - let num = s:lookForParens(pattern[0],pattern[1],'nbw',2000) - elseif syns != '' - let num = s:lookForParens('(\|{\|\[',')\|}\|\]','nbW',2000) + let num = s:lookForParens(pattern[0],pattern[1],'bW',2000) else - let num = 0 + let num = s:lookForParens('(\|{\|\[',')\|}\|\]','bW',2000) end end - let b:js_cache = [v:lnum, num] + let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] " most significant part if line =~ s:line_pre . '[])}]' @@ -185,15 +185,14 @@ function GetJavascriptIndent() end let switch_offset = 0 if index(map(synstack(v:lnum, 1), 'synIDattr( v:val, "name")'),'jsSwitchBlock') > -1 - let bnum = search('\ 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 return indent(num) + s:sw() + switch_offset From bf7d4b663c743e1a5852080823e9b61f74cab249 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sun, 24 Jul 2016 10:34:39 -0700 Subject: [PATCH 50/63] remove switch syn check (#571) * remove switch syn check https://github.com/pangloss/vim-javascript/issues/177#issuecomment-234758932 --- indent/javascript.vim | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 4863cb1f..e366cece 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -76,7 +76,7 @@ function s:Onescope(lnum,text,add) \ cursor(line('.'),match( ' ' . strpart(getline(line('.')),0,col('.') - 1), \ (a:add ? '\K\k*' : \ '\<\%(else\|for\%(\s+each\)\=\|function\*\=\%(\s\+\K\k*\)\=\|if\|let\|switch\|while\|with\)\C') . s:line_term)) > -1) && - \ (a:add || (expand("") =~ 'while\C' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) + \ (a:add || (expand("") == 'while' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) endfunction " Auxiliary Functions {{{2 @@ -183,16 +183,12 @@ function GetJavascriptIndent() if line =~ s:line_pre . '[])}]' return indent(num) end - let switch_offset = 0 - if index(map(synstack(v:lnum, 1), 'synIDattr( v:val, "name")'),'jsSwitchBlock') > -1 - let bnum = search('\") != 'switch' ? 0 : &cino !~ ':' || !has('float') ? s:sw() : + \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (match(&cino,'.*:\zs[^,]*s') ? s:sw() : 1)) if ((line =~ g:javascript_opfirst || \ (getline(lnum) =~ g:javascript_continuation && getline(lnum) !~ s:expr_case)) && - \ (num == 0 || s:Onescope(num, strpart(getline(num),0,b:js_cache[2] - 1),1))) || - \ (s:Onescope(lnum,getline(lnum),0) && line !~ s:line_pre . '{') + \ inb) || (s:Onescope(lnum,getline(lnum),0) && line !~ s:line_pre . '{') return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset elseif num > 0 return indent(num) + s:sw() + switch_offset From ad8d72ad4c0d1dad9c2012b2eead9ed7d5ec07c2 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sun, 24 Jul 2016 11:00:35 -0700 Subject: [PATCH 51/63] cleaning indent --- indent/javascript.vim | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index e366cece..611ed1ea 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -44,7 +44,7 @@ let s:syng_strcom = '\%(string\|regex\|special\|doc\|comment\|template\)\c' let s:syng_comment = '\%(comment\|doc\)\c' " Expression used to check whether we should skip a match with searchpair(). -let s:skip_expr = "s:IsInStringOrComment(line('.'),col('.'))" +let s:skip_expr = "s:IsSyn(line('.'),col('.'),0)" func s:lookForParens(start,end,flags,time) try @@ -83,15 +83,15 @@ endfunction " ====================== " Check if the character at lnum:col is inside a string, comment, or is ascii. -function s:IsInStringOrComment(lnum, col) - return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_strcom +function s:IsSyn(lnum, col, reg) + return synIDattr(synID(a:lnum, a:col, 1), 'name') =~? (a:reg ? a:reg : s:syng_strcom) endfunction " Find line above 'lnum' that isn't empty, in a comment, or in a string. function s:PrevNonBlankNonString(lnum) let lnum = prevnonblank(a:lnum) while lnum > 0 - if !s:IsInStringOrComment(lnum, matchend(getline(lnum), '^\s*[^''"]')) + if !s:IsSyn(lnum, matchend(getline(lnum), '^\s*[^''"]'),0) break endif let lnum = prevnonblank(lnum - 1) @@ -108,7 +108,7 @@ function s:LineHasOpeningBrackets(lnum) let pos = match(line, '[][(){}]', 0) let last = 0 while pos != -1 - if !s:IsInStringOrComment(a:lnum, pos + 1) + if !s:IsSyn(a:lnum, pos + 1, 0) let idx = stridx('(){}[]', line[pos]) if idx % 2 == 0 let open_{idx} = open_{idx} + 1 @@ -141,8 +141,8 @@ function GetJavascriptIndent() endif " start with strings,comments,etc.{{{2 - if (line !~ '^[''"`]' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? 'string\|template') || - \ (line !~ '^\s*[/*]' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? s:syng_comment) + if (line !~ '^[''"`]' && s:IsSyn(v:lnum,1,'string\|template')) || + \ (line !~ '^\s*[/*]' && s:IsSyn(v:lnum,1,s:syng_comment)) return -1 endif if line !~ '^\%(\/\*\|\s*\/\/\)' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? s:syng_comment) From f90b8c85e0a510c3e35fd3b10c53127e61bffb26 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sun, 24 Jul 2016 11:06:15 -0700 Subject: [PATCH 52/63] more cleaning --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 611ed1ea..b46573ee 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -145,7 +145,7 @@ function GetJavascriptIndent() \ (line !~ '^\s*[/*]' && s:IsSyn(v:lnum,1,s:syng_comment)) return -1 endif - if line !~ '^\%(\/\*\|\s*\/\/\)' && synIDattr(synID(v:lnum, 1, 1), 'name') =~? s:syng_comment) + if line !~ '^\%(\/\*\|\s*\/\/\)' && s:IsSyn(v:lnum,1,s:syng_comment) return cindent(v:lnum) endif From 57470573a9fe7caf60c95d1582fafb412ba6d333 Mon Sep 17 00:00:00 2001 From: bounceme Date: Sun, 24 Jul 2016 17:02:29 -0700 Subject: [PATCH 53/63] remove obvious comment the folding is enough for separating content --- indent/javascript.vim | 2 -- 1 file changed, 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index b46573ee..09a0674c 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -124,8 +124,6 @@ function s:LineHasOpeningBrackets(lnum) endfunction " }}} -" GetJavascriptIndent Function -" ========================= function GetJavascriptIndent() if !exists('b:js_cache') let b:js_cache = [0,0,0] From 506783bc16a9ffed9a1fb1360891ced486b697be Mon Sep 17 00:00:00 2001 From: bounceme Date: Sun, 24 Jul 2016 22:20:24 -0700 Subject: [PATCH 54/63] move lines from search pair function --- indent/javascript.vim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 09a0674c..806da210 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -44,13 +44,11 @@ let s:syng_strcom = '\%(string\|regex\|special\|doc\|comment\|template\)\c' let s:syng_comment = '\%(comment\|doc\)\c' " Expression used to check whether we should skip a match with searchpair(). -let s:skip_expr = "s:IsSyn(line('.'),col('.'),0)" +let s:skip_expr = "line('.') < (prevnonblank(v:lnum) - 2000) ? dummy : s:IsSyn(line('.'),col('.'),0)" func s:lookForParens(start,end,flags,time) try - return searchpair(a:start,'',a:end,a:flags, - \ "line('.') < " . (prevnonblank(v:lnum) - 2000) . " ? dummy :" . s:skip_expr - \ ,0,a:time) + return searchpair(a:start,'',a:end,a:flags,s:skip_expr,0,a:time) catch /E118/ return searchpair(a:start,'',a:end,a:flags,0,0) endtry From acb4f00324c84c175d93804b39efad76ee66442a Mon Sep 17 00:00:00 2001 From: bounceme Date: Mon, 25 Jul 2016 01:50:02 -0700 Subject: [PATCH 55/63] fix syn function vimscript is strange --- indent/javascript.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 806da210..8a1e4b63 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -44,7 +44,7 @@ let s:syng_strcom = '\%(string\|regex\|special\|doc\|comment\|template\)\c' let s:syng_comment = '\%(comment\|doc\)\c' " Expression used to check whether we should skip a match with searchpair(). -let s:skip_expr = "line('.') < (prevnonblank(v:lnum) - 2000) ? dummy : s:IsSyn(line('.'),col('.'),0)" +let s:skip_expr = "line('.') < (prevnonblank(v:lnum) - 2000) ? dummy : s:IsSyn(line('.'),col('.'),'')" func s:lookForParens(start,end,flags,time) try @@ -82,14 +82,14 @@ endfunction " Check if the character at lnum:col is inside a string, comment, or is ascii. function s:IsSyn(lnum, col, reg) - return synIDattr(synID(a:lnum, a:col, 1), 'name') =~? (a:reg ? a:reg : s:syng_strcom) + return synIDattr(synID(a:lnum, a:col, 1), 'name') =~? (a:reg != '' ? a:reg : s:syng_strcom) endfunction " Find line above 'lnum' that isn't empty, in a comment, or in a string. function s:PrevNonBlankNonString(lnum) let lnum = prevnonblank(a:lnum) while lnum > 0 - if !s:IsSyn(lnum, matchend(getline(lnum), '^\s*[^''"]'),0) + if !s:IsSyn(lnum, matchend(getline(lnum), '^\s*[^''"]'),'') break endif let lnum = prevnonblank(lnum - 1) @@ -106,7 +106,7 @@ function s:LineHasOpeningBrackets(lnum) let pos = match(line, '[][(){}]', 0) let last = 0 while pos != -1 - if !s:IsSyn(a:lnum, pos + 1, 0) + if !s:IsSyn(a:lnum, pos + 1, '') let idx = stridx('(){}[]', line[pos]) if idx % 2 == 0 let open_{idx} = open_{idx} + 1 From 2905f34d829f62478fe7755a6cf49d593645a15f Mon Sep 17 00:00:00 2001 From: bounceme Date: Mon, 25 Jul 2016 10:26:51 -0700 Subject: [PATCH 56/63] removing mode-line the file is no longer long enough to require automatic folding! --- indent/javascript.vim | 2 -- 1 file changed, 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 8a1e4b63..568b7570 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -195,5 +195,3 @@ endfunction let &cpo = s:cpo_save unlet s:cpo_save - -" vim: foldmethod=marker:foldlevel=1 From cbcfaaf09f1ce37170b20507ba5f95ebc13d9c5e Mon Sep 17 00:00:00 2001 From: bounceme Date: Tue, 26 Jul 2016 13:25:47 -0700 Subject: [PATCH 57/63] adding more operators (#573) * adding more operators I think adding `<>` could mess with xml type things so i've not included them --- indent/javascript.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 568b7570..441f1b97 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -58,12 +58,12 @@ let s:line_term = '\s*\%(\%(:\@\@!\||\|&\|in\%(stanceof\)\=\>\)\C' endif let g:javascript_opfirst = s:line_pre . g:javascript_opfirst if !exists('g:javascript_continuation') - let g:javascript_continuation = '\%([*,.?:]\|+\@ Date: Wed, 27 Jul 2016 11:28:46 -0700 Subject: [PATCH 58/63] Flow tweaks * Improved OR operator * Various fixes for arguments --- extras/flow.vim | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/extras/flow.vim b/extras/flow.vim index 505ab26a..a1848830 100644 --- a/extras/flow.vim +++ b/extras/flow.vim @@ -1,5 +1,5 @@ syntax region jsFlowDefinition contained start=/:/ end=/\%(\s*[,=;)\n]\)\@=/ contains=@jsFlowCluster containedin=jsParen -syntax region jsFlowArgumentDef contained start=/:/ end=/\%(\s*[,)]\)\@=/ contains=@jsFlowCluster +syntax region jsFlowArgumentDef contained start=/:/ end=/\%(\s*[,)]\|=>\@!\)\@=/ contains=@jsFlowCluster syntax region jsFlowArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster syntax region jsFlowObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster syntax region jsFlowParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster @@ -12,14 +12,16 @@ syntax region jsFlowArrowArguments contained matchgroup=jsFlowNoise start=/(/ syntax match jsFlowArrow contained /=>/ skipwhite skipempty nextgroup=jsFlowType,jsFlowTypeCustom,jsFlowParens syntax match jsFlowMaybe contained /?/ skipwhite skipempty nextgroup=jsFlowType,jsFlowTypeCustom,jsFlowParens,jsFlowArrowArguments syntax match jsFlowObjectKey contained /[0-9a-zA-Z_$?]*\(\s*:\)\@=/ contains=jsFunctionKey,jsFlowMaybe skipwhite skipempty nextgroup=jsObjectValue containedin=jsObject +syntax match jsFlowOrOperator contained /|/ skipwhite skipempty nextgroup=@jsFlowCluster syntax match jsFlowReturn contained /:\s*/ contains=jsFlowNoise skipwhite skipempty nextgroup=@jsFlowReturnCluster -syntax region jsFlowReturnObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock -syntax region jsFlowReturnArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock -syntax region jsFlowReturnParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock -syntax match jsFlowReturnKeyword contained /\k\+/ contains=jsFlowType,jsFlowTypeCustom skipwhite skipempty nextgroup=jsFlowReturnGroup,jsFuncBlock +syntax region jsFlowReturnObject contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp +syntax region jsFlowReturnArray contained matchgroup=jsFlowNoise start=/\[/ end=/\]/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp +syntax region jsFlowReturnParens contained matchgroup=jsFlowNoise start=/(/ end=/)/ contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp +syntax match jsFlowReturnKeyword contained /\k\+/ contains=jsFlowType,jsFlowTypeCustom skipwhite skipempty nextgroup=jsFlowReturnGroup,jsFuncBlock,jsFlowReturnOrOp syntax match jsFlowReturnMaybe contained /?/ skipwhite skipempty nextgroup=jsFlowReturnKeyword -syntax region jsFlowReturnGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock +syntax region jsFlowReturnGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncBlock,jsFlowReturnOrOp +syntax match jsFlowReturnOrOp contained /\s*|\s*/ skipwhite skipempty nextgroup=@jsFlowReturnCluster syntax region jsFlowFunctionGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster skipwhite skipempty nextgroup=jsFuncArgs syntax region jsFlowClassGroup contained matchgroup=jsFlowNoise start=// contains=@jsFlowCluster skipwhite skipempty nextgroup=jsClassBlock @@ -39,8 +41,8 @@ syntax region jsFlowDeclareBlock contained matchgroup=jsFlowNoise start=/{/ e syntax region jsFlowInterfaceBlock contained matchgroup=jsFlowNoise start=/{/ end=/}/ contains=jsObjectKey,jsObjectKeyString,jsObjectKeyComputed,jsObjectSeparator,jsObjectFuncName,jsObjectMethodType,jsGenerator,jsComment,jsObjectStringKey,jsSpreadExpression,jsFlowNoise keepend -syntax cluster jsFlowReturnCluster contains=jsFlowNoise,jsFlowReturnObject,jsFlowReturnArray,jsFlowReturnKeyword,jsFlowReturnGroup,jsFlowReturnMaybe -syntax cluster jsFlowCluster contains=jsFlowArray,jsFlowObject,jsFlowNoise,jsFlowTypeof,jsFlowType,jsFlowGroup,jsFlowArrowArguments,jsFlowMaybe,jsFlowParens +syntax cluster jsFlowReturnCluster contains=jsFlowNoise,jsFlowReturnObject,jsFlowReturnArray,jsFlowReturnKeyword,jsFlowReturnGroup,jsFlowReturnMaybe,jsFlowReturnOrOp +syntax cluster jsFlowCluster contains=jsFlowArray,jsFlowObject,jsFlowNoise,jsFlowTypeof,jsFlowType,jsFlowGroup,jsFlowArrowArguments,jsFlowMaybe,jsFlowParens,jsFlowOrOperator if version >= 508 || !exists("did_javascript_syn_inits") if version < 508 @@ -79,5 +81,7 @@ if version >= 508 || !exists("did_javascript_syn_inits") HiLink jsFlowInterface PreProc HiLink jsFlowNoise Noise HiLink jsFlowObjectKey jsObjectKey + HiLink jsFlowOrOperator PreProc + HiLink jsFlowReturnOrOp jsFlowOrOperator delcommand HiLink endif From 13610e67c47529e3745c76e4b963cc97fdec9486 Mon Sep 17 00:00:00 2001 From: Amadeus Demarzi Date: Wed, 27 Jul 2016 11:35:24 -0700 Subject: [PATCH 59/63] Updating indent top comments --- indent/javascript.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 441f1b97..18ad9630 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -1,5 +1,7 @@ " Vim indent file " Language: Javascript +" Maintainer: vim-javascript community +" URL: https://github.com/pangloss/vim-javascript " Acknowledgement: Based off of vim-ruby maintained by Nikolai Weibull http://vim-ruby.rubyforge.org " Only load this indent file when no other was loaded. @@ -179,7 +181,7 @@ function GetJavascriptIndent() if line =~ s:line_pre . '[])}]' return indent(num) end - let inb = num == 0 ? 1 : s:Onescope(num, strpart(getline(num),0,b:js_cache[2] - 1),1) + let inb = num == 0 ? 1 : s:Onescope(num, strpart(getline(num),0,b:js_cache[2] - 1),1) let switch_offset = (!inb || num == 0) || expand("") != 'switch' ? 0 : &cino !~ ':' || !has('float') ? s:sw() : \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (match(&cino,'.*:\zs[^,]*s') ? s:sw() : 1)) if ((line =~ g:javascript_opfirst || From 33833cc48f67540632a2654cab36efc205cf76ac Mon Sep 17 00:00:00 2001 From: bounceme Date: Wed, 27 Jul 2016 19:06:40 -0700 Subject: [PATCH 60/63] allow for line breaks before blocks (#575) ``` if () a=b ``` --- indent/javascript.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 18ad9630..1b3706b6 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -73,9 +73,9 @@ function s:Onescope(lnum,text,add) return a:text =~ '\%(\' . (a:add ? '\|try\|finally' : '' ) . '\)\C' . s:line_term || \ (cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1 && \ s:lookForParens('(', ')', 'cbW', 100) > 0 && - \ cursor(line('.'),match( ' ' . strpart(getline(line('.')),0,col('.') - 1), - \ (a:add ? '\K\k*' : - \ '\<\%(else\|for\%(\s+each\)\=\|function\*\=\%(\s\+\K\k*\)\=\|if\|let\|switch\|while\|with\)\C') . s:line_term)) > -1) && + \ search((a:add ? '\K\k*' : + \ '\<\%(else\|for\%(\s+each\)\=\|function\*\=\%(\s\+\K\k*\)\=\|if\|let\|switch\|while\|with\)\C') . + \ '\_s*\%#','bW')) && \ (a:add || (expand("") == 'while' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) endfunction From 9e2c10e32e8fada2019a27f34ce494f1b36d3862 Mon Sep 17 00:00:00 2001 From: bounceme Date: Wed, 27 Jul 2016 20:11:43 -0700 Subject: [PATCH 61/63] remove else not supposed to be there --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 1b3706b6..78e96026 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -74,7 +74,7 @@ function s:Onescope(lnum,text,add) \ (cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1 && \ s:lookForParens('(', ')', 'cbW', 100) > 0 && \ search((a:add ? '\K\k*' : - \ '\<\%(else\|for\%(\s+each\)\=\|function\*\=\%(\s\+\K\k*\)\=\|if\|let\|switch\|while\|with\)\C') . + \ '\<\%(for\%(\s+each\)\=\|function\*\=\%(\s\+\K\k*\)\=\|if\|let\|switch\|while\|with\)\C') . \ '\_s*\%#','bW')) && \ (a:add || (expand("") == 'while' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) endfunction From 1d32e38b0a875263a9fb4cbe60787df48f2b6b12 Mon Sep 17 00:00:00 2001 From: bounceme Date: Wed, 27 Jul 2016 21:34:07 -0700 Subject: [PATCH 62/63] regex for word boundary --- indent/javascript.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index 78e96026..eab6dbd5 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -70,7 +70,7 @@ endif let g:javascript_continuation .= s:line_term function s:Onescope(lnum,text,add) - return a:text =~ '\%(\' . (a:add ? '\|try\|finally' : '' ) . '\)\C' . s:line_term || + return a:text =~ '\%(\' . (a:add ? '\|\ -1 && \ s:lookForParens('(', ')', 'cbW', 100) > 0 && \ search((a:add ? '\K\k*' : From 6d70fab417009adb22062962c853fb8648d044b0 Mon Sep 17 00:00:00 2001 From: bounceme Date: Thu, 28 Jul 2016 00:24:25 -0700 Subject: [PATCH 63/63] fix c-style continuation (#576) * fix c-style continuation --- indent/javascript.vim | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/indent/javascript.vim b/indent/javascript.vim index eab6dbd5..6844dc2f 100644 --- a/indent/javascript.vim +++ b/indent/javascript.vim @@ -71,16 +71,15 @@ let g:javascript_continuation .= s:line_term function s:Onescope(lnum,text,add) return a:text =~ '\%(\' . (a:add ? '\|\ -1 && \ s:lookForParens('(', ')', 'cbW', 100) > 0 && - \ search((a:add ? '\K\k*' : - \ '\<\%(for\%(\s+each\)\=\|function\*\=\%(\s\+\K\k*\)\=\|if\|let\|switch\|while\|with\)\C') . - \ '\_s*\%#','bW')) && + \ search((a:add ? '\%(function\*\|[A-Za-z_$][0-9A-Za-z_$]*\)\C' : + \ '\<\%(for\%(\s+each\)\=\|if\|let\|switch\|while\|with\)\C') . '\_s*\%#','bW')) && \ (a:add || (expand("") == 'while' ? !s:lookForParens('\\C', '\\C','bW',100) : 1)) endfunction " Auxiliary Functions {{{2 -" ====================== " Check if the character at lnum:col is inside a string, comment, or is ascii. function s:IsSyn(lnum, col, reg) @@ -88,7 +87,7 @@ function s:IsSyn(lnum, col, reg) endfunction " Find line above 'lnum' that isn't empty, in a comment, or in a string. -function s:PrevNonBlankNonString(lnum) +function s:PrevCodeLine(lnum) let lnum = prevnonblank(a:lnum) while lnum > 0 if !s:IsSyn(lnum, matchend(getline(lnum), '^\s*[^''"]'),'') @@ -133,7 +132,7 @@ function GetJavascriptIndent() " previous nonblank line number let prevline = prevnonblank(v:lnum - 1) " previous line of code - let lnum = s:PrevNonBlankNonString(v:lnum - 1) + let lnum = s:PrevCodeLine(v:lnum - 1) if lnum == 0 return 0 endif