runtime(tex): improve syntax highlighting
Commit:
https://github.com/vim/vim/commit/a35040f795fbf217b0a1e21b6b3a94ad56c2298b
Author: Eisuke Kawashima <[email protected]>
Date: Sat Feb 8 18:32:14 2025 +0100
runtime(tex): improve syntax highlighting
this change includes the following changes:
- a macro option must be
https://github.com/vim/vim/issues/1–https://github.com/vim/vim/issues/9
- add \providecommand
- add starred versions of
ewcommand,
ewenvironment, and their
variants
- add number of arguments to \(re)newenvironment
Signed-off-by: Eisuke Kawashima <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/runtime/syntax/testdir/dumps/tex_02_00.dump
b/runtime/syntax/testdir/dumps/tex_02_00.dump
new file mode 100644
index 000000000..5c79b8f55
--- /dev/null
+++ b/runtime/syntax/testdir/dumps/tex_02_00.dump
@@ -0,0 +1,20 @@
+>\+0#af5f00255#ffffff0|d|o|c|u|m|e|n|t|c|l|a|s@1|{+0#e000e06&|a|r|t|i|c|l|e|}|
+0#0000000&@51
+|\+0#af5f00255&|n|e|w|c|o|m@1|a|n|d|{+0#e000e06&|\+0#af5f00255&|f|o@1|}+0#e000e06&|{|}|
+0#0000000&@55
+|\+0#af5f00255&|r|e|n|e|w|c|o|m@1|a|n|d|*|{+0#e000e06&|\+0#af5f00255&|f|o@1|}+0#e000e06&|[|1+0#e000002&|]+0#e000e06&|{|#|1|0+0#0000000&|}+0#e000e06&|
+0#0000000&@46
+|\+0#af5f00255&|p|r|o|v|i|d|e|c|o|m@1|a|n|d|{+0#e000e06&|\+0#af5f00255&|f|o@1|}+0#e000e06&|[|1+0#e000002&|]+0#e000e06&|[|d+0#0000000&|e|f|a|u|l|t|]+0#e000e06&|{|#|1|1+0#0000000&|}+0#e000e06&|
+0#0000000&@36
+|\+0#af5f00255&|n|e|w|e|n|v|i|r|o|n|m|e|n|t|*|{+0#e000e06&|b+0#0000000&|a|z|}+0#e000e06&|{|S+0#0000000&|T|A|R|T|}+0#e000e06&|{|S+0#0000000&|T|O|P|}+0#e000e06&|
+0#0000000&@40
+|\+0#af5f00255&|r|e|n|e|w|e|n|v|i|r|o|n|m|e|n|t|{+0#e000e06&|b+0#0000000&|a|z|}+0#e000e06&|[|1+0#e000002&|]+0#e000e06&|{|H+0#0000000&|E|A|D|
|o|f|
|#+0#e000e06&|1|2+0#0000000&|:|}+0#e000e06&|{|T+0#0000000&|A|I|L|}+0#e000e06&|
+0#0000000&@29
+|\+0#af5f00255&|r|e|n|e|w|e|n|v|i|r|o|n|m|e|n|t|*|{+0#e000e06&|b+0#0000000&|a|z|}+0#e000e06&|[|1+0#e000002&|]+0#e000e06&|[|d+0#0000000&|e|f|a|u|l|t|]+0#e000e06&|{|B+0#0000000&|E|G|I|N@1|I|N|G|
|o|f|
|#+0#e000e06&|1|2+0#0000000&|:|}+0#e000e06&|{|E+0#0000000&|N|D|}+0#e000e06&|
+0#0000000&@15
+|\+0#e000e06&|b|e|g|i|n|{|d|o|c|u|m|e|n|t|}| +0#0000000&@58
+|\+0#af5f00255&|f|o@1|{+0#e000e06&|T+0#0000000&|e|X|}+0#e000e06&|
+0#0000000&@1|%+0#0000e05&| |-|>| |T|e|X|0| +0#0000000&@54
+|\+0#af5f00255&|b|e|g|i|n|{+0#e000e06&|b|a|z|}| +0#0000000&|t|e|x|
|\+0#af5f00255&|e|n|d|{+0#e000e06&|b|a|z|}| +0#0000000&@1|%+0#0000e05&| |-|>|
|B|E|G|I|N@1|I|N|G| |o|f| |d|e|f|a|u|l|t|2|:|t|e|x| |E|N|D| +0#0000000&@13
+|\+0#e000e06&|e|n|d|{|d|o|c|u|m|e|n|t|}| +0#0000000&@60
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+| +0#0000000&@56|1|,|1| @10|A|l@1|
diff --git a/runtime/syntax/testdir/input/tex_02.tex
b/runtime/syntax/testdir/input/tex_02.tex
new file mode 100644
index 000000000..0d6e92a21
--- /dev/null
+++ b/runtime/syntax/testdir/input/tex_02.tex
@@ -0,0 +1,11 @@
+\documentclass{article}
+
ewcommand{oo}{}
+
enewcommand*{oo}[1]{#10}
+\providecommand{oo}[1][default]{#11}
+
ewenvironment*{baz}{START}{STOP}
+
enewenvironment{baz}[1]{HEAD of #12:}{TAIL}
+
enewenvironment*{baz}[1][default]{BEGINNING of #12:}{END}
+ egin{document}
+oo{TeX} % -> TeX0
+ egin{baz} tex nd{baz} % -> BEGINNING of default2:tex END
+ nd{document}
diff --git a/runtime/syntax/tex.vim b/runtime/syntax/tex.vim
index 4f35bba93..109ce61b7 100644
--- a/runtime/syntax/tex.vim
+++ b/runtime/syntax/tex.vim
@@ -5,6 +5,8 @@
" Last Change: Apr 22, 2022
" 2024 Feb 19 by Vim Project: announce adoption
" 2025 Jan 18 by Vim Project: add texEmphStyle to texMatchGroup, #16228
+" 2025 Feb 08 by Vim Project: improve macro option, \providecommand,
+"
ewcommand and
ewenvironment #16543
" Version: 121
" Former URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_TEX
"
@@ -167,7 +169,7 @@ syn cluster texCmdGroup
contains=texCmdBody,texComment,texDefParm,texDelimiter
if !s:tex_no_error
syn cluster texCmdGroup add=texMathError
endif
-syn cluster texEnvGroup
contains=texMatcher,texMathDelim,texSpecialChar,texStatement
+syn cluster texEnvGroup
contains=texDefParm,texMatcher,texMathDelim,texSpecialChar,texStatement
syn cluster texFoldGroup
contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texInputFile,texLength,texLigature,texMatcher,texMathZoneV,texMathZoneW,texMathZoneX,texMathZoneY,texMathZoneZ,texNewCmd,texNewEnv,texOnlyMath,texOption,texParen,texRefZone,texSection,texBeginEnd,texSectionZone,texSpaceCode,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,@texMathZones,texTitle,texAbstract,texBoldStyle,texItalStyle,texEmphStyle,texNoSpell
syn cluster texBoldGroup
contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texInputFile,texLength,texLigature,texMathZoneV,texMathZoneW,texMathZoneX,texMathZoneY,texMathZoneZ,texNewCmd,texNewEnv,texOnlyMath,texOption,texParen,texRefZone,texSection,texBeginEnd,texSectionZone,texSpaceCode,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,@texMathZones,texTitle,texAbstract,texBoldStyle,texBoldItalStyle,texNoSpell
syn cluster texItalGroup
contains=texAccent,texBadMath,texComment,texDefCmd,texDelimiter,texDocType,texInput,texInputFile,texLength,texLigature,texMathZoneV,texMathZoneW,texMathZoneX,texMathZoneY,texMathZoneZ,texNewCmd,texNewEnv,texOnlyMath,texOption,texParen,texRefZone,texSection,texBeginEnd,texSectionZone,texSpaceCode,texSpecialChar,texStatement,texString,texTypeSize,texTypeStyle,texZone,@texMathZones,texTitle,texAbstract,texItalStyle,texEmphStyle,texItalBoldStyle,texNoSpell
@@ -287,7 +289,7 @@ syn match texDelimiter "&"
syn match texDelimiter "\\"
" Tex/Latex Options: {{{1
-syn match texOption "[^\]\zs#\d\+\|^#\d\+"
+syn match texOption "[^\]\zs#[1-9]\|^#[1-9]"
" texAccent (tnx to Karim Belabas) avoids annoying highlighting for accents:
{{{1
if b:tex_stylish
@@ -669,16 +671,46 @@ if s:tex_fast =~# 'r'
endif
syn match texRefZone '\cite\%([tp]\*\=\)\=\>'
nextgroup=texRefOption,texCite
-" Handle (re)newcommand, (re)newenvironment : {{{1
-syn match texNewCmd "\\%(re\)\=newcommand\>"
nextgroup=texCmdName skipwhite skipnl
+" Handle (re)newcommand, providecommand, (re)newenvironment : {{{1
+" EXAMPLE:
+"
+" The followings are valid (ignoring error due to redefinition):
+"
+"
ewcommand{oo}{body}
+"
ewcommand{oo}[1]{#1}
+"
ewcommand{oo}[1][def]{#1}
+"
+" The followings are ill-formed:
+"
+"
ewcommand{oo}{#1} ! Illegal parameter number in definition of oo.
+"
ewcommand{oo}[x]{…} ! Missing number, treated as zero.
+"
ewcommand{oo}[10]{…} ! You already have nine parameters.
+syn match texNewCmd
"\\%(\%(re\)\=new\|provide\)command\>\*\?" nextgroup=texCmdName skipwhite
skipnl
if s:tex_fast =~# 'V'
syn region texCmdName contained matchgroup=texDelimiter start="{"rs=s+1
end="}" nextgroup=texCmdArgs,texCmdBody skipwhite skipnl
- syn region texCmdArgs contained matchgroup=texDelimiter start="\["rs=s+1
end="]" nextgroup=texCmdBody skipwhite skipnl
+ syn region texCmdArgs contained matchgroup=texDelimiter start="\["rs=s+1
end="]" nextgroup=texCmdDefaultPar,texCmdBody skipwhite skipnl
+ syn region texCmdDefaultPar contained matchgroup=texDelimiter
start="\["rs=s+1 end="]" nextgroup=texCmdBody skipwhite skipnl
syn region texCmdBody contained matchgroup=texDelimiter start="{"rs=s+1
skip="\\\|\[{}]" matchgroup=texDelimiter end="}" contains=@texCmdGroup
endif
-syn match texNewEnv "\\%(re\)\=newenvironment\>"
nextgroup=texEnvName skipwhite skipnl
+" EXAMPLE:
+"
+" The followings are valid (ignoring error due to redefinition):
+"
+"
ewenvironment{baz}{beg}{end}
+"
ewenvironment{baz}[1]{beg #1}{end}
+"
ewenvironment{baz}[1][default]{beg #1}{end}
+"
+" The followings are invalid:
+"
+"
ewenvironment{baz}{#1}{…} ! Illegal parameter number in
definition of az.
+"
ewenvironment{baz}[x]{…}{…} ! Missing number, treated as zero.
+"
ewenvironment{baz}[10]{…}{…} ! You already have nine parameters.
+"
ewenvironment{baz}[1]{…}{#1} ! Illegal parameter number in definition of
ndbaz.
+syn match texNewEnv
"\\%(re\)\=newenvironment\>\*\?" nextgroup=texEnvName skipwhite
skipnl
if s:tex_fast =~# 'V'
- syn region texEnvName contained matchgroup=texDelimiter start="{"rs=s+1
end="}" nextgroup=texEnvBgn skipwhite skipnl
+ syn region texEnvName contained matchgroup=texDelimiter start="{"rs=s+1
end="}" nextgroup=texEnvArgs,texEnvBgn skipwhite skipnl
+ syn region texEnvArgs contained matchgroup=texDelimiter start="\["rs=s+1
end="]" nextgroup=texEnvDefaultPar,texEnvBgn skipwhite skipnl
+ syn region texEnvDefaultPar contained matchgroup=texDelimiter
start="\["rs=s+1 end="]" nextgroup=texEnvBgn skipwhite skipnl
syn region texEnvBgn contained matchgroup=texDelimiter start="{"rs=s+1
end="}" nextgroup=texEnvEnd skipwhite skipnl contains=@texEnvGroup
syn region texEnvEnd contained matchgroup=texDelimiter start="{"rs=s+1
end="}" skipwhite skipnl contains=@texEnvGroup
endif
@@ -693,7 +725,7 @@ else
syn match texDefName contained "\\A"
nextgroup=texDefParms,texCmdBody skipwhite skipnl
endif
syn match texDefParms contained "#[^{]*"
contains=texDefParm nextgroup=texCmdBody skipwhite skipnl
-syn match texDefParm contained "#\d\+"
+syn match texDefParm contained "#[1-9]"
" TeX Lengths: {{{1
syn match texLength
"\<\d\+\([.,]\d\+\)\=\s*\(true\)\=\s*\(bp\|cc\|cm\|dd\|em\|ex\|in\|mm\|pc\|pt\|sp\)\>"
@@ -1325,6 +1357,7 @@ if !exists("skip_tex_syntax_inits")
hi def link texDef Statement
hi def link texDefParm Special
hi def link texDelimiter Delimiter
+ hi def link texEnvArgs Number
hi def link texInput Special
hi def link texInputFile Special
hi def link texLength Number
--
--
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/E1tgot5-00EnmK-MX%40256bit.org.