Skip to content

Commit

Permalink
Merge branch 'lervag:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
shivangp76 authored Apr 20, 2024
2 parents 9d28d47 + 268dd8d commit b88f47d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
26 changes: 21 additions & 5 deletions autoload/vimtex/syntax.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,29 @@ endfunction

" }}}1
function! vimtex#syntax#in_mathzone(...) abort " {{{1
" The following checks if we are inside a texMathZone environment. The
" arguments to \label{...}, the texRefArg group, and \text{...} like
" commands, the texMathTextArg group, are actively ignored as these should
" not be considered to be math environments.
let l:groups = reverse(call('vimtex#syntax#stack', a:000))
let l:group = matchstr(l:groups, '\v^tex%(Math%(Zone|Text|Tag)|RefArg)')
let l:group = matchstr(l:groups, s:__mathzone_regex)
return l:group =~# '^texMathZone'
endfunction

" This specifies matchers that are combined for finding the group used to
" determine if we are in a mathzone. The first entry is `texMathZone`, which
" indicates that we are in a mathzone. The other entries are groups that
" indicate specifically that we are NOT in a mathzone. The entries here are
" part of the core spec. Extensions can register more groups that should be
" ignored with vimtex#syntax#register_mathzone_ignore.
let s:__mathzone_matchers = [
\ 'texMathZone',
\ 'texMathText',
\ 'texMathTag',
\ 'texRefArg',
\]
let s:__mathzone_regex = '^\%(' . join(s:__mathzone_matchers, '\|') . '\)'

" }}}1
function! vimtex#syntax#add_to_mathzone_ignore(regex) abort " {{{1
let s:__mathzone_matchers += [a:regex]
let s:__mathzone_regex = '^\%(' . join(s:__mathzone_matchers, '\|') . '\)'
endfunction

" }}}1
14 changes: 11 additions & 3 deletions doc/vimtex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6248,10 +6248,18 @@ Note: This API is currently a work in progress!
the |VimtexEventCompiling|, |VimtexEventCompileFailed| and
|VimtexEventCompileSuccess| events.

*vimtex#syntax#in*
`vimtex#syntax#in(name)` -> |Boolean|
`vimtex#syntax#in(name, line, column)` -> |Boolean|
Returns |v:true| if the cursor position or the specified position is inside
the `name`d group. `name` is a regex that is used to matched against the
syntax group stack.

*vimtex#syntax#in_mathzone*
Returns 1 if the position is inside a math zone. If called without
arguments, the position refers to the cursor position. Else must be called
with two arguments: the line number and column number.
`vimtex#syntax#in_mathzone()` -> |Boolean|
`vimtex#syntax#in_mathzone(line, column)` -> |Boolean|
Returns |v:true| if the cursor position or the specified position is inside
a math zone.

*vimtex#view#inverse_search*
Utility function for reverse search from pdf viewer. Takes two arguments:
Expand Down
2 changes: 2 additions & 0 deletions test/test-syntax/test-custom.tex
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@
\Ac*{arg}
\iacsp{arg}

$\mather{some text}$

\end{document}
11 changes: 11 additions & 0 deletions test/test-syntax/test-custom.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@ let g:vimtex_syntax_custom_cmds = [
\ {'name': 'mygls', 'argspell': 0},
\ {'name': 'slurp', 'argspell': 0, 'arggreedy': v:true},
\ {'name': 'regex', 'cmdre': '[iI]?[aA]c[slaf]?p?\*?', 'conceal': 1},
\ {'name': 'mather', 'mathmode': 1,
\ 'nextgroup': 'texMatherArg', 'hlgroup': 'texOpt'},
\]

call vimtex#syntax#add_to_mathzone_ignore('texMatherArg')

EditConcealed test-custom.tex

call vimtex#syntax#core#new_arg('texMatherArg', {
\ 'opts': 'contained keepend'
\})

if empty($INMAKE) | finish | endif

call assert_true(vimtex#syntax#in_mathzone(31, 5))
call assert_false(vimtex#syntax#in_mathzone(31, 15))

call vimtex#test#finished()

0 comments on commit b88f47d

Please sign in to comment.