patch 9.1.0982: TI linker files are not recognized
Commit:
https://github.com/vim/vim/commit/39a4eb0b2ca901b59800fad086550053556e59dc
Author: Wu, Zhenyu <[email protected]>
Date: Tue Dec 31 10:25:44 2024 +0100
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: #16320
Signed-off-by: Wu, Zhenyu <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index 4244e0ce6..1adb4038b 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -1,7 +1,7 @@
" Vim support file to detect file types
"
" Maintainer: The Vim Project <https://github.com/vim/vim>
-" Last Change: 2024 Dec 30
+" Last Change: 2024 Dec 31
" Former Maintainer: Bram Moolenaar <[email protected]>
" Listen very carefully, I will say this only once
@@ -240,9 +240,17 @@ au BufNewFile,BufRead *.fb setf freebasic
" Batch file for MSDOS. See dist#ft#FTsys for *.sys
au BufNewFile,BufRead *.bat setf dosbatch
-" *.cmd is close to a Batch file, but on OS/2 Rexx files also use *.cmd.
+" *.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`
au BufNewFile,BufRead *.cmd
- \ if getline(1) =~ '^/\*' | setf rexx | else | setf dosbatch | endif
+ \ if join(getline(1, 20), "
") =~ 'MEMORY\|SECTIONS\|\%(^\|
\)--\S\|\%(^\|
\)//'
+ \| setf lnk
+ \| elseif getline(1) =~ '^/\*'
+ \| setf rexx
+ \| else
+ \| setf dosbatch
+ \| endif
" ABB RAPID or Batch file for MSDOS.
au BufNewFile,BufRead *.sys call dist#ft#FTsys()
if has("fname_case")
diff --git a/runtime/ftplugin/lnk.vim b/runtime/ftplugin/lnk.vim
new file mode 100644
index 000000000..8b280d983
--- /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 <[email protected]>
+" 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/syntax/cmacro.vim b/runtime/syntax/cmacro.vim
new file mode 100644
index 000000000..1d448f0d1
--- /dev/null
+++ b/runtime/syntax/cmacro.vim
@@ -0,0 +1,77 @@
+" Vim syntax file
+" Language: C macro for C preprocessor
+" Maintainer: Wu, Zhenyu <[email protected]>
+" 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 000000000..45ca382ac
--- /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 <[email protected]>
+" 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 "^--[^ $=`'"|);]\+"
+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/src/testdir/test_filetype.vim b/src/testdir/test_filetype.vim
index 0373055a7..66942b90c 100644
--- a/src/testdir/test_filetype.vim
+++ b/src/testdir/test_filetype.vim
@@ -2309,6 +2309,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
diff --git a/src/version.c b/src/version.c
index a8f0eea6c..a4b0fc45e 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 982,
/**/
981,
/**/
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1tSYZh-00FePY-Gv%40256bit.org.