diff options
Diffstat (limited to 'autoload/vimtex/view')
| -rw-r--r-- | autoload/vimtex/view/common.vim | 211 | ||||
| -rw-r--r-- | autoload/vimtex/view/general.vim | 111 | ||||
| -rw-r--r-- | autoload/vimtex/view/mupdf.vim | 186 | ||||
| -rw-r--r-- | autoload/vimtex/view/skim.vim | 114 | ||||
| -rw-r--r-- | autoload/vimtex/view/zathura.vim | 155 | 
5 files changed, 777 insertions, 0 deletions
diff --git a/autoload/vimtex/view/common.vim b/autoload/vimtex/view/common.vim new file mode 100644 index 00000000..ca39cf0a --- /dev/null +++ b/autoload/vimtex/view/common.vim @@ -0,0 +1,211 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1 + +" vimtex - LaTeX plugin for Vim +" +" Maintainer: Karl Yngve Lervåg +" Email:      karl.yngve@gmail.com +" + +function! vimtex#view#common#apply_common_template(viewer) abort " {{{1 +  return extend(a:viewer, deepcopy(s:common_template)) +endfunction + +" }}}1 +function! vimtex#view#common#apply_xwin_template(class, viewer) abort " {{{1 +  let a:viewer.class = a:class +  let a:viewer.xwin_id = 0 +  call extend(a:viewer, deepcopy(s:xwin_template)) +  return a:viewer +endfunction + +" }}}1 +function! vimtex#view#common#not_readable(output) abort " {{{1 +  if !filereadable(a:output) +    call vimtex#log#warning('Viewer cannot read PDF file!', a:output) +    return 1 +  else +    return 0 +  endif +endfunction + +" }}}1 + +let s:common_template = {} + +function! s:common_template.out() dict abort " {{{1 +  return g:vimtex_view_use_temp_files +        \ ? b:vimtex.root . '/' . b:vimtex.name . '_vimtex.pdf' +        \ : b:vimtex.out(1) +endfunction + +" }}}1 +function! s:common_template.synctex() dict abort " {{{1 +  return fnamemodify(self.out(), ':r') . '.synctex.gz' +endfunction + +" }}}1 +function! s:common_template.copy_files() dict abort " {{{1 +  if !g:vimtex_view_use_temp_files | return | endif + +  " +  " Copy pdf file +  " +  let l:out = self.out() +  if getftime(b:vimtex.out()) > getftime(l:out) +    call writefile(readfile(b:vimtex.out(), 'b'), l:out, 'b') +  endif + +  " +  " Copy synctex file +  " +  let l:old = b:vimtex.ext('synctex.gz') +  let l:new = self.synctex() +  if getftime(l:old) > getftime(l:new) +    call rename(l:old, l:new) +  endif +endfunction + +" }}}1 +function! s:common_template.pprint_items() abort dict " {{{1 +  let l:list = [] + +  if has_key(self, 'xwin_id') +    call add(l:list, ['xwin id', self.xwin_id]) +  endif + +  if has_key(self, 'process') +    call add(l:list, ['process', self.process]) +  endif + +  for l:key in filter(keys(self), 'v:val =~# ''^cmd_''') +    call add(l:list, [l:key, self[l:key]]) +  endfor + +  return l:list +endfunction + +" }}}1 + +let s:xwin_template = {} + +function! s:xwin_template.view(file) dict abort " {{{1 +  if empty(a:file) +    let outfile = self.out() +  else +    let outfile = a:file +  endif +  if vimtex#view#common#not_readable(outfile) +    return +  endif + +  if self.xwin_exists() +    call self.forward_search(outfile) +  else +    if g:vimtex_view_use_temp_files +      call self.copy_files() +    endif +    call self.start(outfile) +  endif + +  if has_key(self, 'hook_view') +    call self.hook_view() +  endif +endfunction + +" }}}1 +function! s:xwin_template.xwin_get_id() dict abort " {{{1 +  if !executable('xdotool') | return 0 | endif +  if self.xwin_id > 0 | return self.xwin_id | endif + +  " Allow some time for the viewer to start properly +  sleep 500m + +  " +  " Get the window ID +  " +  let cmd = 'xdotool search --class ' . self.class +  let xwin_ids = split(system(cmd), '\n') +  if len(xwin_ids) == 0 +    call vimtex#log#warning('Viewer cannot find ' . self.class . ' window ID!') +    let self.xwin_id = 0 +  else +    let self.xwin_id = xwin_ids[-1] +  endif + +  return self.xwin_id +endfunction + +" }}}1 +function! s:xwin_template.xwin_exists() dict abort " {{{1 +  if !executable('xdotool') | return 0 | endif + +  " +  " If xwin_id is already set, check if it still exists +  " +  if self.xwin_id > 0 +    let cmd = 'xdotool search --class ' . self.class +    if index(split(system(cmd), '\n'), self.xwin_id) < 0 +      let self.xwin_id = 0 +    endif +  endif + +  " +  " If xwin_id is unset, check if matching viewer windows exist +  " +  if self.xwin_id == 0 +    if has_key(self, 'get_pid') +      let cmd = 'xdotool search' +            \ . ' --all --pid ' . self.get_pid() +            \ . ' --name ' . fnamemodify(self.out(), ':t') +      let self.xwin_id = get(split(system(cmd), '\n'), 0) +    else +      let cmd = 'xdotool search --name ' . fnamemodify(self.out(), ':t') +      let ids = split(system(cmd), '\n') +      let ids_already_used = filter(map(deepcopy(vimtex#state#list_all()), +            \ "get(get(v:val, 'viewer', {}), 'xwin_id')"), 'v:val > 0') +      for id in ids +        if index(ids_already_used, id) < 0 +          let self.xwin_id = id +          break +        endif +      endfor +    endif +  endif + +  return self.xwin_id > 0 +endfunction + +" }}}1 +function! s:xwin_template.xwin_send_keys(keys) dict abort " {{{1 +  if a:keys ==# '' || !executable('xdotool') || self.xwin_id <= 0 +    return +  endif + +  let cmd  = 'xdotool key --window ' . self.xwin_id +  let cmd .= ' ' . a:keys +  silent call system(cmd) +endfunction + +" }}}1 +function! s:xwin_template.move(arg) abort " {{{1 +  if !executable('xdotool') || self.xwin_id <= 0 +    return +  endif + +  let l:cmd = 'xdotool windowmove ' . self.xwin_get_id() . ' ' . a:arg +  silent call system(l:cmd) +endfunction + +" }}}1 +function! s:xwin_template.resize(arg) abort " {{{1 +  if !executable('xdotool') || self.xwin_id <= 0 +    return +  endif + +  let l:cmd = 'xdotool windowsize ' . self.xwin_get_id()  . ' ' . a:arg +  silent call system(l:cmd) +endfunction + +" }}}1 + +endif diff --git a/autoload/vimtex/view/general.vim b/autoload/vimtex/view/general.vim new file mode 100644 index 00000000..701fe33c --- /dev/null +++ b/autoload/vimtex/view/general.vim @@ -0,0 +1,111 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1 + +" vimtex - LaTeX plugin for Vim +" +" Maintainer: Karl Yngve Lervåg +" Email:      karl.yngve@gmail.com +" + +function! vimtex#view#general#new() 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) +    call vimtex#log#warning( +          \ 'Selected viewer is not executable!', +          \ '- Selection: ' . g:vimtex_view_general_viewer . +          \ '- Executable: ' . l:exe . +          \ '- Please see :h g:vimtex_view_general_viewer') +    return {} +  endif + +  " Start from standard template +  let l:viewer = vimtex#view#common#apply_common_template(deepcopy(s:general)) + +  " Add callback hook +  if exists('g:vimtex_view_general_callback') +    let l:viewer.compiler_callback = function(g:vimtex_view_general_callback) +  endif + +  return l:viewer +endfunction + +" }}}1 + +let s:general = { +      \ 'name' : 'General' +      \} + +function! s:general.view(file) dict abort " {{{1 +  if empty(a:file) +    let outfile = self.out() + +    " Only copy files if they don't exist +    if g:vimtex_view_use_temp_files +          \ && vimtex#view#common#not_readable(outfile) +      call self.copy_files() +    endif +  else +    let outfile = a:file +  endif + +  " Update the path for Windows on cygwin +  if executable('cygpath') +    let outfile = join( +          \ vimtex#process#capture('cygpath -aw "' . outfile . '"'), '') +  endif + +  if vimtex#view#common#not_readable(outfile) | return | endif + +  " 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', +        \ vimtex#util#shellescape(expand('%:p')), 'g') +  let l:cmd = substitute(l:cmd, '@pdf', vimtex#util#shellescape(outfile), 'g') + +  " Start the view process +  let self.process = vimtex#process#start(l:cmd, {'silent': 0}) + +  if has_key(self, 'hook_view') +    call self.hook_view() +  endif +endfunction + +" }}}1 +function! s:general.latexmk_append_argument() dict abort " {{{1 +  if g:vimtex_view_use_temp_files +    return ' -view=none' +  else +    let l:option = g:vimtex_view_general_viewer +    if !empty(g:vimtex_view_general_options_latexmk) +      let l:option .= ' ' +      let l:option .= substitute(g:vimtex_view_general_options_latexmk, +            \                    '@line', line('.'), 'g') +    endif +    return vimtex#compiler#latexmk#wrap_option('pdf_previewer', l:option) +  endif +endfunction + +" }}}1 +function! s:general.compiler_callback(status) dict abort " {{{1 +  if !a:status && g:vimtex_view_use_temp_files < 2 +    return +  endif + +  if g:vimtex_view_use_temp_files +    call self.copy_files() +  endif + +  if has_key(self, 'hook_callback') +    call self.hook_callback() +  endif +endfunction + +" }}}1 + +endif diff --git a/autoload/vimtex/view/mupdf.vim b/autoload/vimtex/view/mupdf.vim new file mode 100644 index 00000000..95d3710c --- /dev/null +++ b/autoload/vimtex/view/mupdf.vim @@ -0,0 +1,186 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1 + +" vimtex - LaTeX plugin for Vim +" +" Maintainer: Karl Yngve Lervåg +" Email:      karl.yngve@gmail.com +" + +function! vimtex#view#mupdf#new() abort " {{{1 +  " Check if the viewer is executable +  if !executable('mupdf') +    call vimtex#log#error( +          \ 'MuPDF is not executable!', +          \ '- vimtex viewer will not work!') +    return {} +  endif + +  " Use the xwin template +  return vimtex#view#common#apply_xwin_template('MuPDF', +        \ vimtex#view#common#apply_common_template(deepcopy(s:mupdf))) +endfunction + +" }}}1 + +let s:mupdf = { +      \ 'name': 'MuPDF', +      \} + +function! s:mupdf.start(outfile) dict abort " {{{1 +  let l:cmd = 'mupdf ' .  g:vimtex_view_mupdf_options +        \ . ' ' . vimtex#util#shellescape(a:outfile) +  let self.process = vimtex#process#start(l:cmd) + +  call self.xwin_get_id() +  call self.xwin_send_keys(g:vimtex_view_mupdf_send_keys) + +  if g:vimtex_view_forward_search_on_start +    call self.forward_search(a:outfile) +  endif +endfunction + +" }}}1 +function! s:mupdf.forward_search(outfile) dict abort " {{{1 +  if !executable('xdotool') | return | endif +  if !executable('synctex') | return | endif + +  let self.cmd_synctex_view = 'synctex view -i ' +        \ . (line('.') + 1) . ':' +        \ . (col('.') + 1) . ':' +        \ . vimtex#util#shellescape(expand('%:p')) +        \ . ' -o ' . vimtex#util#shellescape(a:outfile) +        \ . " | grep -m1 'Page:' | sed 's/Page://' | tr -d '\n'" +  let self.page = system(self.cmd_synctex_view) + +  if self.page > 0 +    let l:cmd = 'xdotool' +          \ . ' type --window ' . self.xwin_id +          \ . ' "' . self.page . 'g"' +    call vimtex#process#run(l:cmd) +    let self.cmd_forward_search = l:cmd +  endif + +  call self.focus_viewer() +endfunction + +" }}}1 +function! s:mupdf.reverse_search() dict abort " {{{1 +  if !executable('xdotool') | return | endif +  if !executable('synctex') | return | endif + +  let outfile = self.out() +  if vimtex#view#common#not_readable(outfile) | return | endif + +  if !self.xwin_exists() +    call vimtex#log#warning('Reverse search failed (is MuPDF open?)') +    return +  endif + +  " Get page number +  let self.cmd_getpage  = 'xdotool getwindowname ' . self.xwin_id +  let self.cmd_getpage .= " | sed 's:.* - \\([0-9]*\\)/.*:\\1:'" +  let self.cmd_getpage .= " | tr -d '\n'" +  let self.page = system(self.cmd_getpage) +  if self.page <= 0 | return | endif + +  " Get file +  let self.cmd_getfile  = 'synctex edit ' +  let self.cmd_getfile .= "-o \"" . self.page . ':288:108:' . outfile . "\"" +  let self.cmd_getfile .= "| grep 'Input:' | sed 's/Input://' " +  let self.cmd_getfile .= "| head -n1 | tr -d '\n' 2>/dev/null" +  let self.file = system(self.cmd_getfile) + +  " Get line +  let self.cmd_getline  = 'synctex edit ' +  let self.cmd_getline .= "-o \"" . self.page . ':288:108:' . outfile . "\"" +  let self.cmd_getline .= "| grep -m1 'Line:' | sed 's/Line://' " +  let self.cmd_getline .= "| head -n1 | tr -d '\n'" +  let self.line = system(self.cmd_getline) + +  " Go to file and line +  silent exec 'edit ' . fnameescape(self.file) +  if self.line > 0 +    silent exec ':' . self.line +    " Unfold, move to top line to correspond to top pdf line, and go to end of +    " line in case the corresponding pdf line begins on previous pdf page. +    normal! zvztg_ +  endif +endfunction + +" }}}1 +function! s:mupdf.compiler_callback(status) dict abort " {{{1 +  if !a:status && g:vimtex_view_use_temp_files < 2 +    return +  endif + +  if g:vimtex_view_use_temp_files +    call self.copy_files() +  endif + +  if !filereadable(self.out()) | return | endif + +  if g:vimtex_view_automatic +    " +    " Search for existing window created by latexmk +    "   It may be necessary to wait some time before it is opened and +    "   recognized. Sometimes it is very quick, other times it may take +    "   a second. This way, we don't block longer than necessary. +    " +    if !has_key(self, 'started_through_callback') +      for l:dummy in range(30) +        sleep 50m +        if self.xwin_exists() | break | endif +      endfor +    endif + +    if !self.xwin_exists() && !has_key(self, 'started_through_callback') +      call self.start(self.out()) +      let self.started_through_callback = 1 +    endif +  endif + +  if g:vimtex_view_use_temp_files || get(b:vimtex.compiler, 'callback') +    call self.xwin_send_keys('r') +  endif + +  if has_key(self, 'hook_callback') +    call self.hook_callback() +  endif +endfunction + +" }}}1 +function! s:mupdf.latexmk_append_argument() dict abort " {{{1 +  if g:vimtex_view_use_temp_files +    let cmd = ' -view=none' +  else +    let cmd  = vimtex#compiler#latexmk#wrap_option('new_viewer_always', '0') +    let cmd .= vimtex#compiler#latexmk#wrap_option('pdf_update_method', '2') +    let cmd .= vimtex#compiler#latexmk#wrap_option('pdf_update_signal', 'SIGHUP') +    let cmd .= vimtex#compiler#latexmk#wrap_option('pdf_previewer', +          \ 'mupdf ' .  g:vimtex_view_mupdf_options) +  endif + +  return cmd +endfunction + +" }}}1 +function! s:mupdf.focus_viewer() dict abort " {{{1 +  if !executable('xdotool') | return | endif + +  if self.xwin_id > 0 +    silent call system('xdotool windowactivate ' . self.xwin_id . ' --sync') +    silent call system('xdotool windowraise ' . self.xwin_id) +  endif +endfunction + +" }}}1 +function! s:mupdf.focus_vim() dict abort " {{{1 +  if !executable('xdotool') | return | endif + +  silent call system('xdotool windowactivate ' . v:windowid . ' --sync') +  silent call system('xdotool windowraise ' . v:windowid) +endfunction + +" }}}1 + +endif diff --git a/autoload/vimtex/view/skim.vim b/autoload/vimtex/view/skim.vim new file mode 100644 index 00000000..c3dc6dec --- /dev/null +++ b/autoload/vimtex/view/skim.vim @@ -0,0 +1,114 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1 + +" vimtex - LaTeX plugin for Vim +" +" Maintainer: Karl Yngve Lervåg +" Email:      karl.yngve@gmail.com +" + +function! vimtex#view#skim#new() abort " {{{1 +  " Check if Skim is installed +  let l:cmd = join([ +        \ 'osascript -e ', +        \ '''tell application "Finder" to POSIX path of ', +        \ '(get application file id (id of application "Skim") as alias)''', +        \]) + +  if system(l:cmd) +    call vimtex#log#error('Skim is not installed!') +    return {} +  endif + +  return vimtex#view#common#apply_common_template(deepcopy(s:skim)) +endfunction + +" }}}1 + +let s:skim = { +      \ 'name' : 'Skim', +      \ 'startskim' : 'open -a Skim', +      \} + +function! s:skim.view(file) dict abort " {{{1 +  if empty(a:file) +    let outfile = self.out() + +    " Only copy files if they don't exist +    if g:vimtex_view_use_temp_files +          \ && vimtex#view#common#not_readable(outfile) +      call self.copy_files() +    endif +  else +    let outfile = a:file +  endif +  if vimtex#view#common#not_readable(outfile) | return | endif + +  let l:cmd = join([ +        \ 'osascript', +        \ '-e ''set theLine to ' . line('.') . ' as integer''', +        \ '-e ''set theFile to POSIX file "' . outfile . '"''', +        \ '-e ''set thePath to POSIX path of (theFile as alias)''', +        \ '-e ''set theSource to POSIX file "' . expand('%:p') . '"''', +        \ '-e ''tell application "Skim"''', +        \ '-e ''try''', +        \ '-e ''set theDocs to get documents whose path is thePath''', +        \ '-e ''if (count of theDocs) > 0 then revert theDocs''', +        \ '-e ''end try''', +        \ '-e ''open theFile''', +        \ '-e ''tell front document to go to TeX line theLine from theSource', +        \ g:vimtex_view_skim_reading_bar ? 'showing reading bar true''' : '''', +        \ g:vimtex_view_skim_activate ? '-e ''activate''' : '', +        \ '-e ''end tell''', +        \]) + +  let self.process = vimtex#process#start(l:cmd) + +  if has_key(self, 'hook_view') +    call self.hook_view() +  endif +endfunction + +" }}}1 +function! s:skim.compiler_callback(status) dict abort " {{{1 +  if !a:status && g:vimtex_view_use_temp_files < 2 +    return +  endif + +  if g:vimtex_view_use_temp_files +    call self.copy_files() +  endif + +  if !filereadable(self.out()) | return | endif + +  let l:cmd = join([ +        \ 'osascript', +        \ '-e ''set theFile to POSIX file "' . self.out() . '"''', +        \ '-e ''set thePath to POSIX path of (theFile as alias)''', +        \ '-e ''tell application "Skim"''', +        \ '-e ''try''', +        \ '-e ''set theDocs to get documents whose path is thePath''', +        \ '-e ''if (count of theDocs) > 0 then revert theDocs''', +        \ '-e ''end try''', +        \ '-e ''open theFile''', +        \ '-e ''end tell''', +        \]) + +  let self.process = vimtex#process#start(l:cmd) + +  if has_key(self, 'hook_callback') +    call self.hook_callback() +  endif +endfunction + +" }}}1 +function! s:skim.latexmk_append_argument() dict abort " {{{1 +  if g:vimtex_view_use_temp_files || g:vimtex_view_automatic +    return ' -view=none' +  else +    return vimtex#compiler#latexmk#wrap_option('pdf_previewer', self.startskim) +  endif +endfunction + +" }}}1 + +endif diff --git a/autoload/vimtex/view/zathura.vim b/autoload/vimtex/view/zathura.vim new file mode 100644 index 00000000..48e8e27a --- /dev/null +++ b/autoload/vimtex/view/zathura.vim @@ -0,0 +1,155 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1 + +" vimtex - LaTeX plugin for Vim +" +" Maintainer: Karl Yngve Lervåg +" Email:      karl.yngve@gmail.com +" + +function! vimtex#view#zathura#new() abort " {{{1 +  " Check if the viewer is executable +  if !executable('zathura') +    call vimtex#log#error('Zathura is not executable!') +    return {} +  endif + +  if executable('ldd') +    let l:shared = split(system('ldd =zathura')) +    if v:shell_error == 0 +          \ && empty(filter(l:shared, 'v:val =~# ''libsynctex''')) +      call vimtex#log#warning('Zathura is not linked to libsynctex!') +      let s:zathura.has_synctex = 0 +    endif +  endif + +  " Check if the xdotool is available +  if !executable('xdotool') +    call vimtex#log#warning('Zathura requires xdotool for forward search!') +  endif + +  " +  " Use the xwin template +  " +  return vimtex#view#common#apply_xwin_template('Zathura', +        \ vimtex#view#common#apply_common_template(deepcopy(s:zathura))) +endfunction + +" }}}1 + +let s:zathura = { +      \ 'name' : 'Zathura', +      \ 'has_synctex' : 1, +      \} + +function! s:zathura.start(outfile) dict abort " {{{1 +  let l:cmd  = 'zathura' +  if self.has_synctex +    let l:cmd .= ' -x "' . g:vimtex_compiler_progname +          \ . ' --servername ' . v:servername +          \ . ' --remote-expr ' +          \ .     '\"vimtex#view#reverse_goto(%{line}, ''%{input}'')\""' +    if g:vimtex_view_forward_search_on_start +      let l:cmd .= ' --synctex-forward ' +            \ .  line('.') +            \ .  ':' . col('.') +            \ .  ':' . vimtex#util#shellescape(expand('%:p')) +    endif +  endif +  let l:cmd .= ' ' . g:vimtex_view_zathura_options +  let l:cmd .= ' ' . vimtex#util#shellescape(a:outfile) +  let self.process = vimtex#process#start(l:cmd) + +  call self.xwin_get_id() +  let self.outfile = a:outfile +endfunction + +" }}}1 +function! s:zathura.forward_search(outfile) dict abort " {{{1 +  if !self.has_synctex | return | endif +  if !filereadable(self.synctex()) | return | endif + +  let l:cmd  = 'zathura --synctex-forward ' +  let l:cmd .= line('.') +  let l:cmd .= ':' . col('.') +  let l:cmd .= ':' . vimtex#util#shellescape(expand('%:p')) +  let l:cmd .= ' ' . vimtex#util#shellescape(a:outfile) +  call vimtex#process#run(l:cmd) +  let self.cmd_forward_search = l:cmd +  let self.outfile = a:outfile +endfunction + +" }}}1 +function! s:zathura.compiler_callback(status) dict abort " {{{1 +  if !a:status && g:vimtex_view_use_temp_files < 2 +    return +  endif + +  if g:vimtex_view_use_temp_files +    call self.copy_files() +  endif + +  if !filereadable(self.out()) | return | endif + +  if g:vimtex_view_automatic +    " +    " Search for existing window created by latexmk +    "   It may be necessary to wait some time before it is opened and +    "   recognized. Sometimes it is very quick, other times it may take +    "   a second. This way, we don't block longer than necessary. +    " +    if !has_key(self, 'started_through_callback') +      for l:dummy in range(30) +        sleep 50m +        if self.xwin_exists() | break | endif +      endfor +    endif + +    if !self.xwin_exists() && !has_key(self, 'started_through_callback') +      call self.start(self.out()) +      let self.started_through_callback = 1 +    endif +  endif + +  if has_key(self, 'hook_callback') +    call self.hook_callback() +  endif +endfunction + +" }}}1 +function! s:zathura.latexmk_append_argument() dict abort " {{{1 +  if g:vimtex_view_use_temp_files +    let cmd = ' -view=none' +  else +    let zathura = 'zathura ' . g:vimtex_view_zathura_options +    if self.has_synctex +      let zathura .= ' -x \"' . g:vimtex_compiler_progname +          \ . ' --servername ' . v:servername +          \ . ' --remote +\%{line} \%{input}\" \%S' +    endif + +    let cmd  = vimtex#compiler#latexmk#wrap_option('new_viewer_always', '0') +    let cmd .= vimtex#compiler#latexmk#wrap_option('pdf_previewer', zathura) +  endif + +  return cmd +endfunction + +" }}}1 +function! s:zathura.get_pid() dict abort " {{{1 +  " First try to match full output file name +  let cmd = 'pgrep -nf "zathura.*' +        \ . escape(get(self, 'outfile', self.out()), '~\%.') . '"' +  let pid = str2nr(system(cmd)[:-2]) + +  " Now try to match correct servername as fallback +  if empty(pid) +    let cmd = 'pgrep -nf "zathura.+--servername ' . v:servername . '"' +    let pid = str2nr(system(cmd)[:-2]) +  endif + +  return pid +endfunction + +" }}}1 + +endif  | 
