File: packages.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-- 1,807 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#packages#init() abort " {{{1
  if !exists('b:vimtex') || !exists('b:vimtex_syntax') | return | endif

  " Initialize project cache (used e.g. for the minted package)
  if !has_key(b:vimtex, 'syntax')
    let b:vimtex.syntax = {}
  endif

  call s:register_packages()

  let l:loaded = 0
  for [l:pkg, l:cfg] in items(b:vimtex_syntax)
    if !l:cfg.__load || l:cfg.__loaded | continue | endif

    call vimtex#syntax#p#{l:pkg}#load(l:cfg)
    let l:cfg.__loaded = 1
    let l:loaded += 1
  endfor

  if l:loaded > 0
    call vimtex#syntax#core#init_custom()
  endif
endfunction

" }}}1
function! vimtex#syntax#packages#load(pkg) abort " {{{1
  let l:cfg = get(b:vimtex_syntax, a:pkg, {})
  if empty(l:cfg) || l:cfg.__loaded | return | endif

  call vimtex#syntax#p#{a:pkg}#load(l:cfg)
  let l:cfg.__loaded = 1
endfunction

" }}}1

function! s:register_packages() abort " {{{1
  let l:packages = map(
        \ keys(b:vimtex.packages) + [b:vimtex.documentclass],
        \ {_, x -> tolower(substitute(x, '-', '_', 'g'))})

  for l:pkg in s:addons
    if empty(l:pkg) | continue | endif

    " Register "state" for package in current buffer
    if !has_key(b:vimtex_syntax, l:pkg)
      let b:vimtex_syntax[l:pkg] = extend({
            \ 'load': 1,
            \ '__load': 0,
            \ '__loaded': 0,
            \}, get(g:vimtex_syntax_packages, l:pkg, {}))
    endif
    let l:cfg = b:vimtex_syntax[l:pkg]

    let l:cfg.__load =
          \    l:cfg.load > 1
          \ || (l:cfg.load == 1 && index(l:packages, l:pkg) >= 0)
  endfor
endfunction

let s:addons = map(
      \ glob(expand('<sfile>:h') . '/p/*.vim', 0, 1),
      \ { _, x -> fnamemodify(x, ':t:r') })

" }}}1