Skip to content

Commit c8db23b

Browse files
committed
Improvements to function, name and arguments
This commit is a first pass at adding a number of improvements to functions and how they are detected. Function declarations now have a higher granularity to expose the function keyword, the name, the parenthesis, argument definitions, and commas within the argument definitions. I also added a new block type called jsFuncBlock which is unique from jsBlock that defines a block region for function definitions. This also ultimately differentiates function definitions from jsFuncCall.
1 parent 1ab789c commit c8db23b

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

syntax/javascript.vim

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ syntax sync fromstart
3434
syntax match jsNoise /\%(:\|,\|\;\|\.\)/
3535

3636
"" Program Keywords
37-
syntax keyword jsType function
3837
syntax keyword jsStorageClass const var let
3938
syntax keyword jsOperator delete instanceof typeof void new in
4039
syntax match jsOperator /\(!\||\|&\|+\|-\|<\|>\|=\|%\|\/\|*\|\~\|\^\)/
@@ -185,9 +184,10 @@ endif "DOM/HTML/CSS
185184
"" Code blocks
186185
syntax cluster jsExpression contains=jsComment,jsLineComment,jsDocComment,jsStringD,jsStringS,jsRegexpString,jsNumber,jsFloat,jsThis,jsType,jsOperator,jsBoolean,jsNull,jsFunction,jsGlobalObjects,jsExceptions,jsFutureKeys,jsDomErrNo,jsDomNodeConsts,jsHtmlEvents,jsDotNotation,jsBracket,jsParen,jsBlock,jsParenError,jsFuncCall,jsUndefined,jsNan,jsKeyword,jsStorageClass,jsPrototype,jsBuiltins
187186
syntax cluster jsAll contains=@jsExpression,jsLabel,jsConditional,jsRepeat,jsBranch,jsReturn,jsStatement,jsTernaryIf,jsNoise,jsException
188-
syntax region jsBracket matchgroup=jsBrackets start="\[" end="\]" contains=@jsAll,jsParensErrB,jsParensErrC,jsBracket,jsParen,jsBlock,@htmlPreproc
189-
syntax region jsParen matchgroup=jsParens start="(" end=")" contains=@jsAll,jsParensErrA,jsParensErrC,jsParen,jsBracket,jsBlock,@htmlPreproc
190-
syntax region jsBlock matchgroup=jsBlocks start="{" end="}" contains=@jsAll,jsParensErrA,jsParensErrB,jsParen,jsBracket,jsBlock,@htmlPreproc
187+
syntax region jsBracket matchgroup=jsBrackets start="\[" end="\]" contains=@jsAll,jsParensErrB,jsParensErrC,jsBracket,jsParen,jsBlock,@htmlPreproc
188+
syntax region jsParen matchgroup=jsParens start="(" end=")" contains=@jsAll,jsParensErrA,jsParensErrC,jsParen,jsBracket,jsBlock,@htmlPreproc
189+
syntax region jsBlock matchgroup=jsBlocks start="{" end="}" contains=@jsAll,jsParensErrA,jsParensErrB,jsParen,jsBracket,jsBlock,@htmlPreproc
190+
syntax region jsFuncBlock matchgroup=jsFuncBlocks start="{" end="}" contains=@jsAll,jsParensErrA,jsParensErrB,jsParen,jsBracket,jsBlock,@htmlPreproc contained
191191
syntax region jsTernaryIf matchgroup=jsTernaryIfOperator start=+?+ end=+:+ contains=@jsExpression
192192

193193
"" catch errors caused by wrong parenthesis
@@ -203,18 +203,15 @@ if main_syntax == "javascript"
203203
endif
204204

205205
if g:javascript_conceal == 1
206-
syntax match jsFunction /\<function\>/ nextgroup=jsFuncName skipwhite conceal cchar=ƒ
206+
syntax match jsFunction /\<function\>/ nextgroup=jsFuncName,jsFuncArgs skipwhite conceal cchar=ƒ
207207
else
208-
syntax match jsFunction /\<function\>/ nextgroup=jsFuncName skipwhite
208+
syntax match jsFunction /\<function\>/ nextgroup=jsFuncName,jsFuncArgs skipwhite
209209
endif
210210

211211
syntax match jsOpAssign /=\@<!=/ nextgroup=jsFuncBlock skipwhite skipempty
212-
syntax match jsFuncName contained /\<[a-zA-Z_$][0-9a-zA-Z_$]*/
213-
214-
"" Fold control
215-
if exists("b:javascript_fold")
216-
syntax region jsFuncBlock contained matchgroup=jsFuncBlock start="{" end="}" contains=@jsAll,jsParensErrA,jsParensErrB,jsParen,jsBracket,jsBlock fold
217-
endif
212+
syntax match jsFuncName contained /\<[a-zA-Z_$][0-9a-zA-Z_$]*/ nextgroup=jsFuncArgs skipwhite
213+
syntax region jsFuncArgs contained matchgroup=jsFuncParens start='(' end=')' contains=jsFuncArgCommas nextgroup=jsFuncBlock keepend skipwhite
214+
syntax match jsFuncArgCommas contained ','
218215

219216
" Define the default highlighting.
220217
" For version 5.7 and earlier: only when not done already
@@ -261,6 +258,9 @@ if version >= 508 || !exists("did_javascript_syn_inits")
261258
HiLink jsFunction Type
262259
HiLink jsFuncName Function
263260
HiLink jsFuncCall Function
261+
HiLink jsFuncParens Function
262+
HiLink jsFuncArgCommas Function
263+
HiLink jsFuncArgs Function
264264
HiLink jsError Error
265265
HiLink jsParensError Error
266266
HiLink jsParensErrA Error

0 commit comments

Comments
 (0)