1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
" VimTeX - LaTeX plugin for Vim
"
" Maintainer: Karl Yngve LervÄg
" Email: karl.yngve@gmail.com
"
function! vimtex#syntax#stack(...) abort " {{{1
let l:pos = a:0 > 0 ? [a:1, a:2] : [line('.'), col('.')]
if mode() ==# 'i'
let l:pos[1] -= 1
endif
call map(l:pos, 'max([v:val, 1])')
return map(synstack(l:pos[0], l:pos[1]), "synIDattr(v:val, 'name')")
endfunction
" }}}1
function! vimtex#syntax#in(name, ...) abort " {{{1
return match(call('vimtex#syntax#stack', a:000), '^' . a:name) >= 0
endfunction
" }}}1
function! vimtex#syntax#in_comment(...) abort " {{{1
return call('vimtex#syntax#in', ['texComment'] + a:000)
endfunction
" }}}1
function! vimtex#syntax#in_mathzone(...) abort " {{{1
let l:groups = reverse(call('vimtex#syntax#stack', a:000))
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
|