Improved docs, improved MuPDF support

This commit is contained in:
Karl Yngve Lervåg 2015-01-29 21:12:43 +01:00
parent 270f2a80ba
commit 7f117363d8
3 changed files with 81 additions and 40 deletions

View File

@ -88,6 +88,14 @@ function! latex#latexmk#callback(status) " {{{1
echo "latexmk compile: fail"
endif
echohl None
" Get window ID after first callback
if s:first_callback
let s:first_callback = 0
if g:latex_view_method == 'mupdf'
call latex#view#mupdf_poststart()
endif
endif
endfunction
" }}}1
@ -141,41 +149,19 @@ endfunction
" }}}1
function! latex#latexmk#compile() " {{{1
let data = g:latex#data[b:latex.id]
if data.pid
echomsg "latexmk is already running for `" . data.base . "'"
return
endif
call s:latexmk_set_cmd(data)
" Start latexmk
let exe = {}
let exe.null = 0
if !g:latex_latexmk_continuous && !g:latex_latexmk_background
let exe.bg = 0
let exe.silent = 0
endif
let exe.cmd = data.cmds.compile
" Build command line and start latexmk
let exe = s:latexmk_build_cmd(data)
call latex#util#execute(exe)
if g:latex_latexmk_continuous
call s:latexmk_set_pid(data)
echomsg 'latexmk started in continuous mode ...'
" Get window ID
if g:latex_view_method == 'mupdf'
" give time to read window ID
sleep
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
endif
else
echomsg 'latexmk compiling ...'
endif
@ -336,7 +322,10 @@ endfunction
" }}}1
" Helper functions for latexmk command
function! s:latexmk_set_cmd(data) " {{{1
function! s:latexmk_build_cmd(data) " {{{1
let exe = {}
let exe.null = 0
" Note: We don't send output to /dev/null, but rather to a temporary file,
" which allows inspection of latexmk output
let tmp = tempname()
@ -371,6 +360,7 @@ function! s:latexmk_set_cmd(data) " {{{1
let cmd .= ' -e ''$success_cmd .= "' . success . '"'''
let cmd .= ' -e ''$failure_cmd .= "' . failed . '"'''
endif
let s:first_callback = 1
endif
let cmd .= ' ' . shellescape(a:data.base)
@ -384,8 +374,16 @@ function! s:latexmk_set_cmd(data) " {{{1
endif
endif
let exe.cmd = cmd
let a:data.cmds.compile = cmd
let a:data.tmp = tmp
if !g:latex_latexmk_continuous && !g:latex_latexmk_background
let exe.bg = 0
let exe.silent = 0
endif
return exe
endfunction
" }}}1

View File

@ -19,6 +19,7 @@ function! latex#view#init(initialized) " {{{1
\ })
call latex#util#set_default('g:latex_view_method', '')
call latex#util#set_default('g:latex_view_mupdf_options', '')
call latex#util#set_default('g:latex_view_mupdf_send_keys', '')
call latex#util#set_default('g:latex_view_okular_options', '')
call latex#util#set_default('g:latex_view_sumatrapdf_options', '')
call latex#util#error_deprecated('g:latex_viewer')
@ -94,6 +95,33 @@ function! latex#view#mupdf() "{{{1
endfunction
" }}}1
function! latex#view#mupdf_poststart() "{{{1
" First get the window id
let mupdf_ids = []
if executable('xdotool')
let cmd = 'xdotool search --class MuPDF'
let mupdf_ids = systemlist(cmd)
endif
if len(mupdf_ids) == 0
echomsg "Couldn't find MuPDF window ID!"
let g:latex#data[b:latex.id].mupdf_id = 0
else
let g:latex#data[b:latex.id].mupdf_id = mupdf_ids[-1]
endif
" Next return focus to vim and send some keys to mupdf if desired
if executable('xdotool')
if g:latex_view_mupdf_send_keys != ''
let cmd = 'xdotool key --window ' . g:latex#data[b:latex.id].mupdf_id
let cmd .= ' ' . g:latex_view_mupdf_send_keys
call system(cmd)
endif
silent execute '!xdotool windowfocus ' . v:windowid
endif
endfunction
"}}}1
function! latex#view#mupdf_rsearch() "{{{1
if !s:mupdf_exists_win()
echomsg "Can't search backwards: Is the PDF file open?"
@ -268,17 +296,7 @@ function! s:mupdf_start() "{{{1
call latex#util#execute(exe)
let g:latex#data[b:latex.id].cmds.view = exe.cmd
" Get window ID
if executable('xdotool')
let cmd = 'xdotool search --class MuPDF'
let mupdf_ids = systemlist(cmd)
if len(mupdf_ids) == 0
echomsg "Couldn't find MuPDF window ID!"
let g:latex#data[b:latex.id].mupdf_id = 0
else
let g:latex#data[b:latex.id].mupdf_id = mupdf_ids[-1]
endif
endif
call latex#view#mupdf_poststart()
endfunction
"}}}1

View File

@ -566,6 +566,11 @@ Set custom options for the given viewer. >
let g:latex_view_mupdf_options = ''
let g:latex_view_okular_options = ''
let g:latex_view_sumatrapdf_options = ''
<
*g:latex_view_mupdf_send_keys*
String of keys sent to MuPDF after the PDF file has been opened. The keys are
sent by the function |latex#view#mupdf_poststart|. >
let g:latex_view_mupdf_send_keys = ''
<
==============================================================================
OMNI COMPLETION *vim-latex-completion*
@ -1016,7 +1021,12 @@ Overview:~
|latex#util#kpsewhich|
|latex#util#tex2tree|
|latex#util#tree2tex|
|latex#view#view|
|latex#view#general|
|latex#view#mupdf|
|latex#view#mupdf_poststart|
|latex#view#mupdf_rsearch|
|latex#view#okular|
|latex#view#sumatrapdf|
------------------------------------------------------------------------------
Detailed descriptions:~
@ -1184,8 +1194,23 @@ Turn tex structure to a tree composed of lists. E.g. >
Turns a tree composed of lists into tex structure. E.g. >
[ "testing" , [ "tex2tree", []]] => { testing { tex2tree { } } }
<
*latex#view#view*
Open the output file with the default viewer |g:latex_view_method|.
*latex#view#general*
Open the output file with the viewer that is specified with the option
|g:latex_view_general_viewer|.
*latex#view#mupdf*
*latex#view#okular*
*latex#view#sumatrapdf*
First open the output file if it is not open with MuPDF/Okular/SumatraPDF.
Then perform a forward search.
*latex#view#mupdf_poststart*
Function that is called after the MuPDF window has been opened. The function
is used to run `xdotool` commands, for instance to return focus to vim and to
possibly send some keys to MuPDF as specified in |g:latex_view_mupdf_send_keys|.
*latex#view#mupdf_rsearch*
Perform a reverse search by use of `xdotool` and `synctex`.
==============================================================================
FAQ *vim-latex-faq*