comparison runtime/syntax/dosbatch.vim @ 34285:9c674ef89d9d

runtime(dosbatch): improve '::' comment highlighting Commit: https://github.com/vim/vim/commit/f7f33e3719c87279dfad109b874e2817007a1184 Author: Christian Brabandt <cb@256bit.org> Date: Tue Feb 6 10:56:26 2024 +0100 runtime(dosbatch): improve '::' comment highlighting Added a syntax region for command blocks so that the highlighting of `::` comments in them can be controlled. The `dosbatch_colons_comment` variable now controls if all `::` comments in a code block are highlighted as comments or errors. A `::` comment at the end of a command block is always highlighted as an error. This re-enables the highlighting of `::` comments in `.bat` files as requested in #13666, while allowing control of highlighting them in command blocks requested in #11778 and first attempted in #11980. related: #11980 fixes: #13666 Co-authored-by: Mike Williams <mikew@globalgraphics.com> Signed-off-by: Mike Williams <mikew@globalgraphics.com> Signed-off-by: mevanlc <mevanlc@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Tue, 06 Feb 2024 11:00:14 +0100
parents a9b5ffbc0428
children
comparison
equal deleted inserted replaced
34284:757a81de9ec4 34285:9c674ef89d9d
1 " Vim syntax file 1 " Vim syntax file
2 " Language: MS-DOS/Windows batch file (with NT command extensions) 2 " Language: MS-DOS/Windows batch file (with NT command extensions)
3 " Maintainer: Mike Williams <mrmrdubya@gmail.com> 3 " Maintainer: Mike Williams <mrmrdubya@gmail.com>
4 " Filenames: *.bat 4 " Filenames: *.bat
5 " Last Change: 12th February 2023 5 " Last Change: 3rd February 2024
6 " 6 "
7 " Options Flags: 7 " Options Flags:
8 " dosbatch_cmdextversion - 1 = Windows NT, 2 = Windows 2000 [default] 8 " dosbatch_cmdextversion - 1 = Windows NT, 2 = Windows 2000 [default]
9 " dosbatch_colons_comment - any value to treat :: as comment line 9 " dosbatch_colons_comment - any value to allow :: comments in code blocks
10 " 10 "
11 11
12 " quit when a syntax file was already loaded 12 " quit when a syntax file was already loaded
13 if exists("b:current_syntax") 13 if exists("b:current_syntax")
14 finish 14 finish
86 syn match dosbatchLabel "\<\(goto\|call\)\s\+:\h\w*\>"lc=4 86 syn match dosbatchLabel "\<\(goto\|call\)\s\+:\h\w*\>"lc=4
87 syn match dosbatchLabel "\<goto\s\+\h\w*\>"lc=4 87 syn match dosbatchLabel "\<goto\s\+\h\w*\>"lc=4
88 syn match dosbatchLabel ":\h\w*\>" 88 syn match dosbatchLabel ":\h\w*\>"
89 89
90 " Comments - usual rem but also two colons as first non-space is an idiom 90 " Comments - usual rem but also two colons as first non-space is an idiom
91 syn match dosbatchComment "^rem\($\|\s.*$\)"lc=3 contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell 91 syn match dosbatchRemComment "^rem\($\|\s.*$\)"lc=3 contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
92 syn match dosbatchComment "^@rem\($\|\s.*$\)"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell 92 syn match dosbatchRemComment "^@rem\($\|\s.*$\)"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
93 syn match dosbatchComment "\srem\($\|\s.*$\)"lc=4 contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell 93 syn match dosbatchRemComment "\srem\($\|\s.*$\)"lc=4 contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
94 syn match dosbatchComment "\s@rem\($\|\s.*$\)"lc=5 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell 94 syn match dosbatchRemComment "\s@rem\($\|\s.*$\)"lc=5 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
95 syn match dosbatchColonComment "\s*:\s*:.*$" contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell
96
97 " Commands code blocks
98 syn cluster dosbatchCodeBlockComment contains=dosbatchRemComment
95 if exists("dosbatch_colons_comment") 99 if exists("dosbatch_colons_comment")
96 syn match dosbatchComment "\s*:\s*:.*$" contains=dosbatchTodo,dosbatchSpecialChar,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell 100 syn cluster dosbatchCodeBlockComment add=dosbatchColonComment
97 else 101 else
98 syn match dosbatchError "\s*:\s*:.*$" 102 syn match dosbatchColonCommentErr contained "\s*:\s*:.*$"
99 endif 103 endif
100 104 syn match dosbatchColonCommentErr contained "\s*:\s*:[^)]*\(\(\n\s*\)\?)\)\@="
101 " Comments in ()'s - still to handle spaces before rem 105 syn region dosbatchCodeBlock transparent start=+(+ end=+)+ contains=dosbatchString,dosbatchVariable,dosBatchArgument,@dosbatchNumber,dosbatchImplicit,dosbatchStatement,dosbatchConditional,dosbatchRepeat,dosbatchOperator,@dosbatchCodeBlockComment,dosbatchColonCommentErr,dosbatchCodeBlock
102 syn match dosbatchComment "(rem\([^)]\|\^\@<=)\)*"lc=4 contains=dosbatchTodo,@dosbatchNumber,dosbatchVariable,dosbatchArgument,@Spell 106 syn match dosbatchCodeBlockErr ")"
103 107
104 syn keyword dosbatchImplicit append assoc at attrib break cacls cd chcp chdir 108 syn keyword dosbatchImplicit append assoc at attrib break cacls cd chcp chdir
105 syn keyword dosbatchImplicit chkdsk chkntfs cls cmd color comp compact convert copy 109 syn keyword dosbatchImplicit chkdsk chkntfs cls cmd color comp compact convert copy
106 syn keyword dosbatchImplicit date del dir diskcomp diskcopy doskey echo endlocal 110 syn keyword dosbatchImplicit date del dir diskcomp diskcopy doskey echo endlocal
107 syn keyword dosbatchImplicit erase fc find findstr format ftype 111 syn keyword dosbatchImplicit erase fc find findstr format ftype
114 " Define the default highlighting. 118 " Define the default highlighting.
115 " Only when an item doesn't have highlighting yet 119 " Only when an item doesn't have highlighting yet
116 120
117 hi def link dosbatchTodo Todo 121 hi def link dosbatchTodo Todo
118 hi def link dosbatchError Error 122 hi def link dosbatchError Error
123 hi def link dosbatchCodeBlockErr dosbatchError
124 hi def link dosbatchColonCommentErr dosbatchError
119 125
120 hi def link dosbatchStatement Statement 126 hi def link dosbatchStatement Statement
121 hi def link dosbatchCommands dosbatchStatement 127 hi def link dosbatchCommands dosbatchStatement
122 hi def link dosbatchLabel Label 128 hi def link dosbatchLabel Label
123 hi def link dosbatchConditional Conditional 129 hi def link dosbatchConditional Conditional
138 hi def link dosbatchHex dosbatchNumber 144 hi def link dosbatchHex dosbatchNumber
139 hi def link dosbatchBinary dosbatchNumber 145 hi def link dosbatchBinary dosbatchNumber
140 hi def link dosbatchOctal dosbatchNumber 146 hi def link dosbatchOctal dosbatchNumber
141 147
142 hi def link dosbatchComment Comment 148 hi def link dosbatchComment Comment
149 hi def link dosbatchRemComment dosbatchComment
150 hi def link dosbatchColonComment dosbatchComment
151
143 hi def link dosbatchImplicit Function 152 hi def link dosbatchImplicit Function
144 153
145 hi def link dosbatchSwitch Special 154 hi def link dosbatchSwitch Special
146 155
147 hi def link dosbatchCmd PreProc 156 hi def link dosbatchCmd PreProc