File: tcolorbox.vim

package info (click to toggle)
vim-vimtex 2.16-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,660 kB
  • sloc: makefile: 367; python: 103
file content (43 lines) | stat: -rw-r--r-- 1,249 bytes parent folder | download
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
" VimTeX - LaTeX plugin for Vim
"
" Maintainer: Karl Yngve LervÄg
" Email:      karl.yngve@gmail.com
"

function! vimtex#syntax#p#tcolorbox#load(cfg) abort " {{{1
  call s:parse_constructs()

  " Match texTCBZone environment "boundaries"
  syntax match texCmdTCBEnv contained '\\begin{\w\+}'
        \ nextgroup=texTCBEnvArg skipwhite
        \ contains=texCmdEnv
  call vimtex#syntax#core#new_arg('texTCBEnvArg', {'contains': ''})

  " Add listing support for detected environments
  for l:env in b:vimtex.syntax.tcolorbox.listing_envs
    call vimtex#syntax#core#new_env({
          \ 'name': l:env,
          \ 'region': 'texTCBZone',
          \ 'contains': 'texCmdEnv,texCmdTCBEnv',
          \})
  endfor

  highlight def link texTCBZone texZone
  highlight def link texTCBEnvArg texArg
endfunction

" }}}1

function! s:parse_constructs() abort " {{{1
  if has_key(b:vimtex.syntax, 'tcolorbox') | return | endif

  let l:re = '\c\\\%(declare\|new\)tcblisting'

  let b:vimtex.syntax.tcolorbox = {}
  let b:vimtex.syntax.tcolorbox.listing_envs = map(filter(
        \   vimtex#parser#tex(b:vimtex.tex, {'detailed': 0}),
        \   { _, x -> x =~? l:re }),
        \ {_, x -> matchstr(x, l:re . '\s*{\zs[a-zA-Z-]\+\ze}')})
endfunction

" }}}1