Added option to turn of continuous mode (see docs)

This commit is contained in:
Karl Yngve Lervåg 2014-08-24 21:22:24 +02:00
parent d44ecff1cf
commit 0dc505bd58
4 changed files with 88 additions and 57 deletions

View File

@ -232,6 +232,7 @@ function! s:init_options() " {{{1
call latex#util#error_deprecated('g:latex_errorformat_show_warnings') call latex#util#error_deprecated('g:latex_errorformat_show_warnings')
call latex#util#error_deprecated('g:latex_latexmk_autojump') call latex#util#error_deprecated('g:latex_latexmk_autojump')
call latex#util#error_deprecated('g:latex_latexmk_quickfix') call latex#util#error_deprecated('g:latex_latexmk_quickfix')
call latex#util#error_deprecated('g:latex_latexmk_options')
call latex#util#set_default('g:latex_build_dir', '.') call latex#util#set_default('g:latex_build_dir', '.')
call latex#util#set_default('g:latex_complete_enabled', 1) call latex#util#set_default('g:latex_complete_enabled', 1)
@ -264,7 +265,8 @@ function! s:init_options() " {{{1
call latex#util#set_default('g:latex_indent_enabled', 1) call latex#util#set_default('g:latex_indent_enabled', 1)
call latex#util#set_default('g:latex_latexmk_enabled', 1) call latex#util#set_default('g:latex_latexmk_enabled', 1)
call latex#util#set_default('g:latex_latexmk_callback', 1) call latex#util#set_default('g:latex_latexmk_callback', 1)
call latex#util#set_default('g:latex_latexmk_options', '') call latex#util#set_default('g:latex_latexmk_continuous', 1)
call latex#util#set_default('g:latex_latexmk_background', 0)
call latex#util#set_default('g:latex_latexmk_output', 'pdf') call latex#util#set_default('g:latex_latexmk_output', 'pdf')
call latex#util#set_default('g:latex_mappings_enabled', 1) call latex#util#set_default('g:latex_mappings_enabled', 1)
call latex#util#set_default('g:latex_motion_enabled', 1) call latex#util#set_default('g:latex_motion_enabled', 1)

View File

