File: jobs.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 (83 lines) | stat: -rw-r--r-- 2,334 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
" VimTeX - LaTeX plugin for Vim
"
" Maintainer: Karl Yngve LervÄg
" Email:      karl.yngve@gmail.com
"

" These are wrapper functions for starting processes. They are created to give
" a unified interface that should work reliably on both Vim and neovim on all
" OSes.

function! vimtex#jobs#start(cmd, ...) abort " {{{1
  " Start a background process.
  "
  " The optional argument is a dictionary of options. Each option is parsed in
  " the code below.
  "
  " Return: Job object.
  let l:opts = a:0 > 0 ? a:1 : {}

  let l:job = vimtex#jobs#{s:backend}#new(a:cmd)
  let l:job.cmd_raw = a:cmd
  let l:job.cwd = get(l:opts, 'cwd',
        \ exists('b:vimtex.root') ? b:vimtex.root : '')
  let l:job.wait_timeout = str2nr(get(l:opts, 'wait_timeout', 5000))
  let l:job.capture_output = get(l:opts, 'capture_output', v:false)
  let l:job.detached = get(l:opts, 'detached', v:false)
  call l:job.start()

  " Add some minor delay to ensure the job was properly started
  sleep 100m

  return l:job
endfunction

" }}}1
function! vimtex#jobs#run(cmd, ...) abort " {{{1
  " Run an external process.
  "
  " The optional argument is a dictionary of options. Each option is parsed in
  " the code below.
  "
  " Return: Nothing.
  let l:opts = a:0 > 0 ? a:1 : {}

  call vimtex#paths#pushd(get(l:opts, 'cwd', ''))
  call vimtex#jobs#{s:backend}#run(a:cmd)
  call vimtex#paths#popd()
endfunction

" }}}1
function! vimtex#jobs#capture(cmd, ...) abort " {{{1
  " Run an external process and capture the command output.
  "
  " The optional argument is a dictionary of options. Each option is parsed in
  " the code below.
  "
  " Return: Command output as list of strings.
  let l:opts = a:0 > 0 ? a:1 : {}

  call vimtex#paths#pushd(get(l:opts, 'cwd', ''))
  let l:output = vimtex#jobs#{s:backend}#capture(a:cmd)
  call vimtex#paths#popd()

  " On Windows there may be trailing CR characters
  return vimtex#util#is_win()
        \ ? vimtex#util#win_clean_output(l:output)
        \ : l:output
endfunction

" }}}1
function! vimtex#jobs#cached(cmd) abort " {{{1
  " Cached version of vimtex#jobs#capture(...)
  let l:cache = vimtex#cache#open('capture')

  return l:cache.has(a:cmd)
        \ ? l:cache.get(a:cmd)
        \ : l:cache.set(a:cmd, vimtex#jobs#capture(a:cmd))
endfunction

" }}}1


let s:backend = has('nvim') ? 'neovim' : 'vim'