# HG changeset patch # User Christian Brabandt # Date 1700923506 -3600 # Node ID d515e012d713725a111ad1d43ad8ed20e5804598 # Parent f084d22c6a9a322a6403b1d1ed5d70eae8a487c7 patch 9.0.2128: runtime(swig): add syntax and filetype plugins Commit: https://github.com/vim/vim/commit/2e31065a650015892179e520038bf2083a9519b6 Author: Julien Marrec Date: Sat Nov 25 15:30:46 2023 +0100 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 #1247 (which I found after writing this). closes: #13562 Co-authored-by: Mat?j Cepl Co-authored-by: Julien Marrec Signed-off-by: Julien Marrec Signed-off-by: Doug Kearns Signed-off-by: Christian Brabandt diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -224,6 +224,7 @@ runtime/ftplugin/spec.vim @ignatenkobra 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 --- 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 --- a/runtime/filetype.vim +++ b/runtime/filetype.vim @@ -1688,8 +1688,8 @@ au BufNewFile,BufRead .procmail,.procmai " 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 " 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 --- /dev/null +++ b/runtime/ftplugin/swig.vim @@ -0,0 +1,13 @@ +" Vim filetype plugin file +" Language: SWIG +" Maintainer: Julien Marrec +" 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 --- /dev/null +++ b/runtime/syntax/swig.vim @@ -0,0 +1,99 @@ +" Vim syntax file +" Language: SWIG +" Maintainer: Julien Marrec +" 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 --- a/src/testdir/test_filetype.vim +++ b/src/testdir/test_filetype.vim @@ -673,6 +673,7 @@ def s:GetFilenameChecks(): dict', '%}'], '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 --- 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,