summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Marrec <julien.marrec@gmail.com>2023-11-25 15:30:46 +0100
committerChristian Brabandt <cb@256bit.org>2023-11-25 15:30:46 +0100
commit2e31065a650015892179e520038bf2083a9519b6 (patch)
tree11606cc1f0564adcb22bbbb52f5954aa6b049ee8
parente214692718d6a997a0540fc688e1417564416f80 (diff)
patch 9.0.2128: runtime(swig): add syntax and filetype pluginsv9.0.2128
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 #1247 (which I found after writing this). closes: #13562 Co-authored-by: Matěj Cepl <mcepl@cepl.eu> Co-authored-by: Julien Marrec <julien.marrec@gmail.com> Signed-off-by: Julien Marrec <julien.marrec@gmail.com> Signed-off-by: Doug Kearns <dougkearns@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
-rw-r--r--.github/CODEOWNERS2
-rw-r--r--runtime/autoload/dist/ft.vim18
-rw-r--r--runtime/filetype.vim7
-rw-r--r--runtime/ftplugin/swig.vim13
-rw-r--r--runtime/syntax/swig.vim99
-rw-r--r--src/testdir/test_filetype.vim31
-rw-r--r--src/version.c2
7 files changed, 163 insertions, 9 deletions
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index d99c8c7101..977bb5d4c6 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -224,6 +224,7 @@ runtime/ftplugin/spec.vim @ignatenkobrain
runtime/ftplugin/ssa.vim @ObserverOfTime
runtime/ftplugin/swayconfig.vim @jamespeapen
runtime/ftplugin/systemverilog.vim @Kocha
+runtime/ftplugin/swig.vim @jmarrec
runtime/ftplugin/tap.vim @petdance
runtime/ftplugin/tcsh.vim @dkearns
runtime/ftplugin/tidy.vim @dkearns
@@ -502,6 +503,7 @@ runtime/syntax/sshdconfig.vim @Jakuje
runtime/syntax/sudoers.vim @e-kwsm
runtime/syntax/svn.vim @hdima
runtime/syntax/swayconfig.vim @jamespeapen
+runtime/syntax/swig.vim @jmarrec
runtime/syntax/systemverilog.vim @Kocha
runtime/syntax/tags.vim @cecamp
runtime/syntax/tap.vim @petdance
diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim
index 2958f45d0a..53c56f6b52 100644
--- a/runtime/autoload/dist/ft.vim
+++ b/runtime/autoload/dist/ft.vim
@@ -590,23 +590,27 @@ export def FTprogress_cweb()
endif
enddef
-export def FTprogress_asm()
+# These include the leading '%' sign
+var 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++)
+var ft_swig_verbatim_block_start = '^\s*%{'
+
+export def FTi()
if exists("g:filetype_i")
exe "setf " .. g:filetype_i
return
endif
- # This function checks for an assembly comment the first ten lines.
+ # This function checks for an assembly comment or a SWIG keyword or verbatim block in the first 50 lines.
# If not found, assume Progress.
var lnum = 1
- while lnum <= 10 && lnum < line('$')
+ while lnum <= 50 && lnum < line('$')
var line = getline(lnum)
if line =~ '^\s*;' || line =~ '^\*'
FTasm()
return
- elseif line !~ '^\s*$' || line =~ '^/\*'
- # Not an empty line: Doesn't look like valid assembly code.
- # Or it looks like a Progress /* comment
- break
+ elseif line =~ ft_swig_keywords || line =~ ft_swig_verbatim_block_start
+ setf swig
+ return
endif
lnum += 1
endwhile
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index b067c70e6a..5e9e015290 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -1688,8 +1688,8 @@ au BufNewFile,BufRead .procmail,.procmailrc setf procmail
" Progress or CWEB
au BufNewFile,BufRead *.w call dist#ft#FTprogress_cweb()
-" Progress or assembly
-au BufNewFile,BufRead *.i call dist#ft#FTprogress_asm()
+" Progress or assembly or Swig
+au BufNewFile,BufRead *.i call dist#ft#FTi()
" Progress or Pascal
au BufNewFile,BufRead *.p call dist#ft#FTprogress_pascal()
@@ -2183,6 +2183,9 @@ au BufNewFile,BufRead *.swift.gyb setf swiftgyb
" Swift Intermediate Language or SILE
au BufNewFile,BufRead *.sil call dist#ft#FTsil()
+" Swig
+au BufNewFile,BufRead *.swg,*.swig setf swig
+
" Sysctl
au BufNewFile,BufRead */etc/sysctl.conf,*/etc/sysctl.d/*.conf setf sysctl
diff --git a/runtime/ftplugin/swig.vim b/runtime/ftplugin/swig.vim
new file mode 100644
index 0000000000..506c929a43
--- /dev/null
+++ b/runtime/ftplugin/swig.vim
@@ -0,0 +1,13 @@
+" Vim filetype plugin file
+" Language: SWIG
+" Maintainer: Julien Marrec <julien.marrec 'at' gmail com>
+" Last Change: 2023 November 23
+
+" Only do this when not done yet for this buffer
+if exists("b:did_ftplugin")
+ finish
+endif
+let b:did_ftplugin = 1
+
+let b:undo_ftplugin = "setlocal iskeyword<"
+setlocal iskeyword+=%
diff --git a/runtime/syntax/swig.vim b/runtime/syntax/swig.vim
new file mode 100644
index 0000000000..b62621264a
--- /dev/null
+++ b/runtime/syntax/swig.vim
@@ -0,0 +1,99 @@
+" Vim syntax file
+" Language: SWIG
+" Maintainer: Julien Marrec <julien.marrec 'at' gmail com>
+" Last Change: 2023 November 23
+
+if exists("b:current_syntax")
+ finish
+endif
+
+" Read the C++ syntax to start with
+runtime! syntax/cpp.vim
+unlet b:current_syntax
+
+" SWIG extentions
+syn keyword swigInclude %include %import %importfile %includefile %module
+
+syn keyword swigMostCommonDirective %alias %apply %beginfile %clear %constant %define %echo %enddef %endoffile
+syn keyword swigMostCommonDirective %extend %feature %director %fragment %ignore %inline
+syn keyword swigMostCommonDirective %keyword %name %namewarn %native %newobject %parms %pragma
+syn keyword swigMostCommonDirective %rename %template %typedef %typemap %types %varargs
+
+" SWIG: Language specific macros
+syn keyword swigOtherLanguageSpecific %luacode %go_import
+
+syn keyword swigCSharp %csattributes %csconst %csconstvalue %csmethodmodifiers %csnothrowexception
+syn keyword swigCSharp %dconstvalue %dmanifestconst %dmethodmodifiers
+
+syn keyword swigJava %javaconstvalue %javaexception %javamethodmodifiers %javaconst %nojavaexception
+
+syn keyword swigGuile %multiple_values %values_as_list %values_as_vector
+
+syn keyword swigPHP %rinit %rshutdown %minit %mshutdown
+
+syn keyword swigPython %pybinoperator %pybuffer_binary %pybuffer_mutable_binary %pybuffer_mutable_string %pybuffer_string
+syn keyword swigPython %pythonappend %pythonbegin %pythoncode %pythondynamic %pythonnondynamic %pythonprepend
+
+syn keyword swigRuby %markfunc %trackobjects %bang
+syn keyword swigScilab %scilabconst
+
+" SWIG: Insertion
+syn keyword swigInsertSection %insert %begin %runtime %header %wrapper %init
+
+" SWIG: Other directives
+syn keyword swigCstring %cstring_bounded_mutable %cstring_bounded_output %cstring_chunk_output %cstring_input_binary %cstring_mutable
+syn keyword swigCstring %cstring_output_allocate %cstring_output_allocate_size %cstring_output_maxsize %cstring_output_withsize
+syn keyword swigCWstring %cwstring_bounded_mutable %cwstring_bounded_output %cwstring_chunk_output %cwstring_input_binary %cwstring_mutable
+syn keyword swigCWstring %cwstring_output_allocate %cwstring_output_allocate_size %cwstring_output_maxsize %cwstring_output_withsize
+syn keyword swigCMalloc %malloc %calloc %realloc %free %sizeof %allocators
+
+syn keyword swigExceptionHandling %catches %raise %allowexception %exceptionclass %warn %warnfilter %exception
+syn keyword swigContract %contract %aggregate_check
+
+syn keyword swigDirective %addmethods %array_class %array_functions %attribute %attribute2 %attribute2ref
+syn keyword swigDirective %attribute_ref %attributeref %attributestring %attributeval %auto_ptr %callback
+syn keyword swigDirective %delete_array %delobject %extend_smart_pointer %factory %fastdispatch %freefunc %immutable
+syn keyword swigDirective %implicit %implicitconv %interface %interface_custom %interface_impl %intrusive_ptr %intrusive_ptr_no_wrap
+syn keyword swigDirective %mutable %naturalvar %nocallback %nocopyctor %nodefaultctor %nodefaultdtor %nonaturalvar %nonspace
+syn keyword swigDirective %nspace %pointer_cast %pointer_class %pointer_functions %predicate %proxycode
+syn keyword swigDirective %refobject %set_output %shared_ptr %std_comp_methods
+syn keyword swigDirective %std_nodefconst_type %typecheck %typemaps_string %unique_ptr %unrefobject %valuewrapper
+
+syn match swigVerbatimStartEnd "%[{}]"
+
+syn match swigUserDef "%\w\+"
+syn match swigVerbatimMacro "^\s*%#\w\+\%( .*\)\?$"
+
+" SWIG: typemap var and typemap macros (eg: $1, $*1_type, $&n_ltype, $self)
+syn match swigTypeMapVars "\$[*&_a-zA-Z0-9]\+"
+
+" Default highlighting
+hi def link swigInclude Include
+hi def link swigMostCommonDirective Structure
+hi def link swigDirective Macro
+hi def link swigContract swigExceptionHandling
+hi def link swigExceptionHandling Exception
+hi def link swigUserDef Function
+
+hi def link swigCMalloc Statement
+hi def link swigCstring Type
+hi def link swigCWstring Type
+
+hi def link swigCSharp swigOtherLanguageSpecific
+hi def link swigJava swigOtherLanguageSpecific
+hi def link swigGuile swigOtherLanguageSpecific
+hi def link swigPHP swigOtherLanguageSpecific
+hi def link swigPython swigOtherLanguageSpecific
+hi def link swigRuby swigOtherLanguageSpecific
+hi def link swigScilab swigOtherLanguageSpecific
+hi def link swigOtherLanguageSpecific Special
+
+hi def link swigInsertSection PreProc
+
+hi def link swigVerbatimStartEnd Statement
+hi def link swigVerbatimMacro Macro
+
+hi def link swigTypeMapVars SpecialChar
+
+let b:current_syntax = "swig"
+" vim: ts=8
diff --git a/src/testdir/test_filetype.vim b/src/testdir/test_filetype.vim
index 483d01b89b..0018bbabfc 100644
--- a/src/testdir/test_filetype.vim
+++ b/src/testdir/test_filetype.vim
@@ -673,6 +673,7 @@ def s:GetFilenameChecks(): dict<list<string>>
swayconfig: ['/home/user/.sway/config', '/home/user/.config/sway/config', '/etc/sway/config', '/etc/xdg/sway/config'],
swift: ['file.swift'],
swiftgyb: ['file.swift.gyb'],
+ swig: ['file.swg', 'file.swig'],
sysctl: ['/etc/sysctl.conf', '/etc/sysctl.d/file.conf', 'any/etc/sysctl.conf', 'any/etc/sysctl.d/file.conf'],
systemd: ['any/systemd/file.automount', 'any/systemd/file.dnssd',
'any/systemd/file.link', 'any/systemd/file.mount',
@@ -2340,4 +2341,34 @@ func Test_vba_file()
filetype off
endfunc
+func Test_i_file()
+ filetype on
+
+ " Swig: keyword
+ call writefile(['%module mymodule', '/* a comment */'], 'Xfile.i', 'D')
+ split Xfile.i
+ call assert_equal('swig', &filetype)
+ bwipe!
+
+ " Swig: verbatim block
+ call writefile(['%{', '#include <header.hpp>', '%}'], 'Xfile.i', 'D')
+ split Xfile.i
+ call assert_equal('swig', &filetype)
+ bwipe!
+
+ " ASM
+ call writefile(['; comment', ';'], 'Xfile.i', 'D')
+ split Xfile.i
+ call assert_equal('asm', &filetype)
+ bwipe!
+
+ " *.i defaults to progress
+ call writefile(['looks like progress'], 'Xfile.i', 'D')
+ split Xfile.i
+ call assert_equal('progress', &filetype)
+ bwipe!
+
+ filetype off
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 6f3397e98e..a9d0bdd2b4 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2128,
+/**/
2127,
/**/
2126,