@ -45,6 +45,9 @@ function! latex#latexmk#init(initialized) " {{{1
nnoremap <silent><buffer> <localleader>lo :call latex#latexmk#output()<cr> nnoremap <silent><buffer> <localleader>lo :call latex#latexmk#output()<cr>
endif endif
" The remaining part is only relevant for continuous mode
if !g:latex_latexmk_continuous | return | endif
" "
" Ensure that all latexmk processes are stopped when vim exits " Ensure that all latexmk processes are stopped when vim exits
" Note: Only need to define this once, globally. " Note: Only need to define this once, globally.
@ -69,7 +72,7 @@ endfunction
" }}}1 " }}}1
function! latex#latexmk#clean(full) " {{{1 function! latex#latexmk#clean(full) " {{{1
let data = g:latex#data[b:latex.id] let data = g:latex#data[b:latex.id]
if s:latexmk_check_pid(data.pid) if data.pid
echomsg "latexmk is already running" echomsg "latexmk is already running"
return return
endif endif
@ -106,7 +109,7 @@ endfunction
function! latex#latexmk#compile() " {{{1 function! latex#latexmk#compile() " {{{1
let data = g:latex#data[b:latex.id] let data = g:latex#data[b:latex.id]
if s:latexmk_check_pid(data.pid) if data.pid
echomsg "latexmk is already running for `" . data.base . "'" echomsg "latexmk is already running for `" . data.base . "'"
return return
endif endif
@ -114,17 +117,20 @@ function! latex#latexmk#compile() " {{{1
call s:latexmk_set_cmd(data) call s:latexmk_set_cmd(data)
" Start latexmk " Start latexmk
" Define execute dictionary and latexmk command
let exe = {} let exe = {}
let exe.null = 0 let exe.null = 0
if !g:latex_latexmk_continuous && !g:latex_latexmk_background
let exe.bg = 0
endif
let exe.cmd = data.cmds.compile let exe.cmd = data.cmds.compile
call latex#util#execute(exe) call latex#util#execute(exe)
" Save PID if g:latex_latexmk_continuous
call s:latexmk_set_pid(data) call s:latexmk_set_pid(data)
echomsg 'latexmk continuous mode started successfully'
" Finished else
echomsg 'latexmk started successfully' echomsg 'latexmk compiling'
endif
endfunction endfunction
" }}}1 " }}}1
@ -200,7 +206,7 @@ function! latex#latexmk#status(detailed) " {{{1
if a:detailed if a:detailed
let running = 0 let running = 0
for data in g:latex#data for data in g:latex#data
if s:latexmk_check_pid(data.pid) if data.pid
if !running if !running
echo "latexmk is running" echo "latexmk is running"
let running = 1 let running = 1
@ -219,7 +225,7 @@ function! latex#latexmk#status(detailed) " {{{1
echo "latexmk is not running" echo "latexmk is not running"
endif endif
else else
if s:latexmk_check_pid(g:latex#data[b:latex.id].pid) if g:latex#data[b:latex.id].pid
echo "latexmk is running" echo "latexmk is running"
else else
echo "latexmk is not running" echo "latexmk is not running"
@ -231,7 +237,7 @@ endfunction
function! latex#latexmk#stop() " {{{1 function! latex#latexmk#stop() " {{{1
let pid = g:latex#data[b:latex.id].pid let pid = g:latex#data[b:latex.id].pid
let base = g:latex#data[b:latex.id].base let base = g:latex#data[b:latex.id].base
if s:latexmk_check_pid(pid) if pid
call s:latexmk_kill_pid(pid) call s:latexmk_kill_pid(pid)
let g:latex#data[b:latex.id].pid = 0 let g:latex#data[b:latex.id].pid = 0
echo "latexmk stopped for `" . base . "'" echo "latexmk stopped for `" . base . "'"
@ -243,7 +249,7 @@ endfunction
" }}}1 " }}}1
function! latex#latexmk#stop_all() " {{{1 function! latex#latexmk#stop_all() " {{{1
for data in g:latex#data for data in g:latex#data
if s:latexmk_check_pid(data.pid) if data.pid
call s:latexmk_kill_pid(data.pid) call s:latexmk_kill_pid(data.pid)
let data.pid = 0 let data.pid = 0
endif endif
@ -267,30 +273,32 @@ function! s:latexmk_set_cmd(data) " {{{1
endif endif
let cmd .= ' -' . g:latex_latexmk_output let cmd .= ' -' . g:latex_latexmk_output
let cmd .= ' -verbose '
let cmd .= ' -pvc'
let cmd .= ' ' . g:latex_latexmk_options
let cmd .= ' -e ' . shellescape('$pdflatex =~ s/ / -file-line-error /') let cmd .= ' -e ' . shellescape('$pdflatex =~ s/ / -file-line-error /')
if g:latex_latexmk_callback && has('clientserver') if g:latex_latexmk_continuous
let callback = 'vim --servername ' . v:servername let cmd .= ' -pvc'
\ . ' --remote-expr \"latex\#latexmk\#errors(0)\"' if g:latex_latexmk_callback && has('clientserver')
if has('win32') let callback = 'vim --servername ' . v:servername
let cmd .= ' -e "$success_cmd .= ''' . callback . '''"' \ . ' --remote-expr \"latex\#latexmk\#errors(0)\"'
\ . ' -e "$failure_cmd .= ''' . callback . '''"' if has('win32')
else let cmd .= ' -e "$success_cmd .= ''' . callback . '''"'
let cmd .= ' -e ''$success_cmd .= "' . callback . '"''' \ . ' -e "$failure_cmd .= ''' . callback . '''"'
\ . ' -e ''$failure_cmd .= "' . callback . '"''' else
let cmd .= ' -e ''$success_cmd .= "' . callback . '"'''
\ . ' -e ''$failure_cmd .= "' . callback . '"'''
endif
endif endif
endif endif
let cmd .= ' ' . shellescape(a:data.base) let cmd .= ' ' . shellescape(a:data.base)
if has('win32') if g:latex_latexmk_continuous || g:latex_latexmk_background
let cmd .= ' >' . tmp if has('win32')
let cmd = 'cmd /s /c "' . cmd . '"' let cmd .= ' >' . tmp
else let cmd = 'cmd /s /c "' . cmd . '"'
let cmd .= ' &>' . tmp else
let cmd .= ' &>' . tmp
endif
endif endif
let a:data.cmds.compile = cmd let a:data.cmds.compile = cmd
@ -313,18 +321,6 @@ function! s:latexmk_set_pid(data) " {{{1
endif endif
endfunction endfunction
function! s:latexmk_check_pid(pid) " {{{1
if has('win32')
" don't have Windows ==> no change
return a:pid
else
" ps considers a 0 PID out of range and prints and error message
" side effect: will no longer see laxtexmk commands run externally
return a:pid && system('ps -p ' . a:pid . ' -o cmd= | grep "^perl.*latexmk"')
endif
endfunction
" }}}1
function! s:latexmk_kill_pid(pid) " {{{1 function! s:latexmk_kill_pid(pid) " {{{1
let exe = {} let exe = {}
let exe.bg = 0 let exe.bg = 0
@ -361,7 +357,7 @@ function! s:stop_buffer() " {{{1
" "
" Only stop if latexmk is running " Only stop if latexmk is running
" "
if s:latexmk_check_pid(pid) if pid
" "
" Count the number of buffers that point to current latex blob " Count the number of buffers that point to current latex blob
" "

View File

@ -140,7 +140,11 @@ function! latex#util#execute(exe) " {{{1
endif endif
endif endif
silent execute cmd if bg
silent execute cmd
else
execute cmd
endif
" Return to previous working directory " Return to previous working directory
if has_key(a:exe, 'wd') if has_key(a:exe, 'wd')

View File

@ -280,7 +280,8 @@ Overview:~
|g:latex_indent_enabled| |g:latex_indent_enabled|
|g:latex_latexmk_callback| |g:latex_latexmk_callback|
|g:latex_latexmk_enabled| |g:latex_latexmk_enabled|
|g:latex_latexmk_options| |g:latex_latexmk_continuous|
|g:latex_latexmk_background|
|g:latex_latexmk_output| |g:latex_latexmk_output|
|g:latex_mappings_enabled| |g:latex_mappings_enabled|
|g:latex_motion_enabled| |g:latex_motion_enabled|
@ -390,9 +391,17 @@ necessary variables and autocommands will not be defined, and the mappings
will not be created. > will not be created. >
let g:latex_latexmk_enabled = 1 let g:latex_latexmk_enabled = 1
< <
*g:latex_latexmk_options* *g:latex_latexmk_background*
Set extra options for `latexmk` compilation. > If continuous mode is disabled, then this option may be used to set
let g:latex_latexmk_options = '' whether single compilations should be run in the foreground or the
background. >
let g:latex_latexmk_background = 0
<
*g:latex_latexmk_continuous*
If enabled, `latexmk` will run in continuous mode. This means that the
document is compiled every time a document file has been changed. Set to 0 to
disable. Note that the callback functions only work if continuous mode is enabled. >
let g:latex_latexmk_continuous = 1
< <
*g:latex_latexmk_output* *g:latex_latexmk_output*
Set desired output for `latexmk` compilation. > Set desired output for `latexmk` compilation. >
@ -615,9 +624,9 @@ Associated settings:
============================================================================== ==============================================================================
LATEXMK *vim-latex-latexmk* LATEXMK *vim-latex-latexmk*
|vim-latex| provides a basic interface to `latexmk` for background |vim-latex| provides a basic interface to `latexmk` for compilation. The
compilation. The interface may be disabled with |g:latex_latexmk_enabled|. interface may be disabled with |g:latex_latexmk_enabled|. The default
The default mappings are: > mappings are: >
nnoremap <localleader>ll :call latex#latexmk#compile()<cr> nnoremap <localleader>ll :call latex#latexmk#compile()<cr>
nnoremap <localleader>lk :call latex#latexmk#stop(1)<cr> nnoremap <localleader>lk :call latex#latexmk#stop(1)<cr>
@ -629,11 +638,17 @@ The default mappings are: >
nnoremap <localleader>lc :call latex#latexmk#clean(0)<cr> nnoremap <localleader>lc :call latex#latexmk#clean(0)<cr>
nnoremap <localleader>lC :call latex#latexmk#clean(1)<cr> nnoremap <localleader>lC :call latex#latexmk#clean(1)<cr>
The background compilation is started with |latex#latexmk#compile|. It relies Compilation is started with |latex#latexmk#compile|. The default behaviour
on the preview continuous mode of `latexmk`. If vim is compiled with the uses preview continuous mode of `latexmk`, which may be disabled with
|+clientserver| option and if |g:latex_latexmk_callback| is enabled, then |g:latex_latexmk_continuous|. If it is disabled, then the option
compilation errors are parsed automatically. This is done by utilizing the |g:latex_latexmk_background| may be used to decide if the single shot
tricks explained in |vim-latex-latexmk-tricks|. compilation should run in the foreground or the background.
If vim is compiled with the |+clientserver| option and if
|g:latex_latexmk_callback| is enabled, then compilation errors are parsed
automatically. This is done by utilizing the tricks explained in
|vim-latex-latexmk-tricks|. Note however that this only works for continuous
compilation mode.
To check for and view errors in the quickfix window, use To check for and view errors in the quickfix window, use
|latex#latexmk#errors|. To check if background compilation is running, use |latex#latexmk#errors|. To check if background compilation is running, use
@ -643,7 +658,8 @@ Associated settings:
|g:latex_latexmk_enabled| |g:latex_latexmk_enabled|
|g:latex_latexmk_callback| |g:latex_latexmk_callback|
|g:latex_latexmk_autojump| |g:latex_latexmk_autojump|
|g:latex_latexmk_options| |g:latex_latexmk_continuous|
|g:latex_latexmk_background|
|g:latex_latexmk_output| |g:latex_latexmk_output|
Functions: Functions:
@ -1017,6 +1033,19 @@ CHANGELOG *vim-latex-changelog*
The following changelog only logs important changes, such as changes that The following changelog only logs important changes, such as changes that
break backwards compatibility. See the git log for the detailed changelog. break backwards compatibility. See the git log for the detailed changelog.
2014-08-24: Made continuous mode optional~
Added option |g:latex_latexmk_continuous| to set whether or not the `latexmk`
process should run in continuous mode. Also added option
|g:latex_latexmk_background| to set whether single compilations should run in
the foreground or the background.
I also deprecated the old variable that sets options for `latexmk`, because
I find that it makes more sense to control `latexmk` through `latexmkrc`
files.
Deprecated option:
*g:latex_latexmk_options*
2014-06-13: Changed some option names~ 2014-06-13: Changed some option names~
Some |vim-latex| option names were changed in an attempt to make the names Some |vim-latex| option names were changed in an attempt to make the names
more consistent. These options are listed here for reference: more consistent. These options are listed here for reference: