Skip to content

Commit e10525a

Browse files
committed
feat: allow groupless args for g:vimtex_syntax_custom_cmds
refer: #1972
1 parent 0215df5 commit e10525a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

autoload/vimtex/syntax/core.vim

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,8 @@ function! vimtex#syntax#core#new_cmd(cfg) abort " {{{1
10801080
let l:group_cmd = l:pre . 'Cmd' . l:name
10811081
let l:group_opt = l:pre . l:name . 'Opt'
10821082
let l:group_arg = l:pre . l:name . 'Arg'
1083+
let l:group_arg_space = l:pre . l:name . 'Argspace'
1084+
let l:group_arg_char = l:pre . l:name . 'ArgChar'
10831085

10841086
" Specify rules for next groups
10851087
if !empty(l:cfg.nextgroup)
@@ -1092,7 +1094,7 @@ function! vimtex#syntax#core#new_cmd(cfg) abort " {{{1
10921094

10931095
let l:opt_cfg = {'opts': l:cfg.optconceal ? 'conceal' : ''}
10941096
if l:cfg.arg
1095-
let l:opt_cfg.next = l:group_arg
1097+
let l:opt_cfg.next = l:group_arg_space
10961098
endif
10971099
call vimtex#syntax#core#new_opt(l:group_opt, l:opt_cfg)
10981100

@@ -1101,7 +1103,13 @@ function! vimtex#syntax#core#new_cmd(cfg) abort " {{{1
11011103

11021104
" Add syntax rules for the argument group
11031105
if l:cfg.arg
1104-
let l:nextgroups += [l:group_arg]
1106+
let l:nextgroups += [l:group_arg_space]
1107+
1108+
execute 'syntax match' l:group_arg_space '"\s*"'
1109+
\ 'contained nextgroup=' .. l:group_arg_char .. ',' .. l:group_arg
1110+
\ l:cfg.conceal ? 'conceal' : ''
1111+
1112+
execute 'syntax match' l:group_arg_char '"\w"' 'contained'
11051113

11061114
let l:arg_cfg = {'opts': 'contained'}
11071115
if l:cfg.conceal && empty(l:cfg.concealchar)
@@ -1128,6 +1136,7 @@ function! vimtex#syntax#core#new_cmd(cfg) abort " {{{1
11281136
\}, l:cfg.argstyle,
11291137
\ l:cfg.mathmode ? 'texMathArg' : '')
11301138
if !empty(l:style)
1139+
execute 'highlight def link' l:group_arg_char l:style
11311140
execute 'highlight def link' l:group_arg l:style
11321141
endif
11331142
endif

test/test-syntax/test-custom.tex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,6 @@
3030

3131
$\mather{some text}$
3232

33+
$\mathcmda ffa$
34+
3335
\end{document}

0 commit comments

Comments
 (0)