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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
" VimTeX - LaTeX plugin for Vim
"
" Maintainer: Karl Yngve LervÄg
" Email: karl.yngve@gmail.com
"
function! vimtex#view#zathura#new() abort " {{{1
return s:viewer.init()
endfunction
" }}}1
function! vimtex#view#zathura#check(viewer) abort " {{{1
" Check if Zathura is executable
if !executable('zathura')
call vimtex#log#error('Zathura is not executable!')
return v:false
endif
" Check if Zathura has libsynctex
if a:viewer.has_synctex
\ && g:vimtex_view_zathura_check_libsynctex
\ && executable('ldd')
let l:shared = vimtex#jobs#capture('ldd $(which zathura)')
if v:shell_error == 0
\ && empty(filter(l:shared, 'v:val =~# ''libsynctex'''))
call vimtex#log#warning('Zathura is not linked to libsynctex!')
if has_key(a:viewer, 'has_synctex')
let a:viewer.has_synctex = 0
endif
endif
endif
return v:true
endfunction
" }}}1
function! vimtex#view#zathura#cmdline(outfile, synctex, start) abort " {{{1
let l:cmd = 'zathura'
if a:start
let l:cmd .= ' ' . g:vimtex_view_zathura_options
if a:synctex
let l:cmd .= printf(
\ ' -x "%s -c \"VimtexInverseSearch %%{line}:%%{column} ''%%{input}''\""',
\ s:inverse_search_cmd)
endif
endif
if a:synctex && (a:start != 1 || g:vimtex_view_forward_search_on_start)
let l:cmd .= printf(
\ ' --synctex-forward %d:%d:%s',
\ line('.'), col('.'),
\ shellescape(expand('%:p')))
endif
return l:cmd . ' '
\ . vimtex#util#shellescape(vimtex#paths#relative(a:outfile, getcwd()))
\ . '&'
endfunction
let s:inverse_search_cmd = get(g:, 'vimtex_callback_progpath',
\ get(v:, 'progpath', get(v:, 'progname', '')))
\ . (has('nvim')
\ ? ' --headless'
\ : ' -T dumb --not-a-term -n')
" }}}1
let s:viewer = vimtex#view#_template#new({
\ 'name': 'Zathura',
\ 'has_synctex': get(g:, 'vimtex_view_zathura_use_synctex', 1),
\ 'xwin_id': 0,
\})
function! s:viewer._check() dict abort " {{{1
return vimtex#view#zathura#check(self)
endfunction
" }}}1
function! s:viewer._exists() dict abort " {{{1
return self.xdo_exists()
endfunction
" }}}1
function! s:viewer._start(outfile) dict abort " {{{1
let self.cmd_start
\ = vimtex#view#zathura#cmdline(a:outfile, self.has_synctex, 1)
call vimtex#jobs#run(self.cmd_start)
call timer_start(500, { _ -> self.xdo_get_id() })
endfunction
" }}}1
function! s:viewer._forward_search(outfile) dict abort " {{{1
if !self.has_synctex | return | endif
let l:synctex_file = fnamemodify(a:outfile, ':r') . '.synctex.gz'
if !filereadable(l:synctex_file) | return | endif
let self.cmd_forward_search
\ = vimtex#view#zathura#cmdline(a:outfile, self.has_synctex, 0)
call vimtex#jobs#run(self.cmd_forward_search)
endfunction
" }}}1
function! s:viewer.get_pid() dict abort " {{{1
" First try to match full output file name
let l:pdf = escape(fnamemodify(self.out(), ':t'), '~\%.')
let l:output = vimtex#jobs#capture(
\ 'pgrep -nf "^zathura.*' . l:pdf . '"')
let l:pid = str2nr(join(l:output, ''))
if !empty(l:pid) | return l:pid | endif
" Now try to match correct servername as fallback
let l:output = vimtex#jobs#capture(
\ 'pgrep -nf "^zathura.+--servername ' . v:servername . '"')
return str2nr(join(l:output, ''))
endfunction
" }}}1
|