Skip to content

Commit 2f7c957

Browse files
dkearnschrisbra
authored andcommitted
runtime(vim): Update base syntax and generator, improve command/function distinction
- Match Ex command modifiers and functions with the same name correctly. E.g., :browse and browse(). - Match full :eval command. closes: #17789 Signed-off-by: Doug Kearns <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 2e58b76 commit 2f7c957

31 files changed

Lines changed: 171 additions & 71 deletions

runtime/syntax/generator/gen_syntax_vim.vim

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" Vim syntax file generator
22
" Language: Vim script
33
" Maintainer: Hirohito Higashi (h_east)
4-
" Last Change: 2025 Jul 03
4+
" Last Change: 2025 Jul 18
55

66
let s:keepcpo= &cpo
77
set cpo&vim
@@ -234,39 +234,48 @@ function s:parse_vim_command(cmd)
234234
endtry
235235
endfunc
236236

237-
function s:get_cmd_modifiers()
238-
try
239-
let file_name = $VIM_SRCDIR .. '/ex_docmd.c'
240-
241-
new
242-
exec 'read ' .. file_name
243-
norm! gg
244-
exec ':/^static cmdmod_info_T cmdmod_info_tab\[] = {/+1;/^};/-1yank'
245-
%delete _
237+
function s:memoize_cmd_modifiers()
238+
let modifiers = []
239+
function _() closure
240+
if empty(modifiers)
241+
try
242+
let file_name = $VIM_SRCDIR .. '/ex_docmd.c'
243+
244+
new
245+
exec 'read ' .. file_name
246+
norm! gg
247+
exec ':/^static cmdmod_info_T cmdmod_info_tab\[] = {/+1;/^};/-1yank'
248+
%delete _
249+
250+
put
251+
1delete _
252+
253+
let list = []
254+
for line in getline(1, line('$'))
255+
let list = matchlist(line, '^\s*{"\(\w\+\)".*')
256+
" :browse and :confirm handled separately as lower priority matches
257+
" because they have same-named builtin functions
258+
if index(['browse', 'confirm'], list[1]) == -1
259+
call add(modifiers, copy(list[1]))
260+
endif
261+
endfor
246262

247-
put
248-
1delete _
263+
quit!
249264

250-
let modifiers = []
251-
let list = []
252-
for line in getline(1, line('$'))
253-
let list = matchlist(line, '^\s*{"\(\w\+\)".*')
254-
call add(modifiers, copy(list[1]))
255-
endfor
256-
257-
quit!
265+
if empty(modifiers)
266+
throw 'cmd modifiers list is empty'
267+
endif
258268

259-
if empty(modifiers)
260-
throw 'cmd modifiers list is empty'
269+
catch /.*/
270+
call s:err_gen('')
271+
throw 'exit'
272+
endtry
261273
endif
262-
263274
return modifiers
264-
265-
catch /.*/
266-
call s:err_gen('')
267-
throw 'exit'
268-
endtry
275+
endfunction
276+
return function("_")
269277
endfunction
278+
let s:get_cmd_modifiers = s:memoize_cmd_modifiers()
270279

271280
function s:get_vim_command_type(cmd_name)
272281
" Return value:
@@ -296,10 +305,13 @@ function s:get_vim_command_type(cmd_name)
296305
behave
297306
call
298307
catch
308+
chdir
299309
class
310+
copy
300311
debuggreedy
301312
def
302313
delcommand
314+
delete
303315
delfunction
304316
doautoall
305317
doautocmd
@@ -319,6 +331,7 @@ function s:get_vim_command_type(cmd_name)
319331
endif
320332
endinterface
321333
enum
334+
eval
322335
execute
323336
export
324337
filetype
@@ -333,6 +346,7 @@ function s:get_vim_command_type(cmd_name)
333346
import
334347
interface
335348
insert
349+
join
336350
k
337351
let
338352
loadkeymap
@@ -378,8 +392,10 @@ function s:get_vim_command_type(cmd_name)
378392
smagic
379393
snomagic
380394
sort
395+
split
381396
static
382397
substitute
398+
swapname
383399
syntax
384400
tcl
385401
tcldo

