Skip to content

Commit a7ee089

Browse files
committed
feat(syntax): generalize nargs in custom_cmds_with_concealed_delims
refer: lervag#3132
1 parent bcb14eb commit a7ee089

File tree

4 files changed

+31
-30
lines changed

4 files changed

+31
-30
lines changed

autoload/vimtex/syntax/core.vim

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,9 +1175,11 @@ function! vimtex#syntax#core#new_cmd_with_concealed_delims(cfg) abort " {{{1
11751175
let l:pre = l:cfg.mathmode ? 'texMath' : 'tex'
11761176
let l:name = 'C' . toupper(l:cfg.name[0]) . l:cfg.name[1:]
11771177
let l:group_cmd = l:pre . 'Cmd' . l:name
1178-
let l:group_arg1 = l:pre . l:name . 'Arg'
1179-
let l:group_arg2 = l:pre . l:name . 'Arg2'
11801178
let l:group_delims = l:pre . l:name . 'ConcealedDelim'
1179+
let l:group_args = map(
1180+
\ range(1, l:cfg.nargs),
1181+
\ { _, x -> l:pre .. l:name .. 'Arg' .. x }
1182+
\)
11811183

11821184
if l:cfg.mathmode
11831185
let l:contains = '@texClusterMath'
@@ -1194,34 +1196,28 @@ function! vimtex#syntax#core#new_cmd_with_concealed_delims(cfg) abort " {{{1
11941196
\ empty(l:cfg.cchar_open)
11951197
\ ? 'conceal'
11961198
\ : 'conceal cchar=' . l:cfg.cchar_open
1197-
\ 'skipwhite nextgroup=' . l:group_arg1
1199+
\ 'skipwhite nextgroup=' . l:group_args[0]
11981200

1199-
if l:cfg.nargs == 1
1200-
execute 'syntax region' l:group_arg1
1201-
\ 'matchgroup=' . l:group_delims
1202-
\ empty(l:cfg.cchar_close)
1203-
\ ? 'concealends'
1204-
\ : 'concealends cchar=' . l:cfg.cchar_close
1205-
\ 'start="{" skip="\%#=1\\[\\\}]" end="}"'
1206-
\ 'contained contains=' . l:contains
1207-
else
1208-
execute 'syntax region' l:group_arg1
1201+
for l:i in range(l:cfg.nargs - 1)
1202+
let l:group_arg_current = l:group_args[l:i]
1203+
let l:group_arg_next = l:group_args[l:i + 1]
1204+
execute 'syntax region' l:group_arg_current
12091205
\ 'matchgroup=' . l:group_delims
12101206
\ empty(l:cfg.cchar_mid)
12111207
\ ? 'concealends'
12121208
\ : 'concealends cchar=' . l:cfg.cchar_mid
12131209
\ 'start="{" skip="\%#=1\\[\\\}]" end="}"'
12141210
\ 'contained contains=' . l:contains
1215-
\ 'skipwhite nextgroup=' . l:group_arg2
1211+
\ 'skipwhite nextgroup=' . l:group_arg_next
1212+
endfor
12161213

1217-
execute 'syntax region' l:group_arg2
1218-
\ 'matchgroup=' . l:group_delims
1219-
\ empty(l:cfg.cchar_close)
1220-
\ ? 'concealends'
1221-
\ : 'concealends cchar=' . l:cfg.cchar_close
1222-
\ 'start="{" skip="\%#=1\\[\\\}]" end="}"'
1223-
\ 'contained contains=' . l:contains
1224-
endif
1214+
execute 'syntax region' l:group_args[-1]
1215+
\ 'matchgroup=' . l:group_delims
1216+
\ empty(l:cfg.cchar_close)
1217+
\ ? 'concealends'
1218+
\ : 'concealends cchar=' . l:cfg.cchar_close
1219+
\ 'start="{" skip="\%#=1\\[\\\}]" end="}"'
1220+
\ 'contained contains=' . l:contains
12251221

12261222
" Define default highlight rule
12271223
execute 'highlight def link' l:group_cmd
@@ -1241,10 +1237,9 @@ function! vimtex#syntax#core#new_cmd_with_concealed_delims(cfg) abort " {{{1
12411237
\}, l:cfg.argstyle,
12421238
\ l:cfg.mathmode ? 'texMathArg' : '')
12431239
if !empty(l:style)
1244-
execute 'highlight def link' l:group_arg1 l:style
1245-
if l:cfg.nargs > 1
1246-
execute 'highlight def link' l:group_arg2 l:style
1247-
endif
1240+
for l:group_arg in l:group_args
1241+
execute 'highlight def link' l:group_arg l:style
1242+
endfor
12481243
endif
12491244
endfunction
12501245

doc/vimtex.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,7 +2727,7 @@ OPTIONS *vimtex-options*
27272727
*g:vimtex_syntax_custom_cmds_with_concealed_delims*
27282728
This option works exactly as |g:vimtex_syntax_custom_cmds|, except it is
27292729
used specifically to add conceals with custom replacement characters for
2730-
single- and double-argument commands, e.g. >
2730+
single- and multi commands, e.g. >
27312731
27322732
\cmd1{argument}
27332733
\cmd2 {argument1} {argument2}
@@ -2741,7 +2741,7 @@ OPTIONS *vimtex-options*
27412741

27422742
nargs ~
27432743
Default: 1
2744-
Specify whether the command has 1 or 2 arguments.
2744+
Specify whether the command has 1 or more arguments.
27452745

27462746
cchar_open ~
27472747
Default: Undefined
@@ -2750,7 +2750,7 @@ OPTIONS *vimtex-options*
27502750

27512751
cchar_mid ~
27522752
Default: Undefined
2753-
Note: Only relevant if `nargs` = 2
2753+
Note: Only relevant if `nargs` > 1
27542754
Specify single letter replacement for the mid (`}{`). If left
27552755
undefined, the mid is fully concealed.
27562756

test/test-syntax/test-conceal.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
\item [tested] This is another item
3232
\end{description}
3333

34-
$\binom{a}{b}$
34+
$\binom{a}{b}$ $\trinom{a}{b}{c}$
3535

3636
$a_1$
3737
$a_+$

test/test-syntax/test-conceal.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ let g:vimtex_syntax_custom_cmds_with_concealed_delims = [
1515
\ 'cchar_open': '(',
1616
\ 'cchar_mid': '|',
1717
\ 'cchar_close': ')'},
18+
\ {'name': 'trinom',
19+
\ 'mathmode': 1,
20+
\ 'nargs': 3,
21+
\ 'cchar_open': '(',
22+
\ 'cchar_mid': '§',
23+
\ 'cchar_close': ')'},
1824
\]
1925

2026
EditConcealed test-conceal.tex

0 commit comments

Comments
 (0)