File: robust_externalize.vim

package info (click to toggle)
vim-vimtex 2.17-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,844 kB
  • sloc: makefile: 360; python: 103
file content (70 lines) | stat: -rw-r--r-- 2,431 bytes parent folder | download | duplicates (2)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
" VimTeX - LaTeX plugin for Vim
"
" Maintainer: Karl Yngve LervÄg
" Email:      karl.yngve@gmail.com
"

function! vimtex#syntax#p#robust_externalize#load(cfg) abort " {{{1
  call vimtex#syntax#packages#load("tikz")

  " Match environment boundaries
  syntax match texRobExtEnvBgn contained '\\begin{\%(RobExt\)\?CacheMeCode\|CacheMe}'
        \ nextgroup=texRobExtEnvOpt,texRobExtEnvArg skipwhite skipnl
        \ contains=texCmdEnv
  call vimtex#syntax#core#new_opt('texRobExtEnvOpt', {'next': 'texRobExtEnvArg'})
  call vimtex#syntax#core#new_arg('texRobExtEnvArg', {'contains': 'texRobExtEnvArg'})

  " Match generic environments
  call vimtex#syntax#core#new_env({
        \ 'name': '\%(RobExt\)\?CacheMeCode\|CacheMe',
        \ 'region': 'texRobExtZone',
        \ 'contains': 'texCmdEnv,texRobExtEnvBgn',
        \})
  call vimtex#syntax#core#new_env({
        \ 'name': 'PlaceholderPathFromCode',
        \ 'region': 'texRobExtZone',
        \ 'contains': 'texCmdEnv,texRobExtEnvBgn',
        \})
  call vimtex#syntax#core#new_env({
        \ 'name': 'SetPlaceholderCode\*\?',
        \ 'region': 'texRobExtZone',
        \ 'contains': 'texCmdEnv,texRobExtEnvBgn',
        \})

  " Add nested syntax support for supported languages
  for [l:preset, l:target] in get(a:cfg, "presets", [])
    if empty(l:target)
      let l:name = 'Verb'
      let l:contains = 'contains=texCmdEnv,texRobExtEnvBgn'
      execute 'highlight def link' l:grp_env 'texRobExtZone'
    elseif l:target ==# "TOP"
      let l:name = 'LaTeX'
      let l:contains = 'contains=TOP,texRobExtZone'
    else
      let l:name = toupper(l:target[0]) . l:target[1:]
      let l:cluster = l:target[0] == "@"
            \ ? l:target
            \ : vimtex#syntax#nested#include(l:target)

      let l:contains = 'contains=texCmdEnv,texRobExtEnvBgn'
      let l:contains .= ',' . l:cluster
    endif

    let l:grp_env = 'texRobExtZone' . l:name

    " Match normal robext environments
    execute 'syntax region' l:grp_env
          \ 'start="\\begin{\z(\%(RobExt\)\?CacheMeCode\|CacheMe\)}\_s*{' . l:preset . '[ ,}]"'
          \ 'end="\\end{\z1}"'
          \ 'keepend'
          \ l:contains
  endfor

  " Specify default highlight groups
  highlight def link texRobExtEnvArg     texSymbol
  highlight def link texRobExtEnvArgOpt  texOpt
  highlight def link texRobExtEnvOpt     texOpt
  highlight def link texRobExtZone       texZone
endfunction

" }}}1