File: general.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 (67 lines) | stat: -rw-r--r-- 2,014 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
" VimTeX - LaTeX plugin for Vim
"
" Maintainer: Karl Yngve LervÄg
" Email:      karl.yngve@gmail.com
"

function! vimtex#view#general#new() abort " {{{1
  return s:viewer.init()
endfunction

" }}}1


let s:viewer = vimtex#view#_template#new({
      \ 'name' : 'General'
      \})

function! s:viewer._check() abort " {{{1
  " Check if the viewer is executable
  " * split to ensure that we handle stuff like "gio open"
  let l:exe = get(split(g:vimtex_view_general_viewer), 0, '')
  if empty(l:exe)
        \ || (!executable(l:exe)
        \     && !(vimtex#util#get_os() ==# 'win'
        \          && g:vimtex_view_general_viewer ==# 'start ""'))
    call vimtex#log#warning(
          \ 'Generic viewer is not executable!',
          \ '- Viewer: ' . g:vimtex_view_general_viewer,
          \ '- Executable: ' . l:exe,
          \ '- Please see :h g:vimtex_view_general_viewer')
    return v:false
  endif

  return v:true
endfunction

" }}}1
function! s:viewer._start(file) dict abort " {{{1
  " Update file path for Windows+cygwin
  let l:path_pdf = executable('cygpath')
        \ ? join(vimtex#jobs#capture('cygpath -aw "' . a:file . '"'), '')
        \ : a:file

  " Escapes for shell command and the substitute
  let l:path_tex = vimtex#util#shellescape(expand('%:p'))
  let l:path_tex = escape(l:path_tex, '&')
  let l:path_pdf = vimtex#util#shellescape(l:path_pdf)
  let l:path_pdf = escape(l:path_pdf, '&')

  " Parse options
  let l:cmd = g:vimtex_view_general_viewer
  let l:cmd .= ' ' . g:vimtex_view_general_options

  " Substitute magic patterns
  let l:cmd = substitute(l:cmd, '@line', line('.'), 'g')
  let l:cmd = substitute(l:cmd, '@col', col('.'), 'g')
  let l:cmd = substitute(l:cmd, '@tex', l:path_tex, 'g')
  let l:cmd = substitute(l:cmd, '@pdf', l:path_pdf, 'g')

  " Start the view process
  " NB: Use vimtex#jobs#start to ensure it runs in the background
  let self.job = vimtex#jobs#start(l:cmd, {
        \ 'detached': vimtex#util#get_os() !=# 'win'
        \})
endfunction

" }}}1