2023-04-20 05:41:47 -07:00
|
|
|
local mpack = vim.mpack
|
2016-06-19 07:41:08 -07:00
|
|
|
|
2015-03-28 15:26:48 -07:00
|
|
|
if arg[1] == '--help' then
|
2016-08-22 01:51:32 -07:00
|
|
|
print('Usage: lua genvimvim.lua src/nvim runtime/syntax/vim/generated.vim')
|
2015-03-28 15:26:48 -07:00
|
|
|
os.exit(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
local nvimsrcdir = arg[1]
|
|
|
|
local syntax_file = arg[2]
|
2016-06-19 07:41:08 -07:00
|
|
|
local funcs_file = arg[3]
|
2015-03-28 15:26:48 -07:00
|
|
|
|
|
|
|
package.path = nvimsrcdir .. '/?.lua;' .. package.path
|
|
|
|
|
2023-01-23 02:26:46 -07:00
|
|
|
_G.vim = loadfile(nvimsrcdir..'/../../runtime/lua/vim/shared.lua')()
|
|
|
|
|
2015-03-28 15:26:48 -07:00
|
|
|
local lld = {}
|
|
|
|
local syn_fd = io.open(syntax_file, 'w')
|
|
|
|
lld.line_length = 0
|
2018-12-07 17:16:58 -07:00
|
|
|
local function w(s)
|
2015-03-28 15:26:48 -07:00
|
|
|
syn_fd:write(s)
|
|
|
|
if s:find('\n') then
|
|
|
|
lld.line_length = #(s:gsub('.*\n', ''))
|
|
|
|
else
|
|
|
|
lld.line_length = lld.line_length + #s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local options = require('options')
|
|
|
|
local auevents = require('auevents')
|
|
|
|
local ex_cmds = require('ex_cmds')
|
|
|
|
|
2018-12-07 17:16:58 -07:00
|
|
|
local function cmd_kw(prev_cmd, cmd)
|
2015-03-28 15:26:48 -07:00
|
|
|
if not prev_cmd then
|
|
|
|
return cmd:sub(1, 1) .. '[' .. cmd:sub(2) .. ']'
|
|
|
|
else
|
|
|
|
local shift = 1
|
|
|
|
while cmd:sub(shift, shift) == prev_cmd:sub(shift, shift) do
|
|
|
|
shift = shift + 1
|
|
|
|
end
|
2023-04-17 18:40:05 -07:00
|
|
|
if cmd:sub(1, shift) == 'def' then
|
|
|
|
shift = shift + 1
|
|
|
|
end
|
2015-03-28 15:26:48 -07:00
|
|
|
if shift >= #cmd then
|
|
|
|
return cmd
|
|
|
|
else
|
|
|
|
return cmd:sub(1, shift) .. '[' .. cmd:sub(shift + 1) .. ']'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-07 17:16:58 -07:00
|
|
|
-- Exclude these from the vimCommand keyword list, they are handled specially
|
2022-06-15 00:20:32 -07:00
|
|
|
-- in syntax/vim.vim (vimAugroupKey, vimAutoCmd, vimGlobal, vimSubst). #9327
|
fix(runtime/genvimvim): omit s[ubstitute] from vimCommand #18480
It's special cased by the vimSubst syntax group, and isn't present in Vim's
vimCommand group.
For example, this fixes `call s:Foo()` highlighting `:` as Error in Nvim, as the
`s` is parsed as vimCommand rather than as vimUserFunc since
`contains=vimCommand` was added to vimUserFunc (and vimFunc) in a rt update.
Interestingly, `g:`, `l:`, etc. have the same issues due to :global, :list, etc.
Vim also has that problem, so it should ideally be fixed upstream.
We could also omit g[lobal] from vimCommand and rely on vimGlobal instead, but
it doesn't work in some cases, like when there's a `:` before the command. Also,
Vim matches only `g` in vimCommand for some reason, which doesn't produce any
highlight for `:global/foo/bar` (with Nvim you at least get some highlights on
the `global` bit despite the leading `:`).
Also, remove special handling of :py3 in syntax/vim.vim, as the generator seems
to have no problems finding it.
2022-05-11 17:08:25 -07:00
|
|
|
local function is_special_cased_cmd(cmd)
|
2018-12-07 17:16:58 -07:00
|
|
|
return (cmd == 'augroup'
|
|
|
|
or cmd == 'autocmd'
|
|
|
|
or cmd == 'doautocmd'
|
fix(runtime/genvimvim): omit s[ubstitute] from vimCommand #18480
It's special cased by the vimSubst syntax group, and isn't present in Vim's
vimCommand group.
For example, this fixes `call s:Foo()` highlighting `:` as Error in Nvim, as the
`s` is parsed as vimCommand rather than as vimUserFunc since
`contains=vimCommand` was added to vimUserFunc (and vimFunc) in a rt update.
Interestingly, `g:`, `l:`, etc. have the same issues due to :global, :list, etc.
Vim also has that problem, so it should ideally be fixed upstream.
We could also omit g[lobal] from vimCommand and rely on vimGlobal instead, but
it doesn't work in some cases, like when there's a `:` before the command. Also,
Vim matches only `g` in vimCommand for some reason, which doesn't produce any
highlight for `:global/foo/bar` (with Nvim you at least get some highlights on
the `global` bit despite the leading `:`).
Also, remove special handling of :py3 in syntax/vim.vim, as the generator seems
to have no problems finding it.
2022-05-11 17:08:25 -07:00
|
|
|
or cmd == 'doautoall'
|
2022-06-15 00:20:32 -07:00
|
|
|
or cmd == 'global'
|
fix(runtime/genvimvim): omit s[ubstitute] from vimCommand #18480
It's special cased by the vimSubst syntax group, and isn't present in Vim's
vimCommand group.
For example, this fixes `call s:Foo()` highlighting `:` as Error in Nvim, as the
`s` is parsed as vimCommand rather than as vimUserFunc since
`contains=vimCommand` was added to vimUserFunc (and vimFunc) in a rt update.
Interestingly, `g:`, `l:`, etc. have the same issues due to :global, :list, etc.
Vim also has that problem, so it should ideally be fixed upstream.
We could also omit g[lobal] from vimCommand and rely on vimGlobal instead, but
it doesn't work in some cases, like when there's a `:` before the command. Also,
Vim matches only `g` in vimCommand for some reason, which doesn't produce any
highlight for `:global/foo/bar` (with Nvim you at least get some highlights on
the `global` bit despite the leading `:`).
Also, remove special handling of :py3 in syntax/vim.vim, as the generator seems
to have no problems finding it.
2022-05-11 17:08:25 -07:00
|
|
|
or cmd == 'substitute')
|
2018-12-07 17:16:58 -07:00
|
|
|
end
|
|
|
|
|
2021-09-19 16:35:38 -07:00
|
|
|
local vimcmd_start = 'syn keyword vimCommand contained '
|
2015-03-28 15:26:48 -07:00
|
|
|
w(vimcmd_start)
|
|
|
|
local prev_cmd = nil
|
2020-12-31 17:56:15 -07:00
|
|
|
for _, cmd_desc in ipairs(ex_cmds.cmds) do
|
2015-03-28 15:26:48 -07:00
|
|
|
if lld.line_length > 850 then
|
|
|
|
w('\n' .. vimcmd_start)
|
|
|
|
end
|
|
|
|
local cmd = cmd_desc.command
|
fix(runtime/genvimvim): omit s[ubstitute] from vimCommand #18480
It's special cased by the vimSubst syntax group, and isn't present in Vim's
vimCommand group.
For example, this fixes `call s:Foo()` highlighting `:` as Error in Nvim, as the
`s` is parsed as vimCommand rather than as vimUserFunc since
`contains=vimCommand` was added to vimUserFunc (and vimFunc) in a rt update.
Interestingly, `g:`, `l:`, etc. have the same issues due to :global, :list, etc.
Vim also has that problem, so it should ideally be fixed upstream.
We could also omit g[lobal] from vimCommand and rely on vimGlobal instead, but
it doesn't work in some cases, like when there's a `:` before the command. Also,
Vim matches only `g` in vimCommand for some reason, which doesn't produce any
highlight for `:global/foo/bar` (with Nvim you at least get some highlights on
the `global` bit despite the leading `:`).
Also, remove special handling of :py3 in syntax/vim.vim, as the generator seems
to have no problems finding it.
2022-05-11 17:08:25 -07:00
|
|
|
if cmd:match('%w') and cmd ~= 'z' and not is_special_cased_cmd(cmd) then
|
2015-03-28 15:26:48 -07:00
|
|
|
w(' ' .. cmd_kw(prev_cmd, cmd))
|
|
|
|
end
|
2023-04-17 18:40:05 -07:00
|
|
|
if cmd == 'delete' then
|
|
|
|
-- Add special abbreviations of :delete
|
|
|
|
w(' ' .. cmd_kw('d', 'dl'))
|
|
|
|
w(' ' .. cmd_kw('del', 'dell'))
|
|
|
|
w(' ' .. cmd_kw('dele', 'delel'))
|
|
|
|
w(' ' .. cmd_kw('delet', 'deletl'))
|
|
|
|
w(' ' .. cmd_kw('delete', 'deletel'))
|
|
|
|
w(' ' .. cmd_kw('d', 'dp'))
|
|
|
|
w(' ' .. cmd_kw('de', 'dep'))
|
|
|
|
w(' ' .. cmd_kw('del', 'delp'))
|
|
|
|
w(' ' .. cmd_kw('dele', 'delep'))
|
|
|
|
w(' ' .. cmd_kw('delet', 'deletp'))
|
|
|
|
w(' ' .. cmd_kw('delete', 'deletep'))
|
|
|
|
end
|
2015-03-28 15:26:48 -07:00
|
|
|
prev_cmd = cmd
|
|
|
|
end
|
|
|
|
|
|
|
|
local vimopt_start = 'syn keyword vimOption contained '
|
|
|
|
w('\n\n' .. vimopt_start)
|
|
|
|
|
|
|
|
for _, opt_desc in ipairs(options.options) do
|
2015-07-26 11:39:19 -07:00
|
|
|
if not opt_desc.varname or opt_desc.varname:sub(1, 7) ~= 'p_force' then
|
|
|
|
if lld.line_length > 850 then
|
|
|
|
w('\n' .. vimopt_start)
|
|
|
|
end
|
|
|
|
w(' ' .. opt_desc.full_name)
|
2015-03-28 15:26:48 -07:00
|
|
|
if opt_desc.abbreviation then
|
2015-07-26 11:39:19 -07:00
|
|
|
w(' ' .. opt_desc.abbreviation)
|
|
|
|
end
|
|
|
|
if opt_desc.type == 'bool' then
|
|
|
|
w(' inv' .. opt_desc.full_name)
|
|
|
|
w(' no' .. opt_desc.full_name)
|
|
|
|
if opt_desc.abbreviation then
|
|
|
|
w(' inv' .. opt_desc.abbreviation)
|
|
|
|
w(' no' .. opt_desc.abbreviation)
|
|
|
|
end
|
2015-03-28 15:26:48 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
w('\n\nsyn case ignore')
|
|
|
|
local vimau_start = 'syn keyword vimAutoEvent contained '
|
|
|
|
w('\n\n' .. vimau_start)
|
|
|
|
|
|
|
|
for _, au in ipairs(auevents.events) do
|
2018-10-21 09:54:07 -07:00
|
|
|
if not auevents.nvim_specific[au] then
|
2015-07-26 11:28:32 -07:00
|
|
|
if lld.line_length > 850 then
|
|
|
|
w('\n' .. vimau_start)
|
|
|
|
end
|
|
|
|
w(' ' .. au)
|
2015-03-28 15:26:48 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
for au, _ in pairs(auevents.aliases) do
|
2018-10-21 09:54:07 -07:00
|
|
|
if not auevents.nvim_specific[au] then
|
2015-07-26 11:28:32 -07:00
|
|
|
if lld.line_length > 850 then
|
|
|
|
w('\n' .. vimau_start)
|
|
|
|
end
|
|
|
|
w(' ' .. au)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local nvimau_start = 'syn keyword nvimAutoEvent contained '
|
|
|
|
w('\n\n' .. nvimau_start)
|
|
|
|
|
2023-01-23 02:26:46 -07:00
|
|
|
for au, _ in vim.spairs(auevents.nvim_specific) do
|
2015-03-28 15:26:48 -07:00
|
|
|
if lld.line_length > 850 then
|
2015-07-26 11:28:32 -07:00
|
|
|
w('\n' .. nvimau_start)
|
2015-03-28 15:26:48 -07:00
|
|
|
end
|
|
|
|
w(' ' .. au)
|
|
|
|
end
|
|
|
|
|
|
|
|
w('\n\nsyn case match')
|
|
|
|
local vimfun_start = 'syn keyword vimFuncName contained '
|
|
|
|
w('\n\n' .. vimfun_start)
|
2023-04-15 03:23:45 -07:00
|
|
|
local funcs = mpack.decode(io.open(funcs_file, 'rb'):read("*all"))
|
2023-01-23 02:26:46 -07:00
|
|
|
for _, name in ipairs(funcs) do
|
2016-01-01 02:17:22 -07:00
|
|
|
if name then
|
|
|
|
if lld.line_length > 850 then
|
|
|
|
w('\n' .. vimfun_start)
|
2015-03-28 15:26:48 -07:00
|
|
|
end
|
2016-01-01 02:17:22 -07:00
|
|
|
w(' ' .. name)
|
2015-03-28 15:26:48 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
w('\n')
|
|
|
|
syn_fd:close()
|