aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2024-12-31 11:53:02 +0100
committerChristian Clason <ch.clason+github@icloud.com>2024-12-31 12:29:35 +0100
commit1877cd5fcdc0bbe5f3d0685d42d4e295fb819724 (patch)
treeb0171f103d6e42e5c71cf1b688565e7dd56f9273
parent7ecd348b3da3bd27a0dd8db07896bf17a86bb26c (diff)
downloadrneovim-1877cd5fcdc0bbe5f3d0685d42d4e295fb819724.tar.gz
rneovim-1877cd5fcdc0bbe5f3d0685d42d4e295fb819724.tar.bz2
rneovim-1877cd5fcdc0bbe5f3d0685d42d4e295fb819724.zip
vim-patch:9.1.0982: TI linker files are not recognized
Problem: TI linker files are not recognized Solution: inspect '*.cmd' files and detect TI linker files as 'lnk' filetype, include a lnk ftplugin and syntax script (Wu, Zhenyu) closes: vim/vim#16320 https://github.com/vim/vim/commit/39a4eb0b2ca901b59800fad086550053556e59dc Co-authored-by: Wu, Zhenyu <wuzhenyu@ustc.edu>
-rw-r--r--runtime/ftplugin/lnk.vim14
-rw-r--r--runtime/lua/vim/filetype.lua2
-rw-r--r--runtime/lua/vim/filetype/detect.lua18
-rw-r--r--runtime/syntax/cmacro.vim77
-rw-r--r--runtime/syntax/lnk.vim40
-rw-r--r--test/old/testdir/test_filetype.vim21
6 files changed, 171 insertions, 1 deletions
diff --git a/runtime/ftplugin/lnk.vim b/runtime/ftplugin/lnk.vim
new file mode 100644
index 0000000000..8b280d9836
--- /dev/null
+++ b/runtime/ftplugin/lnk.vim
@@ -0,0 +1,14 @@
+" Vim filetype plugin file
+" Language: TI linker command file
+" Document: https://software-dl.ti.com/ccs/esd/documents/sdto_cgt_Linker-Command-File-Primer.html
+" Maintainer: Wu, Zhenyu <wuzhenyu@ustc.edu>
+" Last Change: 2024 Dec 31
+
+if exists("b:did_ftplugin") | finish | endif
+let b:did_ftplugin = 1
+
+setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:///,://
+setlocal commentstring=/*\ %s\ */
+setlocal iskeyword+=.
+
+let b:undo_ftplugin = "setl commentstring< comments< iskeyword<"
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
index cef3d667d3..173de8b5d5 100644
--- a/runtime/lua/vim/filetype.lua
+++ b/runtime/lua/vim/filetype.lua
@@ -1393,7 +1393,7 @@ local extension = {
txt = detect.txt,
xml = detect.xml,
y = detect.y,
- cmd = detect_line1('^/%*', 'rexx', 'dosbatch'),
+ cmd = detect.cmd,
rul = detect.rul,
cpy = detect_line1('^##', 'python', 'cobol'),
dsl = detect_line1('^%s*<!', 'dsl', 'structurizr'),
diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua
index 0d9c1ebc2b..a1c17bc1af 100644
--- a/runtime/lua/vim/filetype/detect.lua
+++ b/runtime/lua/vim/filetype/detect.lua
@@ -219,6 +219,24 @@ function M.cls(_, bufnr)
return 'st'
end
+--- *.cmd is close to a Batch file, but on OS/2 Rexx files and TI linker command files also use *.cmd.
+--- lnk: `/* comment */`, `// comment`, and `--linker-option=value`
+--- rexx: `/* comment */`, `-- comment`
+--- @type vim.filetype.mapfn
+function M.cmd(_, bufnr)
+ local lines = table.concat(getlines(bufnr, 1, 20))
+ if matchregex(lines, [[MEMORY\|SECTIONS\|\%(^\|\n\)--\S\|\%(^\|\n\)//]]) then
+ return 'lnk'
+ else
+ local line1 = getline(bufnr, 1)
+ if line1:find('^/%*') then
+ return 'rexx'
+ else
+ return 'dosbatch'
+ end
+ end
+end
+
--- @type vim.filetype.mapfn
function M.conf(path, bufnr)
if fn.did_filetype() ~= 0 or path:find(vim.g.ft_ignore_pat) then
diff --git a/runtime/syntax/cmacro.vim b/runtime/syntax/cmacro.vim
new file mode 100644
index 0000000000..1d448f0d1b
--- /dev/null
+++ b/runtime/syntax/cmacro.vim
@@ -0,0 +1,77 @@
+" Vim syntax file
+" Language: C macro for C preprocessor
+" Maintainer: Wu, Zhenyu <wuzhenyu@ustc.edu>
+" Last Change: 2024 Dec 31
+" modified from syntax/c.vim
+
+" C compiler has a preprocessor: `cpp -P test.txt`
+" test.txt doesn't need to be a C file
+if exists("b:current_syntax")
+ finish
+endif
+
+let s:cpo_save = &cpo
+set cpo&vim
+
+" Accept %: for # (C99)
+syn region cmacroPreCondit start="^\s*\zs\%(%:\|#\)\s*\%(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" keepend contains=cmacroCppParen,cmacroNumbers
+syn match cmacroPreConditMatch display "^\s*\zs\%(%:\|#\)\s*\%(else\|endif\)\>"
+if !exists("c_no_if0")
+ syn cluster cmacroCppOutInGroup contains=cmacroCppInIf,cmacroCppInElse,cmacroCppInElse2,cmacroCppOutIf,cmacroCppOutIf2,cmacroCppOutElse,cmacroCppInSkip,cmacroCppOutSkip
+ syn region cmacroCppOutWrapper start="^\s*\zs\%(%:\|#\)\s*if\s\+0\+\s*\%($\|//\|/\*\|&\)" end=".\@=\|$" contains=cmacroCppOutIf,cmacroCppOutElse,@NoSpell fold
+ syn region cmacroCppOutIf contained start="0\+" matchgroup=cmacroCppOutWrapper end="^\s*\%(%:\|#\)\s*endif\>" contains=cmacroCppOutIf2,cmacroCppOutElse
+ if !exists("c_no_if0_fold")
+ syn region cmacroCppOutIf2 contained matchgroup=cmacroCppOutWrapper start="0\+" end="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0\+\s*\%($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cmacroCppOutSkip,@Spell fold
+ else
+ syn region cmacroCppOutIf2 contained matchgroup=cmacroCppOutWrapper start="0\+" end="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0\+\s*\%($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cmacroCppOutSkip,@Spell
+ endif
+ syn region cmacroCppOutElse contained matchgroup=cmacroCppOutWrapper start="^\s*\%(%:\|#\)\s*\%(else\|elif\)" end="^\s*\%(%:\|#\)\s*endif\>"me=s-1 contains=TOP,cmacroPreCondit
+ syn region cmacroCppInWrapper start="^\s*\zs\%(%:\|#\)\s*if\s\+0*[1-9]\d*\s*\%($\|//\|/\*\||\)" end=".\@=\|$" contains=cmacroCppInIf,cmacroCppInElse fold
+ syn region cmacroCppInIf contained matchgroup=cmacroCppInWrapper start="\d\+" end="^\s*\%(%:\|#\)\s*endif\>" contains=TOP,cmacroPreCondit
+ if !exists("c_no_if0_fold")
+ syn region cmacroCppInElse contained start="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0*[1-9]\d*\s*\%($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cmacroCppInIf contains=cmacroCppInElse2 fold
+ else
+ syn region cmacroCppInElse contained start="^\s*\%(%:\|#\)\s*\%(else\>\|elif\s\+\%(0*[1-9]\d*\s*\%($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cmacroCppInIf contains=cmacroCppInElse2
+ endif
+ syn region cmacroCppInElse2 contained matchgroup=cmacroCppInWrapper start="^\s*\%(%:\|#\)\s*\%(else\|elif\)\%([^/]\|/[^/*]\)*" end="^\s*\%(%:\|#\)\s*endif\>"me=s-1 contains=cmacroCppOutSkip,@Spell
+ syn region cmacroCppOutSkip contained start="^\s*\%(%:\|#\)\s*\%(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\%(%:\|#\)\s*endif\>" contains=cmacroCppOutSkip
+ syn region cmacroCppInSkip contained matchgroup=cmacroCppInWrapper start="^\s*\%(%:\|#\)\s*\%(if\s\+\%(\d\+\s*\%($\|//\|/\*\||\|&\)\)\@!\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\%(%:\|#\)\s*endif\>" containedin=cmacroCppOutElse,cmacroCppInIf,cmacroCppInSkip contains=TOP,cmacroPreProc
+endif
+syn region cmacroIncluded display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
+syn match cmacroIncluded display contained "<[^>]*>"
+syn match cmacroInclude display "^\s*\zs\%(%:\|#\)\s*include\>\s*["<]" contains=cmacroIncluded
+"syn match cmacroLineSkip "\\$"
+syn cluster cmacroPreProcmacroGroup contains=cmacroPreCondit,cmacroIncluded,cmacroInclude,cmacroDefine,cmacroCppOutWrapper,cmacroCppInWrapper,@cmacroCppOutInGroup,cmacroNumbersCom,@cmacroCommentGroup,cmacroParen,cmacroBracket,cmacroMulti,cmacroBadBlock
+syn region cmacroDefine start="^\s*\zs\%(%:\|#\)\s*\%(define\|undef\)\>" skip="\\$" end="$" keepend contains=ALLBUT,@cmacroPreProcmacroGroup,@Spell
+syn region cmacroPreProc start="^\s*\zs\%(%:\|#\)\s*\%(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@cmacroPreProcmacroGroup,@Spell
+
+" be able to fold #pragma regions
+syn region cmacroPragma start="^\s*#pragma\s\+region\>" end="^\s*#pragma\s\+endregion\>" transparent keepend extend fold
+
+syn keyword cmacroTodo contained TODO FIXME XXX NOTE
+syn region cmacroComment start='/\*' end='\*/' contains=cmacroTodo,@Spell
+syn match cmacroCommentError "\*/"
+syn region cmacroComment start='//' end='$' contains=cmacroTodo,@Spell
+
+" Define the default highlighting.
+" Only used when an item doesn't have highlighting yet
+hi def link cmacroInclude Include
+hi def link cmacroPreProc PreProc
+hi def link cmacroDefine Macro
+hi def link cmacroIncluded cmacroString
+hi def link cmacroCppInWrapper cmacroCppOutWrapper
+hi def link cmacroCppOutWrapper cmacroPreCondit
+hi def link cmacroPreConditMatch cmacroPreCondit
+hi def link cmacroPreCondit PreCondit
+hi def link cmacroCppOutSkip cmacroCppOutIf2
+hi def link cmacroCppInElse2 cmacroCppOutIf2
+hi def link cmacroCppOutIf2 cmacroCppOut
+hi def link cmacroCppOut Comment
+hi def link cmacroTodo Todo
+hi def link cmacroComment Comment
+hi def link cmacroCommentError Error
+
+let b:current_syntax = "cmacro"
+
+let &cpo = s:cpo_save
+unlet s:cpo_save
diff --git a/runtime/syntax/lnk.vim b/runtime/syntax/lnk.vim
new file mode 100644
index 0000000000..45ca382aca
--- /dev/null
+++ b/runtime/syntax/lnk.vim
@@ -0,0 +1,40 @@
+" Vim syntax file
+" Language: TI linker command file
+" Document: https://downloads.ti.com/docs/esd/SPRUI03A/Content/SPRUI03A_HTML/linker_description.html
+" Document: https://software-dl.ti.com/ccs/esd/documents/sdto_cgt_Linker-Command-File-Primer.html
+" Maintainer: Wu, Zhenyu <wuzhenyu@ustc.edu>
+" Last Change: 2024 Dec 31
+
+if exists("b:current_syntax")
+ finish
+endif
+
+runtime! syntax/cmacro.vim
+
+syn case ignore
+syn match lnkNumber "0x[0-9a-f]\+"
+" Linker command files are ASCII files that contain one or more of the following:
+" Input filenames, which specify object files, archive libraries, or other command files.
+" Linker options, which can be used in the command file in the same manner that they are used on the command line
+syn match lnkOption "^[-+][-_a-zA-Z#@]\+"
+syn match lnkOption "^--[^ \t$=`'"|);]\+"
+syn match lnkFile '[^ =]\+\%(\.\S\+\)\+\>'
+syn match lnkLibFile '[^ =]\+\.lib\>'
+" The MEMORY and SECTIONS linker directives. The MEMORY directive defines the target memory configuration (see Section 8.5.4). The SECTIONS directive controls how sections are built and allocated (see Section 8.5.5.)
+syn keyword lnkKeyword ADDRESS_MASK f LOAD ORIGIN START ALGORITHM FILL LOAD_END PAGE TABLE ALIGN GROUP LOAD_SIZE PALIGN TYPE ATTR HAMMING_MASK LOAD_START PARITY_MASK UNION BLOCK HIGH MEMORY RUN UNORDERED COMPRESSION INPUT_PAGE MIRRORING RUN_END VFILL COPY INPUT_RANGE NOINIT RUN_SIZE DSECT l NOLOAD RUN_START ECC LEN o SECTIONS END LENGTH ORG SIZE
+syn region lnkLibrary start=+<+ end=+>+
+syn match lnkAttrib '\<[RWXI]\+\>'
+syn match lnkSections '\<\.\k\+'
+" Assignment statements, which define and assign values to global symbols
+syn case match
+
+hi def link lnkNumber Number
+hi def link lnkOption Special
+hi def link lnkKeyword Keyword
+hi def link lnkLibrary String
+hi def link lnkFile String
+hi def link lnkLibFile Special
+hi def link lnkAttrib Type
+hi def link lnkSections Macro
+
+let b:current_syntax = "lnk"
diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim
index 462bf2e025..1bf2bdb360 100644
--- a/test/old/testdir/test_filetype.vim
+++ b/test/old/testdir/test_filetype.vim
@@ -2300,6 +2300,27 @@ func Test_cls_file()
filetype off
endfunc
+func Test_cmd_file()
+ filetype on
+
+ call writefile(['--rom_model'], 'Xfile.cmd')
+ split Xfile.cmd
+ call assert_equal('lnk', &filetype)
+ bwipe!
+
+ call writefile(['/* comment */'], 'Xfile.cmd')
+ split Xfile.cmd
+ call assert_equal('rexx', &filetype)
+ bwipe!
+
+ call writefile(['REM comment'], 'Xfile.cmd')
+ split Xfile.cmd
+ call assert_equal('dosbatch', &filetype)
+ bwipe!
+
+ filetype off
+endfunc
+
func Test_sig_file()
filetype on