File: kpsewhich.vim

package info (click to toggle)
vim-vimtex 2.16-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,660 kB
  • sloc: makefile: 367; python: 103
file content (61 lines) | stat: -rw-r--r-- 1,591 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
" VimTeX - LaTeX plugin for Vim
"
" Maintainer: Karl Yngve LervÄg
" Email:      karl.yngve@gmail.com
"

function! vimtex#kpsewhich#find(file) abort " {{{1
  let l:cache = vimtex#cache#open('kpsewhich', {'default': []})

  let l:root = exists('b:vimtex.root') ? b:vimtex.root : getcwd()
  let l:current = l:cache.get(a:file)

  " Check cache for result
  try
    for [l:result, l:result_root] in l:current
      if empty(l:result_root) || l:result_root ==# l:root
        return l:result
      endif
    endfor
  catch
    call vimtex#log#error(
          \ 'Invalid kpsewhich cache!',
          \ 'Please clear with ":VimtexClearCache kpsewhich"'
          \)
    return ''
  endtry

  " Perform search -> [result, result_root]
  let l:result = get(vimtex#kpsewhich#run(fnameescape(a:file)), 0, '')
  if !vimtex#paths#is_abs(l:result)
    let l:result = empty(l:result) ? '' : simplify(l:root . '/' . l:result)
    call add(l:current, [l:result, l:root])
  else
    call add(l:current, [l:result, ''])
  endif

  " Write cache to file
  let l:cache.modified = 1
  call l:cache.write()

  return l:result
endfunction

" }}}1
function! vimtex#kpsewhich#run(args) abort " {{{1
  " kpsewhich should be run at the project root directory
  if exists('b:vimtex.root')
    call vimtex#paths#pushd(b:vimtex.root)
  endif
  let l:output = vimtex#jobs#capture('kpsewhich ' . a:args)
  if exists('b:vimtex.root')
    call vimtex#paths#popd()
  endif

  " Remove warning lines from output
  call filter(l:output, {_, x -> stridx(x, 'kpsewhich: warning: ') == -1})

  return l:output
endfunction

" }}}1