runtime/syntax/generator/vim.vim.base

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Language: Vim script
33
" Maintainer: Hirohito Higashi <h.east.727 ATMARK gmail.com>
44
" Doug Kearns <[email protected]>
5-
" Last Change: 2025 Jul 17
5+
" Last Change: 2025 Jul 18
66
" Former Maintainer: Charles E. Campbell
77

88
" DO NOT CHANGE DIRECTLY.
@@ -34,10 +34,22 @@ syn cluster vimCommentGroup contains=vimTodo,@Spell
3434
" regular vim commands {{{2
3535
" GEN_SYN_VIM: vimCommand normal, START_STR='syn keyword vimCommand contained', END_STR='nextgroup=vimBang'
3636

37+
" Lower priority :syn-match to allow for :command/function() distinction
38+
syn match vimCommand "\<chd\%[ir]\>" nextgroup=vimBang
39+
syn match vimCommand "\<co\%[py]\>" nextgroup=vimBang
40+
syn match vimCommand "\<d\%[elete]\>" nextgroup=vimBang
41+
syn match vimCommand "\<j\%[oin]\>" nextgroup=vimBang
42+
syn match vimCommand "\<sp\%[lit]\>" nextgroup=vimBang
43+
syn match vimCommand "\<sw\%[apname]\>" nextgroup=vimBang
44+
3745
" GEN_SYN_VIM: vimCommand modifier, START_STR='syn keyword vimCommandModifier', END_STR='skipwhite nextgroup=vimCommandModifierBang,@vimCmdList'
3846
" :filter is handled specially elsewhere
3947
syn match vimCommandModifierBang contained "\a\@1<=!" skipwhite nextgroup=@vimCmdList
4048

49+
" Lower priority :syn-match to allow for :command/function() distinction
50+
syn match vimCommand "\<bro\%[wse]\>" skipwhite nextgroup=vimCommandModifierBang,@vimCmdList
51+
syn match vimCommand "\<conf\%[irm]\>" skipwhite nextgroup=vimCommandModifierBang,@vimCmdList
52+
4153
" Lower priority for _new_ to distinguish constructors from the command.
4254
syn match vimCommand contained "\<new\>(\@!"
4355
syn match vimCommand contained "\<z[-+^.=]\=\>"
@@ -230,7 +242,7 @@ syn match vimNumber '\<0z\%(\x\x\)\+\%(\.\%(\x\x\)\+\)*' skipwhite nextgroup=@vi
230242
syn case match
231243

