aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2023-11-25 16:06:58 +0100
committerChristian Clason <c.clason@uni-graz.at>2023-11-26 00:41:59 +0100
commit38e98754a556404b54d3c28b4272bcacbc3b6b0e (patch)
tree1c2ea09cbf7151b1135da6ede154837d9baece89 /runtime/lua
parentba88fd886ae871025719dfc8602072cc51ce5407 (diff)
downloadrneovim-38e98754a556404b54d3c28b4272bcacbc3b6b0e.tar.gz
rneovim-38e98754a556404b54d3c28b4272bcacbc3b6b0e.tar.bz2
rneovim-38e98754a556404b54d3c28b4272bcacbc3b6b0e.zip
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 https://github.com/vim/vim/commit/2e31065a650015892179e520038bf2083a9519b6 Co-authored-by: Julien Marrec <julien.marrec@gmail.com> Co-authored-by: Matěj Cepl <mcepl@cepl.eu>
Diffstat (limited to 'runtime/lua')
-rw-r--r--runtime/lua/vim/filetype.lua4
-rw-r--r--runtime/lua/vim/filetype/detect.lua45
2 files changed, 28 insertions, 21 deletions
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
index 217f673b5e..cb2656d9ba 100644
--- a/runtime/lua/vim/filetype.lua
+++ b/runtime/lua/vim/filetype.lua
@@ -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'),
diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua
index 5479608148..9d0f1bd3ab 100644
--- a/runtime/lua/vim/filetype/detect.lua
+++ b/runtime/lua/vim/filetype/detect.lua
@@ -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