vim-patch:9.0.2128: runtime(swig): add syntax and filetype plugins

Add syntax and filetype plugins for SWIG (Simplified Wrapper Interface
Generator) description files.

The default syntax for .i files highlights comments in a reverse
color scheme which doesn't look well.  This syntax builds
on vim's c++ syntax by adding highlighting for common swig
directives and user defined directives.  For an alternative
syntax, see vimscript vim/vim#1247 (which I found after writing this).

closes: vim/vim#13562

2e31065a65

Co-authored-by: Julien Marrec <julien.marrec@gmail.com>
Co-authored-by: Matěj Cepl <mcepl@cepl.eu>
This commit is contained in:
Christian Clason
2023-11-25 16:06:58 +01:00
parent ba88fd886a
commit 38e98754a5
5 changed files with 171 additions and 21 deletions

View File

@@ -984,6 +984,8 @@ local extension = {
svelte = 'svelte',
svg = 'svg',
swift = 'swift',
swig = 'swig',
swg = 'swig',
svh = 'systemverilog',
sv = 'systemverilog',
cmm = 'trace32',
@@ -1134,7 +1136,7 @@ local extension = {
web = detect.web,
pl = detect.pl,
pp = detect.pp,
i = detect.progress_asm,
i = detect.i,
w = detect.progress_cweb,
p = detect.progress_pascal,
pro = detect_seq(detect.proto, 'idlang'),

View File

@@ -619,6 +619,31 @@ function M.hw(_, bufnr)
return 'virata'
end
-- This function checks for an assembly comment or a SWIG keyword or verbatim
-- block in the first 50 lines.
-- If not found, assume Progress.
--- @type vim.filetype.mapfn
function M.i(path, bufnr)
if vim.g.filetype_i then
return vim.g.filetype_i
end
-- These include the leading '%' sign
local ft_swig_keywords =
[[^\s*%\%(addmethods\|apply\|beginfile\|clear\|constant\|define\|echo\|enddef\|endoffile\|extend\|feature\|fragment\|ignore\|import\|importfile\|include\|includefile\|inline\|insert\|keyword\|module\|name\|namewarn\|native\|newobject\|parms\|pragma\|rename\|template\|typedef\|typemap\|types\|varargs\|warn\)]]
-- This is the start/end of a block that is copied literally to the processor file (C/C++)
local ft_swig_verbatim_block_start = '^%s*%%{'
for _, line in ipairs(getlines(bufnr, 1, 50)) do
if line:find('^%s*;') or line:find('^%*') then
return M.asm(path, bufnr)
elseif matchregex(line, ft_swig_keywords) or line:find(ft_swig_verbatim_block_start) then
return 'swig'
end
end
return 'progress'
end
--- @type vim.filetype.mapfn
function M.idl(_, bufnr)
for _, line in ipairs(getlines(bufnr, 1, 50)) do
@@ -1016,26 +1041,6 @@ function M.printcap(ptcap_type)
end
end
-- This function checks for an assembly comment in the first ten lines.
-- If not found, assume Progress.
--- @type vim.filetype.mapfn
function M.progress_asm(path, bufnr)
if vim.g.filetype_i then
return vim.g.filetype_i
end
for _, line in ipairs(getlines(bufnr, 1, 10)) do
if line:find('^%s*;') or line:find('^/%*') then
return M.asm(path, bufnr)
elseif not line:find('^%s*$') or line:find('^/%*') then
-- Not an empty line: doesn't look like valid assembly code
-- or it looks like a Progress /* comment.
break
end
end
return 'progress'
end
--- @type vim.filetype.mapfn
function M.progress_cweb(_, bufnr)
if vim.g.filetype_w then