From 15c6909bb198ca8a1a22405a4a7e96357716e57e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 22 Mar 2024 07:31:43 +0800 Subject: [PATCH] vim-patch:35e6f4ca27c8 (#27973) runtime(vim): Update base-syntax, improve function definition highlighting (vim/vim#14203) Improve function definition highlighting. - Match bang and function modifiers - abort etc. - Only match valid scope modifiers. - Match listing commands. - Don't match ex commands in function names. - Split function syntax groups into :func and :def subgroups. - Match Vim9-script parameter and return types. - Limit legacy-script and Vim9-script comments to :func and :def definitions, respectively. https://github.com/vim/vim/commit/35e6f4ca27c8115c606f265e4b09e11db01c970d Omit the vimFunctionError change as it's a whitespace-only change and will likely be superseded by later patches. Co-authored-by: dkearns --- runtime/syntax/vim.vim | 80 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 14 deletions(-) diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim index d5761087e0..d37c54a63f 100644 --- a/runtime/syntax/vim.vim +++ b/runtime/syntax/vim.vim @@ -155,7 +155,7 @@ 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,@vimEcho,vimExecute,vimIsCommand,vimExtCmd,vimFunction,vimGlobal,vimHighlight,vimLet,vimMap,vimMark,vimNotFunc,vimNorm,vimSet,vimSyntax,vimUnlet,vimUnmap,vimUserCmd,vimMenu,vimMenutranslate +syn cluster vimCmdList contains=vimAbb,vimAddress,vimAutoCmd,vimAugroup,vimBehave,vimDef,@vimEcho,vimEnddef,vimEndfunction,vimExecute,vimIsCommand,vimExtCmd,vimFor,vimFunction,vimGlobal,vimHighlight,vimLet,vimMap,vimMark,vimNotFunc,vimNorm,vimSet,vimSyntax,vimUnlet,vimUnmap,vimUserCmd,vimMenu,vimMenutranslate syn match vimCmdSep "[:|]\+" skipwhite nextgroup=@vimCmdList,vimSubst1 syn match vimIsCommand "\<\%(\h\w*\|[23]mat\%[ch]\)\>" contains=vimCommand syn match vimVar contained "\<\h[a-zA-Z0-9#_]*\>" @@ -215,7 +215,7 @@ syn keyword vimAugroupKey contained aug[roup] skipwhite nextgroup=vimAugroupBan " Operators: {{{2 " ========= -syn cluster vimOperGroup contains=vimEnvvar,vimFunc,vimFuncVar,vimOper,vimOperParen,vimNumber,vimString,vimType,vimRegister,@vimContinue,vim9Comment,vimVar +syn cluster vimOperGroup contains=vimEnvvar,vimFunc,vimFuncVar,vimOper,vimOperParen,vimNumber,vimString,vimRegister,@vimContinue,vim9Comment,vimVar syn match vimOper "||\|&&\|[-+*/%.!]" skipwhite nextgroup=vimString,vimSpecFile syn match vimOper "\%#=1\(==\|!=\|>=\|<=\|=\~\|!\~\|>\|<\|=\|!\~#\)[?#]\{0,2}" skipwhite nextgroup=vimString,vimSpecFile syn match vimOper "\(\" skipwhite nextgroup=vimString,vimSpecFile @@ -227,25 +227,67 @@ endif " Functions : Tag is provided for those who wish to highlight tagged functions {{{2 " ========= -syn cluster vimFuncList contains=vimCommand,vimFunctionError,vimFuncKey,Tag,vimFuncSID -syn cluster vimFuncBodyList contains=@vimCmdList,vimCmplxRepeat,vimComment,vim9Comment,vimContinue,vimCtrlChar,vimEnvvar,vimFBVar,vimFunc,vimFunction,vimFuncVar,vimLetHereDoc,vimLineComment,vimNotation,vimNotFunc,vimNumber,vimOper,vimOperParen,vimRegion,vimRegister,vimSearch,vimSpecFile,vimString,vimSubst -syn match vimFunction "\<\(fu\%[nction]\)!\=\s\+\%(<[sS][iI][dD]>\|[sSgGbBwWtTlL]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)*\ze\s*(" contains=@vimFuncList nextgroup=vimFuncBody -syn match vimFunction "\" skipwhite nextgroup=vimCmdSep,vimComment,vimFuncPattern contains=vimFuncKey +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 skipnl nextgroup=vimFuncBody,vimEndfunction +syn match vimDefComment contained "#.*" skipwhite skipnl nextgroup=vimDefBody,vimEnddef + +syn match vimFuncBang contained "!" +syn match vimFuncSID contained "\c" +syn match vimFuncSID contained "\<[sg]:" +syn keyword vimFuncKey contained fu[nction] +syn keyword vimDefKey contained def + +syn region vimFuncParams contained matchgroup=Delimiter start="(" skip=+\n\s*\\\|\n\s*"\\ + end=")" skipwhite skipnl nextgroup=vimFuncBody,vimFuncComment,vimEndfunction,vimFuncMod contains=vimFuncParam,@vimContinue +syn region vimDefParams contained matchgroup=Delimiter start="(" end=")" skipwhite skipnl nextgroup=vimDefBody,vimDefComment,vimEnddef,vimReturnType contains=vimDefParam,vim9Comment +syn match vimFuncParam contained "\<\h\w*\>\|\.\.\." skipwhite nextgroup=vimFuncParamEquals +syn match vimDefParam contained "\<\h\w*\>" skipwhite nextgroup=vimParamType,vimFuncParamEquals + +syn match vimFuncParamEquals contained "=" skipwhite nextgroup=@vimExprList +syn match vimFuncMod contained "\<\%(abort\|closure\|dict\|range\)\>" skipwhite skipnl nextgroup=vimFuncBody,vimFuncComment,vimEndfunction,vimFuncMod + +syn region vimFuncBody contained start="^" matchgroup=vimCommand end="\" contains=@vimFuncBodyList +syn region vimDefBody contained start="^" matchgroup=vimCommand end="\" contains=@vimDefBodyList + +syn match vimEndfunction "\" +syn match vimEnddef "\" if exists("g:vimsyn_folding") && g:vimsyn_folding =~# 'f' - syn region vimFuncBody contained fold start="\ze\s*(" matchgroup=vimCommand end="\<\(endf\>\|endfu\%[nction]\>\|enddef\>\)" contains=@vimFuncBodyList -else - syn region vimFuncBody contained start="\ze\s*(" matchgroup=vimCommand end="\<\(endf\>\|endfu\%[nction]\>\|enddef\>\)" contains=@vimFuncBodyList + syn region vimFuncFold start="\!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)\+\s*(" end="\" contains=vimFunction fold keepend transparent + syn region vimFuncFold start="\!\=\s*\%(<[sS][iI][dD]>\|[sg]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)\+(" end="\" contains=vimDef fold keepend transparent + syn region vimFuncFold start="\\|\" syn match vimFuncBlank contained "\s\+" syn keyword vimPattern contained start skip end +" Types: {{{2 +" ===== " vimTypes : new for vim9 -syn match vimType ":\s*\zs\<\(bool\|number\|float\|string\|blob\|list<\|dict<\|job\|channel\|func\)\>" +syn region vimReturnType contained start=":\s" end="$" matchgroup=vim9Comment end="\ze#" skipwhite skipnl nextgroup=vimDefBody,vimDefComment,vimEnddef contains=vimTypeSep transparent +syn match vimParamType contained ":\s\+\a" skipwhite skipnl nextgroup=vimFuncParamEquals contains=vimTypeSep,@vimType + +syn match vimTypeSep contained ":\s\@=" skipwhite nextgroup=@vimType +syn keyword vimType contained any blob bool channel float job number string void +syn match vimType contained "\" +syn region vimCompoundType contained matchgroup=vimType start="\" + +syn cluster vimType contains=vimType,vimCompoundType,vimUserType " Keymaps: (Vim Project Addition) {{{2 " ======= @@ -454,7 +496,7 @@ syn case ignore syn keyword vimEchohlNone contained none syn case match -syn cluster vimEcho contains=vimEcho.* +syn cluster vimEcho contains=vimEcho,vimEchohl syn region vimExecute matchgroup=vimCommand start="\" skip=+\\|\|\n\s*\\\|\n\s*"\\ + matchgroup=vimCmdSep end="|" excludenl end="$" contains=@vimContinue,@vimExprList transparent @@ -977,11 +1019,16 @@ if !exists("skip_vim_syntax_inits") hi def link vimContinue Special hi def link vimContinueComment vimComment hi def link vimCtrlChar SpecialChar + hi def link vimDefComment vimComment + hi def link vimDefKey vimCommand + hi def link vimDefParam vimVar hi def link vimEcho vimCommand hi def link vimEchohlNone vimGroup hi def link vimEchohl vimCommand hi def link vimElseIfErr Error hi def link vimElseif vimCondHL + hi def link vimEndfunction vimCommand + hi def link vimEnddef vimCommand hi def link vimEnvvar PreProc hi def link vimError Error hi def link vimEscape Special @@ -992,8 +1039,13 @@ if !exists("skip_vim_syntax_inits") hi def link vimFor vimCommand hi def link vimFTCmd vimCommand hi def link vimFTOption vimSynType + hi def link vimFuncBang vimBang + hi def link vimFuncComment vimComment hi def link vimFuncKey vimCommand hi def link vimFuncName Function + hi def link vimFuncMod Special + hi def link vimFuncParam vimVar + hi def link vimFuncParamEquals vimOper hi def link vimFuncSID Special hi def link vimFuncVar Identifier hi def link vimGroupAdd vimSynOption