232244
" All vimCommands are contained by vimIsCommand. {{{2
233-
syn cluster vimCmdList contains=vimAbb,vimAddress,vimAutocmd,vimAugroup,vimBehave,vimCall,vimCatch,vimCommandModifier,vimConst,vimDoautocmd,vimDebuggreedy,vimDef,vimDefFold,vimDelcommand,vimDelFunction,@vimEcho,vimElse,vimEnddef,vimEndfunction,vimEndif,vimExecute,vimIsCommand,vimExtCmd,vimExFilter,vimExMark,vimFiletype,vimFor,vimFunction,vimFunctionFold,vimGrep,vimGrepAdd,vimGlobal,vimHelpgrep,vimHighlight,vimImport,vimLet,vimLoadkeymap,vimLockvar,vimMake,vimMap,vimMark,vimMatch,vimNotFunc,vimNormal,vimProfdel,vimProfile,vimRedir,vimSet,vimSleep,vimSort,vimSyntax,vimSynColor,vimSynLink,vimThrow,vimUniq,vimUnlet,vimUnlockvar,vimUnmap,vimUserCmd,vimVimgrep,vimVimgrepadd,vimMenu,vimMenutranslate,@vim9CmdList,@vimExUserCmdList,vimLua,vimMzScheme,vimPerl,vimPython,vimPython3,vimPythonX,vimRuby,vimTcl
245+
syn cluster vimCmdList contains=vimAbb,vimAddress,vimAutocmd,vimAugroup,vimBehave,vimCall,vimCatch,vimCommandModifier,vimConst,vimDoautocmd,vimDebuggreedy,vimDef,vimDefFold,vimDelcommand,vimDelFunction,@vimEcho,vimElse,vimEnddef,vimEndfunction,vimEndif,vimEval,vimExecute,vimIsCommand,vimExtCmd,vimExFilter,vimExMark,vimFiletype,vimFor,vimFunction,vimFunctionFold,vimGrep,vimGrepAdd,vimGlobal,vimHelpgrep,vimHighlight,vimImport,vimLet,vimLoadkeymap,vimLockvar,vimMake,vimMap,vimMark,vimMatch,vimNotFunc,vimNormal,vimProfdel,vimProfile,vimRedir,vimSet,vimSleep,vimSort,vimSyntax,vimSynColor,vimSynLink,vimThrow,vimUniq,vimUnlet,vimUnlockvar,vimUnmap,vimUserCmd,vimVimgrep,vimVimgrepadd,vimMenu,vimMenutranslate,@vim9CmdList,@vimExUserCmdList,vimLua,vimMzScheme,vimPerl,vimPython,vimPython3,vimPythonX,vimRuby,vimTcl
234246
syn cluster vim9CmdList contains=vim9Abstract,vim9Class,vim9Const,vim9Enum,vim9Export,vim9Final,vim9For,vim9Interface,vim9Type,vim9Var
235247
syn match vimCmdSep "\\\@1<!|" skipwhite nextgroup=@vimCmdList,vimSubst1,@vimFunc
236248
syn match vimCmdSep ":\+" skipwhite nextgroup=@vimCmdList,vimSubst1
@@ -1245,6 +1257,16 @@ syn region vimExecute
12451257
\ contains=@vimContinue,@vimExprList
12461258
\ transparent
12471259

