Skip to content

Commit

Permalink
Attempt at fix for #947
Browse files Browse the repository at this point in the history
  • Loading branch information
lervag committed Sep 26, 2017
1 parent 65dbbcf commit a44998a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
22 changes: 16 additions & 6 deletions autoload/vimtex/view/common.vim
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,24 @@ function! s:xwin_template.xwin_exists() dict " {{{1
" If xwin_id is unset, check if matching viewer windows exist
"
if self.xwin_id == 0
let cmd = 'xdotool search --name ' . fnamemodify(self.out(), ':t')
let result = split(system(cmd), '\n')
if len(result) > 0
let self.xwin_id = result[-1]
endif
let pid = has_key(self, 'get_pid') ? self.get_pid() : 0
let cmd = 'xdotool search'
\ . (pid > 0 ? ' --all --pid ' . pid : '')
\ . ' --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

return (self.xwin_id > 0)
return self.xwin_id > 0
endfunction

" }}}1
Expand Down
10 changes: 10 additions & 0 deletions autoload/vimtex/view/zathura.vim
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function! s:zathura.start(outfile) dict " {{{1
let self.process = vimtex#process#start(l:cmd)

call self.xwin_get_id()
let self.outfile = a:outfile
endfunction

" }}}1
Expand All @@ -58,6 +59,7 @@ function! s:zathura.forward_search(outfile) dict " {{{1
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
Expand Down Expand Up @@ -113,6 +115,14 @@ function! s:zathura.latexmk_append_argument() dict " {{{1
return cmd
endfunction

" }}}1
function! s:zathura.get_pid() dict " {{{1
let cmd = 'pgrep -nf "zathura.*'
\ . escape(get(self, 'outfile', self.out()), '~\%.') . '"'
let pid = str2nr(system(cmd)[:-2])
return pid > 0 ? pid : 0
endfunction

" }}}1

" vim: fdm=marker sw=2

0 comments on commit a44998a

Please sign in to comment.