diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index 9d7dbd39c4..b9daff84f3 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -3493,7 +3493,7 @@ This option is disabled by default. Some folding is now supported with when 'foldmethod' is set to "syntax": > g:vimsyn_folding == 0 or doesn't exist: no syntax-based folding - g:vimsyn_folding =~ 'a' : augroups + g:vimsyn_folding =~ 'a' : fold augroups g:vimsyn_folding =~ 'f' : fold functions g:vimsyn_folding =~ 'h' : fold heredocs g:vimsyn_folding =~ 'l' : fold Lua script diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim index 6e38076d35..3ad04e2957 100644 --- a/runtime/syntax/vim.vim +++ b/runtime/syntax/vim.vim @@ -74,12 +74,22 @@ syn case match com! -nargs=* Vim9 execute s:vim9script ? "" : "contained" com! -nargs=* VimL execute s:vim9script ? "contained" : "" -if exists("g:vimsyn_folding") && g:vimsyn_folding =~# '[afhHlmpPrt]' +if exists("g:vimsyn_folding") && g:vimsyn_folding =~# '[acefhiHlmpPrt]' if g:vimsyn_folding =~# 'a' com! -nargs=* VimFolda fold else com! -nargs=* VimFolda endif + if g:vimsyn_folding =~# 'c' + com! -nargs=* VimFoldc fold + else + com! -nargs=* VimFoldc + endif + if g:vimsyn_folding =~# 'e' + com! -nargs=* VimFolde fold + else + com! -nargs=* VimFolde + endif if g:vimsyn_folding =~# 'f' com! -nargs=* VimFoldf fold else @@ -95,6 +105,11 @@ if exists("g:vimsyn_folding") && g:vimsyn_folding =~# '[afhHlmpPrt]' else com! -nargs=* VimFoldH endif + if g:vimsyn_folding =~# 'i' + com! -nargs=* VimFoldi fold + else + com! -nargs=* VimFoldi + endif if g:vimsyn_folding =~# 'l' com! -nargs=* VimFoldl fold else @@ -127,7 +142,10 @@ if exists("g:vimsyn_folding") && g:vimsyn_folding =~# '[afhHlmpPrt]' endif else com! -nargs=* VimFolda + com! -nargs=* VimFoldc + com! -nargs=* VimFolde com! -nargs=* VimFoldf + com! -nargs=* VimFoldi com! -nargs=* VimFoldh com! -nargs=* VimFoldH com! -nargs=* VimFoldl @@ -177,8 +195,8 @@ syn match vimNumber '\%(^\|\A\)\zs#\x\{6}' skipwhite nextgroup=vimGlobal,vimSub syn case match " All vimCommands are contained by vimIsCommand. {{{2 -syn cluster vimCmdList contains=vimAbb,vimAddress,vimAutoCmd,vimAugroup,vimBehave,vimCall,vimCatch,vimConst,vimDef,vimDelcommand,@vimEcho,vimEnddef,vimEndfunction,vimExecute,vimIsCommand,vimExtCmd,vimFor,vimFunction,vimFuncFold,vimGlobal,vimHighlight,vimLet,vimLoadkeymap,vimMap,vimMark,vimMatch,vimNotFunc,vimNorm,vimSet,vimSleep,vimSyntax,vimThrow,vimUnlet,vimUnmap,vimUserCmd,vimMenu,vimMenutranslate,@vim9CmdList -syn cluster vim9CmdList contains=vim9Const,vim9Final,vim9For,vim9Var +syn cluster vimCmdList contains=vimAbb,vimAddress,vimAutoCmd,vimAugroup,vimBehave,vimCall,vimCatch,vimConst,vimDef,vimDefFold,vimDelcommand,@vimEcho,vimEnddef,vimEndfunction,vimExecute,vimIsCommand,vimExtCmd,vimFor,vimFunction,vimFuncFold,vimGlobal,vimHighlight,vimLet,vimLoadkeymap,vimMap,vimMark,vimMatch,vimNotFunc,vimNormal,vimSet,vimSleep,vimSyntax,vimThrow,vimUnlet,vimUnmap,vimUserCmd,vimMenu,vimMenutranslate,@vim9CmdList +syn cluster vim9CmdList contains=vim9Class,vim9Const,vim9Enum,vim9Export,vim9Final,vim9For,vim9Interface,vim9Type,vim9Var syn match vimCmdSep "[:|]\+" skipwhite nextgroup=@vimCmdList,vimSubst1 syn match vimIsCommand "\<\%(\h\w*\|[23]mat\%[ch]\)\>" contains=vimCommand syn match vimBang contained "!" @@ -189,6 +207,7 @@ syn match vimVar "\s\zs&t_\S[a-zA-Z0-9]\>" syn match vimVar "\s\zs&t_k;" syn match vimFBVar contained "\<[bwglstav]:\h[a-zA-Z0-9#_]*\>" syn keyword vimCommand contained in +syn match vimBang contained "!" syn cluster vimExprList contains=vimEnvvar,vimFunc,vimNumber,vimOper,vimOperParen,vimLetRegister,vimString,vimVar,@vim9ExprList syn cluster vim9ExprList contains=vim9Boolean,vim9Null @@ -220,6 +239,12 @@ syn keyword vimThrow th[row] skipwhite nextgroup=@vimExprList syn keyword vimCatch cat[ch] skipwhite nextgroup=vimCatchPattern syn region vimCatchPattern contained matchgroup=Delimiter start="\z([!#$%&'()*+,-./:;<=>?@[\]^_`{}~]\)" skip="\\\\\|\\\z1" end="\z1" contains=@vimSubstList oneline +" Export {{{2 +" ====== +if s:vim9script + syn keyword vim9Export export skipwhite nextgroup=vim9Abstract,vim9ClassBody,vim9Const,vim9Def,vim9EnumBody,vim9Final,vim9InterfaceBody,vim9Type,vim9Var +endif + " Filetypes {{{2 " ========= syn match vimFiletype "\" skipwhite nextgroup=vimCmdSep,vimCommen syn match vimDef "\" skipwhite nextgroup=vimCmdSep,vimComment,vimFuncPattern contains=vimDefKey syn match vimFunction "\!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)\+" contains=@vimFuncList skipwhite nextgroup=vimFuncParams -syn match vimDef "\!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)\+" contains=@vimDefList nextgroup=vimDefParams syn match vimFuncComment contained +".*+ skipwhite skipempty nextgroup=vimFuncBody,vimEndfunction @@ -300,9 +324,8 @@ syn match vimEndfunction "\" skipwhite nextgroup=vimCmdSep,vim syn match vimEnddef "\" skipwhite nextgroup=vimCmdSep,vim9Comment,vimCommentError if exists("g:vimsyn_folding") && g:vimsyn_folding =~# 'f' - syn region vimFuncFold start="\!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)\+\s*(" end="\" contains=vimFunction fold keepend extend transparent - syn region vimFuncFold start="\!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\)\+(" end="\" contains=vimDef fold keepend extend transparent - syn region vimFuncFold start="\" @@ -323,6 +346,100 @@ syn match vimUserType contained "\<\u\w*\>" syn cluster vimType contains=vimType,vimCompoundType,vimUserType +" Classes, Enums And Interfaces: {{{2 +" ============================= + +if s:vim9script + " Methods {{{3 + syn match vim9MethodDef contained "\" skipwhite nextgroup=vim9MethodDefName + syn match vim9MethodDefName contained "\<\h\w*\>" nextgroup=vim9MethodDefParams contains=@vim9MethodName + syn region vim9MethodDefParams contained + \ matchgroup=Delimiter start="(" end=")" + \ skipwhite skipnl nextgroup=vim9MethodDefBody,vimDefComment,vimEnddef,vim9MethodDefReturnType,vimCommentError + \ contains=vimDefParam,vim9Comment,vimFuncParamEquals + syn region vim9MethodDefReturnType contained + \ start=":\s" end="$" matchgroup=vim9Comment end="\ze[#"]" + \ skipwhite skipnl nextgroup=vim9MethodDefBody,vimDefComment,vimCommentError + \ contains=vimTypeSep + \ transparent + syn region vim9MethodDefBody contained + \ start="^.\=" matchgroup=vimCommand end="\" + \ skipwhite nextgroup=vimCmdSep,vim9Comment,vimCommentError + \ contains=@vim9MethodDefBodyList + + syn cluster vim9MethodDefBodyList contains=@vimDefBodyList,vim9This,vim9Super + + if !exists("g:vimsyn_noerror") && !exists("g:vimsyn_novimfunctionerror") + syn match vim9MethodNameError contained "\<[a-z0-9]\i\>" + endif + syn match vim9MethodName contained "\" + syn keyword vim9MethodName contained empty len string + + syn cluster vim9MethodName contains=vim9MethodName,vim9MethodNameError + + if exists("g:vimsyn_folding") && g:vimsyn_folding =~# 'f' + syn region vim9MethodDefFold contained start="\%(^\s*\%(:\=static\s\+\)\=\)\@16<=:\=def\s\+\h\i*(" end="^\s*:\=enddef\>" contains=vim9MethodDef fold keepend extend transparent + syn region vim9MethodDefFold contained start="^\s*:\=def\s\+new\i*(" end="^\s*:\=enddef\>" contains=vim9MethodDef fold keepend extend transparent + endif + + syn cluster vim9MethodDef contains=vim9MethodDef,vim9MethodDefFold + + " Classes {{{3 + syn cluster vim9ClassBodyList contains=vim9Abstract,vim9Class,vim9Comment,vim9LineComment,@vim9Continue,@vimExprList,vim9Extends,vim9Implements,@vim9MethodDef,vim9Public,vim9Static,vim9Const,vim9Final,vim9This,vim9Super,vim9Var + + syn match vim9Class contained "\" skipwhite nextgroup=vim9ClassName + syn match vim9ClassName contained "\<\u\w*\>" skipwhite skipnl nextgroup=vim9Extends,vim9Implements + syn match vim9SuperClass contained "\<\u\w*\>" skipwhite skipnl nextgroup=vim9Implements + syn match vim9ImplementedInterface contained "\<\u\w*\>" skipwhite skipnl nextgroup=vim9InterfaceListComma,vim9Extends + syn match vim9InterfaceListComma contained "," skipwhite skipnl nextgroup=vim9ImplementedInterface + syn keyword vim9Abstract abstract skipwhite skipnl nextgroup=vim9ClassBody,vim9AbstractDef + syn keyword vim9Extends contained extends skipwhite skipnl nextgroup=vim9SuperClass + syn keyword vim9Implements contained implements skipwhite skipnl nextgroup=vim9ImplementedInterface + syn keyword vim9Public contained public + syn keyword vim9Static contained static + syn keyword vim9This contained this + syn keyword vim9Super contained super + + VimFoldc syn region vim9ClassBody start="\" matchgroup=vimCommand end="\" contains=@vim9ClassBodyList transparent + + " Enums {{{3 + syn cluster vim9EnumBodyList contains=vim9Comment,vim9LineComment,@vim9Continue,vim9Enum,vim9Implements,@vim9MethodDef,vim9Const,vim9Final,vim9Var + + syn match vim9Enum contained "\" skipwhite nextgroup=vim9EnumName + syn match vim9EnumName contained "\<\u\w*\>" skipwhite skipnl nextgroup=vim9Implements + + VimFolde syn region vim9EnumBody start="\" matchgroup=vimCommand end="\" contains=@vim9EnumBodyList transparent + + " Interfaces {{{3 + " TODO: limit to decl only - no init values + syn cluster vim9InterfaceBodyList contains=vim9Comment,vim9LineComment,@vim9Continue,vim9Extends,vim9Interface,vim9AbstractDef,vim9Var + + syn match vim9Interface contained "\" skipwhite nextgroup=vim9InterfaceName + syn match vim9InterfaceName contained "\<\u\w*\>" skipwhite skipnl nextgroup=vim9Extends + + syn keyword vim9AbstractDef contained def skipwhite nextgroup=vim9AbstractDefName + syn match vim9AbstractDefName contained "\<\h\w*\>" skipwhite nextgroup=vim9AbstractDefParams contains=@vim9MethodName + syn region vim9AbstractDefParams contained + \ matchgroup=Delimiter start="(" end=")" + \ skipwhite skipnl nextgroup=vimDefComment,vim9AbstractDefReturnType,vimCommentError + \ contains=vimDefParam,vim9Comment,vimFuncParamEquals + syn region vim9AbstractDefReturnType contained + \ start=":\s" end="$" matchgroup=vim9Comment end="\ze[#"]" + \ skipwhite skipnl nextgroup=vimDefComment,vimCommentError + \ contains=vimTypeSep + \ transparent + + VimFoldi syn region vim9InterfaceBody start="\" matchgroup=vimCommand end="\" contains=@vim9InterfaceBodyList transparent + + " type {{{3 + syn match vim9Type "\" skipwhite nextgroup=vim9TypeAlias,vim9TypeAliasError + syn match vim9TypeAlias contained "\<\u\w*\>" skipwhite nextgroup=vim9TypeEquals + syn match vim9TypeEquals contained "=" skipwhite nextgroup=@vimType + if !exists("g:vimsyn_noerror") && !exists("g:vimsyn_notypealiaserror") + syn match vim9TypeAliasError contained "\<\U\w*" + endif +endif + " Keymaps: {{{2 " ======= @@ -541,7 +658,7 @@ Vim9 syn keyword vim9Const const skipwhite nextgroup=vim9Variable,vim9VariableLi Vim9 syn keyword vim9Final final skipwhite nextgroup=vim9Variable,vim9VariableList Vim9 syn keyword vim9Var var skipwhite nextgroup=vim9Variable,vim9VariableList -syn match vim9Variable contained "\<\h\w*\>" skipwhite nextgroup=vimTypeSep,vimLetHereDoc +syn match vim9Variable contained "\<\h\w*\>" skipwhite nextgroup=vimTypeSep,vimLetHereDoc,vimOper syn region vim9VariableList contained start="\[" end="]" contains=vim9Variable,@vimContinue " For: {{{2 @@ -668,7 +785,7 @@ syn case match " (following Gautam Iyer's suggestion) " ========================== syn match vimFunc "\%(\%([sSgGbBwWtTlL]:\|<[sS][iI][dD]>\)\=\%(\w\+\.\)*\I[a-zA-Z0-9_.]*\)\ze\s*(" contains=vimFuncEcho,vimFuncName,vimUserFunc,vimExecute -syn match vimUserFunc contained "\%(\%([sSgGbBwWtTlL]:\|<[sS][iI][dD]>\)\=\%(\w\+\.\)*\I[a-zA-Z0-9_.]*\)\|\<\u[a-zA-Z0-9.]*\>\|\" contains=vimNotation +syn match vimUserFunc contained "\%(\%([sSgGbBwWtTlL]:\|<[sS][iI][dD]>\)\=\%(\w\+\.\)*\I[a-zA-Z0-9_.]*\)\|\<\u[a-zA-Z0-9.]*\>\|\" contains=vimNotation,vim9MethodName syn keyword vimFuncEcho contained ec ech echo syn match vimMap "\!\=" skipwhite nextgroup=vimNormalArg contains=vimBang +syn region vimNormalArg contained start="\S" skip=+\n\s*\\\|\n\s*["#]\\ + end="$" contains=@vimContinue " Sleep: {{{2 " ===== @@ -886,7 +1003,10 @@ syn match vimShebang "\%^#!.*" display syn match vimContinue "^\s*\zs\\" syn match vimContinueComment '^\s*\zs["#]\\ .*' -syn cluster vimContinue contains=vimContinue,vimContinueComment +syn match vim9ContinueComment "^\s*\zs#\\ .*" +syn cluster vimContinue contains=vimContinue,vimContinueComment +syn cluster vim9Continue contains=vimContinue,vim9ContinueComment + syn region vimString start="^\s*\\\z(['"]\)" skip='\\\\\|\\\z1' end="\z1" oneline keepend contains=@vimStringGroup,vimContinue syn match vimCommentTitleLeader '"\s\+'ms=s+1 contained syn match vim9CommentTitleLeader '#\s\+'ms=s+1 contained @@ -1145,6 +1265,8 @@ if !exists("skip_vim_syntax_inits") hi def link vimSynCaseError vimError hi def link vimSynFoldMethodError vimError hi def link vimBufnrWarn vimWarn + + hi def link vim9TypeAliasError vimError endif hi def link vimAbb vimCommand @@ -1255,8 +1377,9 @@ if !exists("skip_vim_syntax_inits") hi def link vimMenuPriority Number hi def link vimMenuStatus Special hi def link vimMenutranslateComment vimComment + hi def link vim9MethodName vimFuncName hi def link vimMtchComment vimComment - hi def link vimNorm vimCommand + hi def link vimNormal vimCommand hi def link vimNotation Special hi def link vimNotFunc vimCommand hi def link vimNotPatSep vimString @@ -1348,19 +1471,36 @@ if !exists("skip_vim_syntax_inits") hi def link vimVar Identifier hi def link vimWarn WarningMsg + hi def link vim9Abstract vimCommand hi def link vim9Boolean Boolean + hi def link vim9Class vimCommand hi def link vim9Comment Comment hi def link vim9CommentError vimError hi def link vim9CommentTitle PreProc hi def link vim9Const vimCommand + hi def link vim9ContinueComment vimContinueComment + hi def link vim9Enum vimCommand + hi def link vim9Export vimCommand + hi def link vim9Extends Keyword hi def link vim9Final vimCommand hi def link vim9For vimCommand + hi def link vim9Implements Keyword + hi def link vim9AbstractDef vimCommand + hi def link vim9Interface vimCommand hi def link vim9LineComment vimComment + hi def link vim9MethodDef vimCommand + hi def link vim9MethodNameError vimFunctionError hi def link vim9Null Constant - hi def link vim9Var vimCommand + hi def link vim9Public vimCommand + hi def link vim9Static vimCommand + hi def link vim9Super Identifier + hi def link vim9This Identifier + hi def link vim9Type vimCommand + hi def link vim9TypeEquals vimOper hi def link vim9Variable vimVar - hi def link vim9Vim9Script vimCommand + hi def link vim9Var vimCommand hi def link vim9Vim9ScriptArg Special + hi def link vim9Vim9Script vimCommand hi def link nvimAutoEvent vimAutoEvent hi def link nvimHLGroup vimHLGroup @@ -1374,9 +1514,12 @@ let b:current_syntax = "vim" delc Vim9 delc VimL delc VimFolda +delc VimFoldc +delc VimFolde delc VimFoldf delc VimFoldh delc VimFoldH +delc VimFoldi delc VimFoldl delc VimFoldm delc VimFoldp