1260+
syn region vimEval
1261+
\ matchgroup=vimCommand
1262+
\ start="\<ev\%[al]\>"
1263+
\ skip=+\\|\|||\|\n\s*\%(\\\|["#]\\ \)+
1264+
\ end="\ze|"
1265+
\ excludenl end="$"
1266+
\ nextgroup=vimCmdSep
1267+
\ contains=@vimContinue,@vimExprList
1268+
\ transparent
1269+
12481270
" Filter: {{{2
12491271
" ======
12501272
syn match vimExFilter "\<filt\%[er]\>" skipwhite nextgroup=vimExFilterBang,vimExFilterPattern
@@ -2067,7 +2089,7 @@ unlet s:interfaces
20672089
" (following Gautam Iyer's suggestion)
20682090
" ==========================
20692091
syn match vimFunc contained "\<\l\w*\ze\s*(" skipwhite nextgroup=vimOperParen contains=vimFuncName
2070-
syn match vimUserFunc contained "\.\@1<=\l\w*\ze\s*(" skipwhite nextgroup=vimOperParen contains=vimFuncName
2092+
syn match vimUserFunc contained "\.\@1<=\l\w*\ze\s*(" skipwhite nextgroup=vimOperParen
20712093
syn match vimUserFunc contained "\<\%([[:upper:]_]\|\%(\h\w*\.\)\+\h\)\w*\ze\s*(" skipwhite nextgroup=vimOperParen contains=vim9MethodName,vim9Super,vim9This
20722094
syn match vimUserFunc contained "\<\%(g:\)\=\%(\h\w*#\)\+\h\w*\ze\s*(" skipwhite nextgroup=vimOperParen contains=vimVarScope
20732095
syn match vimUserFunc contained "\%(\<[sgbwtlav]:\|<[sS][iI][dD]>\)\%(\h\w*\.\)*\h\w*\ze\s*(" skipwhite nextgroup=vimOperParen contains=vimVarScope,vimNotation
@@ -2224,6 +2246,7 @@ if !exists("skip_vim_syntax_inits")
22242246
hi def link vimEnvvar PreProc
22252247
hi def link vimError Error
22262248
hi def link vimEscape Special
2249+
hi def link vimEval vimCommand
22272250
hi def link vimExFilter vimCommand
22282251
hi def link vimExFilterBang vimBang
22292252
hi def link vimExMark vimCommand

runtime/syntax/testdir/dumps/vim9_function_call_01.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
|v+0#af5f00255&|a|r| +0#0000000&|b|r|o|w|s|e| |=+0#af5f00255&| +0#0000000&|b+0#00e0e07&|r|o|w|s|e|(+0#e000e06&|4+0#e000002&|2|)+0#e000e06&| +0#0000000&@51
1111
|c+0#af5f00255&|a|l@1| +0#0000000&|b+0#00e0e07&|r|o|w|s|e|(+0#e000e06&|4+0#e000002&|2|)+0#e000e06&| +0#0000000&@59
1212
|#+0#0000e05&| |f|u|n|c|t|i|o|n| +0#0000000&@64
13-
|b+0#af5f00255&|r|o|w|s|e|(+0#e000e06&|4+0#e000002&|2|)+0#e000e06&| +0#0000000&@64
13+
|b+0#00e0e07&|r|o|w|s|e|(+0#e000e06&|4+0#e000002&|2|)+0#e000e06&| +0#0000000&@64
1414
|#+0#0000e05&| |c|o|m@1|a|n|d| +0#0000000&@65
1515
|b+0#af5f00255&|r|o|w|s|e| +0#0000000&|(+0#e000e06&|4+0#e000002&|2|)+0#e000e06&| +0#0000000&@63
1616
@75

runtime/syntax/testdir/dumps/vim9_function_call_02.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
|v+0#af5f00255&|a|r| +0#0000000&|c|o|n|f|i|r|m| |=+0#af5f00255&| +0#0000000&|c+0#00e0e07&|o|n|f|i|r|m|(+0#e000e06&|4+0#e000002&|2|)+0#e000e06&| +0#0000000&@49
1414
|c+0#af5f00255&|a|l@1| +0#0000000&|c+0#00e0e07&|o|n|f|i|r|m|(+0#e000e06&|4+0#e000002&|2|)+0#e000e06&| +0#0000000&@58
1515
|#+0#0000e05&| |f|u|n|c|t|i|o|n| +0#0000000&@64
16-
|c+0#af5f00255&|o|n|f|i|r|m|(+0#e000e06&|4+0#e000002&|2|)+0#e000e06&| +0#0000000&@63
16+
|c+0#00e0e07&|o|n|f|i|r|m|(+0#e000e06&|4+0#e000002&|2|)+0#e000e06&| +0#0000000&@63
1717
|#+0#0000e05&| |c|o|m@1|a|n|d| +0#0000000&@65
1818
|c+0#af5f00255&|o|n|f|i|r|m| +0#0000000&|(+0#e000e06&|4+0#e000002&|2|)+0#e000e06&| +0#0000000&@62
1919
@75

runtime/syntax/testdir/dumps/vim9_function_call_09.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
|#+0#0000e05&| |c|o|m@1|a|n|d| +0#0000000&@65
1818
|i+0#af5f00255&|f| +0#0000000&|(+0#e000e06&|4+0#e000002&|2|)+0#e000e06&| +0#0000000&||| |.+0#af5f00255&@1| +0#0000000&||| |e+0#af5f00255&|n|d|i|f| +0#0000000&@54
1919
@75
20-
@57|1|6|3|,|0|-|1| @6|5|3|%|
20+
@57|1|6|3|,|0|-|1| @6|5|2|%|

runtime/syntax/testdir/dumps/vim9_function_call_10.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
@75
1818
|e+0#af5f00255&|c|h|o| +0#0000000&|a+0#00e0e07&|b|s|(+0#e000e06&|4+0#e000002&|2|)+0#e000e06&| +0#0000000&@62
1919
|e+0#af5f00255&|c|h|o| +0#0000000&|(+0#e000e06&|a+0#00e0e07&|b|s|(+0#e000e06&|4+0#e000002&|2|)+0#e000e06&@1| +0#0000000&@60
20-
@57|1|8|1|,|1| @8|5|9|%|
20+
@57|1|8|1|,|1| @8|5|8|%|

runtime/syntax/testdir/dumps/vim9_function_call_11.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
|v+0#af5f00255&|a|r| +0#0000000&|f|o@1| |=+0#af5f00255&| +0#0000000&|g+0#00e0e07&|:|f+0#0000001#ffff4012|o@1|(+0#e000e06#ffffff0|4+0#e000002&|2|)+0#e000e06&| +0#0000000&@55
1818
|c+0#af5f00255&|a|l@1| +0#0000000&|g+0#00e0e07&|:|f+0#0000001#ffff4012|o@1|(+0#e000e06#ffffff0|4+0#e000002&|2|)+0#e000e06&| +0#0000000&@60
1919
@75
20-
@57|1|9@1|,|1| @8|6|5|%|
20+
@57|1|9@1|,|1| @8|6|4|%|

runtime/syntax/testdir/dumps/vim9_function_call_12.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
|m+0#0000001#ffff4012|o|d|u|l|e|.|f|o@1|(+0#e000e06#ffffff0|4+0#e000002&|2|)+0#e000e06&| +0#0000000&@60
1818
@75
1919
|v+0#af5f00255&|a|r| +0#0000000&|f|o@1| |=+0#af5f00255&| +0#0000000&|g+0#00e0e07&|:|m+0#0000001#ffff4012|o|d|u|l|e|.|f|o@1|(+0#e000e06#ffffff0|4+0#e000002&|2|)+0#e000e06&| +0#0000000&@48
20-
@57|2|1|7|,|1| @8|7|1|%|
20+
@57|2|1|7|,|1| @8|7|0|%|

runtime/syntax/testdir/dumps/vim9_function_call_13.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
|v+0#af5f00255&|a|r| +0#0000000&|f|o@1| |=+0#af5f00255&| +0#0000000&|v+0#00e0e07&|:|m+0#0000001#ffff4012|o|d|u|l|e|.|f|o@1|(+0#e000e06#ffffff0|4+0#e000002&|2|)+0#e000e06&| +0#0000000&@48
1818
|c+0#af5f00255&|a|l@1| +0#0000000&|v+0#00e0e07&|:|m+0#0000001#ffff4012|o|d|u|l|e|.|f|o@1|(+0#e000e06#ffffff0|4+0#e000002&|2|)+0#e000e06&| +0#0000000&@53
1919
|v+0#00e0e07&|:|m+0#0000001#ffff4012|o|d|u|l|e|.|f|o@1|(+0#e000e06#ffffff0|4+0#e000002&|2|)+0#e000e06&| +0#0000000&@58
20-
@57|2|3|5|,|1| @8|7@1|%|
20+
@57|2|3|5|,|1| @8|7|6|%|

runtime/syntax/testdir/dumps/vim9_function_call_14.dump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
|c+0#af5f00255&|a|l@1| +0#0000000&|w+0#00e0e07&|:|s+0#0000001#ffff4012|u|b|s|t|i|t|u|t|e|(+0#e000e06#ffffff0|)| +0#0000000&@55
1818
|c+0#af5f00255&|a|l@1| +0#0000000&|t+0#00e0e07&|:|s+0#0000001#ffff4012|u|b|s|t|i|t|u|t|e|(+0#e000e06#ffffff0|)| +0#0000000&@55
1919
|c+0#af5f00255&|a|l@1| +0#0000000&|v+0#00e0e07&|:|s+0#0000001#ffff4012|u|b|s|t|i|t|u|t|e|(+0#e000e06#ffffff0|)| +0#0000000&@55
20-
@57|2|5|3|,|1| @8|8|3|%|
20+
@57|2|5|3|,|1| @8|8|2|%|

0 commit comments

Comments
 (0)