diff --git a/autoload/latex.vim b/autoload/latex.vim index 95f386d..051f5cb 100644 --- a/autoload/latex.vim +++ b/autoload/latex.vim @@ -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_latexmk_autojump') 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_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_latexmk_enabled', 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_mappings_enabled', 1) call latex#util#set_default('g:latex_motion_enabled', 1) diff --git a/autoload/latex/latexmk.vim b/autoload/latex/latexmk.vim index 62260c4..6fdeaaf 100644 --- a/autoload/latex/latexmk.vim +++ b/autoload/latex/latexmk.vim @@ -45,6 +45,9 @@ function! latex#latexmk#init(initialized) " {{{1 nnoremap lo :call latex#latexmk#output() 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 " Note: Only need to define this once, globally. @@ -69,7 +72,7 @@ endfunction " }}}1 function! latex#latexmk#clean(full) " {{{1 let data = g:latex#data[b:latex.id] - if s:latexmk_check_pid(data.pid) + if data.pid echomsg "latexmk is already running" return endif @@ -106,7 +109,7 @@ endfunction function! latex#latexmk#compile() " {{{1 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 . "'" return endif @@ -114,17 +117,20 @@ function! latex#latexmk#compile() " {{{1 call s:latexmk_set_cmd(data) " Start latexmk - " Define execute dictionary and latexmk command let exe = {} let exe.null = 0 + if !g:latex_latexmk_continuous && !g:latex_latexmk_background + let exe.bg = 0 + endif let exe.cmd = data.cmds.compile call latex#util#execute(exe) - " Save PID - call s:latexmk_set_pid(data) - - " Finished - echomsg 'latexmk started successfully' + if g:latex_latexmk_continuous + call s:latexmk_set_pid(data) + echomsg 'latexmk continuous mode started successfully' + else + echomsg 'latexmk compiling' + endif endfunction " }}}1 @@ -200,7 +206,7 @@ function! latex#latexmk#status(detailed) " {{{1 if a:detailed let running = 0 for data in g:latex#data - if s:latexmk_check_pid(data.pid) + if data.pid if !running echo "latexmk is running" let running = 1 @@ -219,7 +225,7 @@ function! latex#latexmk#status(detailed) " {{{1 echo "latexmk is not running" endif 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" else echo "latexmk is not running" @@ -231,7 +237,7 @@ endfunction function! latex#latexmk#stop() " {{{1 let pid = g:latex#data[b:latex.id].pid let base = g:latex#data[b:latex.id].base - if s:latexmk_check_pid(pid) + if pid call s:latexmk_kill_pid(pid) let g:latex#data[b:latex.id].pid = 0 echo "latexmk stopped for `" . base . "'" @@ -243,7 +249,7 @@ endfunction " }}}1 function! latex#latexmk#stop_all() " {{{1 for data in g:latex#data - if s:latexmk_check_pid(data.pid) + if data.pid call s:latexmk_kill_pid(data.pid) let data.pid = 0 endif @@ -267,30 +273,32 @@ function! s:latexmk_set_cmd(data) " {{{1 endif 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 /') - if g:latex_latexmk_callback && has('clientserver') - let callback = 'vim --servername ' . v:servername - \ . ' --remote-expr \"latex\#latexmk\#errors(0)\"' - if has('win32') - let cmd .= ' -e "$success_cmd .= ''' . callback . '''"' - \ . ' -e "$failure_cmd .= ''' . callback . '''"' - else - let cmd .= ' -e ''$success_cmd .= "' . callback . '"''' - \ . ' -e ''$failure_cmd .= "' . callback . '"''' + if g:latex_latexmk_continuous + let cmd .= ' -pvc' + if g:latex_latexmk_callback && has('clientserver') + let callback = 'vim --servername ' . v:servername + \ . ' --remote-expr \"latex\#latexmk\#errors(0)\"' + if has('win32') + let cmd .= ' -e "$success_cmd .= ''' . callback . '''"' + \ . ' -e "$failure_cmd .= ''' . callback . '''"' + else + let cmd .= ' -e ''$success_cmd .= "' . callback . '"''' + \ . ' -e ''$failure_cmd .= "' . callback . '"''' + endif endif endif let cmd .= ' ' . shellescape(a:data.base) - if has('win32') - let cmd .= ' >' . tmp - let cmd = 'cmd /s /c "' . cmd . '"' - else - let cmd .= ' &>' . tmp + if g:latex_latexmk_continuous || g:latex_latexmk_background + if has('win32') + let cmd .= ' >' . tmp + let cmd = 'cmd /s /c "' . cmd . '"' + else + let cmd .= ' &>' . tmp + endif endif let a:data.cmds.compile = cmd @@ -313,18 +321,6 @@ function! s:latexmk_set_pid(data) " {{{1 endif 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 let exe = {} let exe.bg = 0 @@ -361,7 +357,7 @@ function! s:stop_buffer() " {{{1 " " 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 " diff --git a/autoload/latex/util.vim b/autoload/latex/util.vim index 531c896..aaf28c6 100644 --- a/autoload/latex/util.vim +++ b/autoload/latex/util.vim @@ -140,7 +140,11 @@ function! latex#util#execute(exe) " {{{1 endif endif - silent execute cmd + if bg + silent execute cmd + else + execute cmd + endif " Return to previous working directory if has_key(a:exe, 'wd') diff --git a/doc/latex.txt b/doc/latex.txt index ed1cb3f..24f7f7d 100644 --- a/doc/latex.txt +++ b/doc/latex.txt @@ -280,7 +280,8 @@ Overview:~ |g:latex_indent_enabled| |g:latex_latexmk_callback| |g:latex_latexmk_enabled| - |g:latex_latexmk_options| + |g:latex_latexmk_continuous| + |g:latex_latexmk_background| |g:latex_latexmk_output| |g:latex_mappings_enabled| |g:latex_motion_enabled| @@ -390,9 +391,17 @@ necessary variables and autocommands will not be defined, and the mappings will not be created. > let g:latex_latexmk_enabled = 1 < - *g:latex_latexmk_options* -Set extra options for `latexmk` compilation. > - let g:latex_latexmk_options = '' + *g:latex_latexmk_background* +If continuous mode is disabled, then this option may be used to set +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* Set desired output for `latexmk` compilation. > @@ -615,9 +624,9 @@ Associated settings: ============================================================================== LATEXMK *vim-latex-latexmk* -|vim-latex| provides a basic interface to `latexmk` for background -compilation. The interface may be disabled with |g:latex_latexmk_enabled|. -The default mappings are: > +|vim-latex| provides a basic interface to `latexmk` for compilation. The +interface may be disabled with |g:latex_latexmk_enabled|. The default +mappings are: > nnoremap ll :call latex#latexmk#compile() nnoremap lk :call latex#latexmk#stop(1) @@ -629,11 +638,17 @@ The default mappings are: > nnoremap lc :call latex#latexmk#clean(0) nnoremap lC :call latex#latexmk#clean(1) -The background compilation is started with |latex#latexmk#compile|. It relies -on the preview continuous mode of `latexmk`. 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|. +Compilation is started with |latex#latexmk#compile|. The default behaviour +uses preview continuous mode of `latexmk`, which may be disabled with +|g:latex_latexmk_continuous|. If it is disabled, then the option +|g:latex_latexmk_background| may be used to decide if the single shot +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 |latex#latexmk#errors|. To check if background compilation is running, use @@ -643,7 +658,8 @@ Associated settings: |g:latex_latexmk_enabled| |g:latex_latexmk_callback| |g:latex_latexmk_autojump| - |g:latex_latexmk_options| + |g:latex_latexmk_continuous| + |g:latex_latexmk_background| |g:latex_latexmk_output| Functions: @@ -1017,6 +1033,19 @@ CHANGELOG *vim-latex-changelog* The following changelog only logs important changes, such as changes that 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~ Some |vim-latex| option names were changed in an attempt to make the names more consistent. These options are listed here for reference: