make mupdf work for multiple instances of Vim with same main TeX file name
This commit is contained in:
parent
9dade3c42a
commit
cf152e27ce
@ -78,25 +78,21 @@ endfunction
|
|||||||
"}}}1
|
"}}}1
|
||||||
function! latex#view#mupdf(args) "{{{1
|
function! latex#view#mupdf(args) "{{{1
|
||||||
let outfile = g:latex#data[b:latex.id].out()
|
let outfile = g:latex#data[b:latex.id].out()
|
||||||
if !filereadable(outfile)
|
|
||||||
echomsg "Can't view: Output file is not readable!"
|
if !has_key(g:latex#data[b:latex.id],'mupdf_id')
|
||||||
return
|
let g:latex#data[b:latex.id].mupdf_id = 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Open if not already open
|
let mupdf_id = g:latex#data[b:latex.id].mupdf_id
|
||||||
let pgrep = 'pgrep -nf "^mupdf.*'
|
|
||||||
\ . fnamemodify(g:latex#data[b:latex.id].out(), ':t')
|
if mupdf_id == 0 || !s:exists_mupdf_win(mupdf_id)
|
||||||
\ . '"'
|
call s:start_mupdf(outfile)
|
||||||
if !system(pgrep)[:-2]
|
" Update mupdf_id (=> use g:latex#data... everywhere?!)
|
||||||
let exe = {}
|
let mupfd_id = g:latex#data[b:latex.id].mupdf_id
|
||||||
let exe.cmd = 'mupdf ' . g:latex_view_mupdf_options
|
|
||||||
let exe.cmd .= ' ' . shellescape(outfile)
|
|
||||||
call latex#util#execute(exe)
|
|
||||||
let g:latex#data[b:latex.id].cmds.view = exe.cmd
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Do forward search if possible
|
" Do forward search if possible
|
||||||
if !s:mupdf_forward_search | finish | endif
|
if mupdf_id == 0 || !s:mupdf_forward_search | return | endif
|
||||||
|
|
||||||
let l:cmd = "synctex view -i "
|
let l:cmd = "synctex view -i "
|
||||||
\ . (line(".") + 1) . ":"
|
\ . (line(".") + 1) . ":"
|
||||||
@ -110,7 +106,7 @@ function! latex#view#mupdf(args) "{{{1
|
|||||||
|
|
||||||
if l:page > 0
|
if l:page > 0
|
||||||
let exe = {}
|
let exe = {}
|
||||||
let exe.cmd = 'xdotool search --class mupdf type --window \%1 "'
|
let exe.cmd = 'xdotool type --window ' .mupdf_id. ' "'
|
||||||
\ . l:page . 'g"'
|
\ . l:page . 'g"'
|
||||||
call latex#util#execute(exe)
|
call latex#util#execute(exe)
|
||||||
let g:latex#data[b:latex.id].cmds.view_mupdf_xdotool = exe.cmd
|
let g:latex#data[b:latex.id].cmds.view_mupdf_xdotool = exe.cmd
|
||||||
@ -120,17 +116,20 @@ endfunction
|
|||||||
" }}}1
|
" }}}1
|
||||||
function! latex#view#mupdf_rsearch() "{{{1
|
function! latex#view#mupdf_rsearch() "{{{1
|
||||||
let data = g:latex#data[b:latex.id]
|
let data = g:latex#data[b:latex.id]
|
||||||
|
|
||||||
let data.mupdf_rsearch = {}
|
let data.mupdf_rsearch = {}
|
||||||
let outfile = data.out()
|
let outfile = data.out()
|
||||||
|
|
||||||
" Get window ID
|
if !has_key(data,'mupdf_id') || data.mupdf_id == 0|| !s:exists_mupdf_win(data.mupdf_id)
|
||||||
let cmd = 'xdotool search '
|
echomsg "Can't search backwards: Open PDF from Vim first!"
|
||||||
let cmd .= '--name "' . fnamemodify(outfile, ':t') . '"'
|
return
|
||||||
let mupdf_ids = systemlist(cmd)
|
endif
|
||||||
let data.mupdf_rsearch.ids = mupdf_ids
|
|
||||||
let data.mupdf_rsearch.ids_cmd = cmd
|
let mupdf_id = data.mupdf_id
|
||||||
if len(mupdf_ids) != 1 | return | endif
|
|
||||||
let mupdf_id = mupdf_ids[0]
|
if mupdf_id == 0
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
" Get page number
|
" Get page number
|
||||||
let cmd = "xdotool getwindowname " . mupdf_id
|
let cmd = "xdotool getwindowname " . mupdf_id
|
||||||
@ -214,4 +213,42 @@ endfunction
|
|||||||
|
|
||||||
"}}}1
|
"}}}1
|
||||||
|
|
||||||
|
function! s:exists_mupdf_win(id) "{{{1
|
||||||
|
let cmd = 'xdotool search --class MuPDF'
|
||||||
|
let mupdf_ids = systemlist(cmd)
|
||||||
|
|
||||||
|
for id in mupdf_ids
|
||||||
|
if id == a:id | return 1 | endif
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return 0
|
||||||
|
endfunction
|
||||||
|
"}}}1
|
||||||
|
|
||||||
|
function! s:start_mupdf(outfile) "{{{1
|
||||||
|
let outfile = a:outfile
|
||||||
|
if !filereadable(outfile)
|
||||||
|
echomsg "Can't view: Output file is not readable!"
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
let exe = {}
|
||||||
|
let exe.cmd = 'mupdf ' . g:latex_view_mupdf_options
|
||||||
|
let exe.cmd .= ' ' . shellescape(outfile)
|
||||||
|
call latex#util#execute(exe)
|
||||||
|
let g:latex#data[b:latex.id].cmds.view = exe.cmd
|
||||||
|
|
||||||
|
" Get window ID
|
||||||
|
let cmd = 'xdotool search --class MuPDF'
|
||||||
|
let mupdf_ids = systemlist(cmd)
|
||||||
|
|
||||||
|
if len(mupdf_ids) == 0
|
||||||
|
let g:latex#data[b:latex.id].mupdf_id = 0
|
||||||
|
else
|
||||||
|
let g:latex#data[b:latex.id].mupdf_id = mupdf_ids[-1]
|
||||||
|
endif
|
||||||
|
|
||||||
|
endfunction
|
||||||
|
"}}}1
|
||||||
|
|
||||||
" vim: fdm=marker sw=2
|
" vim: fdm=marker sw=2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user