Improve support for output_directory (fixes #162)

Old code did not support absolute paths for output directory.
This commit is contained in:
Karl Yngve Lervåg 2015-05-05 20:49:29 +02:00
parent 5d39c6b4b2
commit 763a796273
3 changed files with 26 additions and 46 deletions

View File

@ -88,7 +88,7 @@ function! s:init_environment() " {{{1
return s:get_main_ext(self, 'log')
endfunction
function data.out() dict
return s:get_main_out(self)
return s:get_main_ext(self, 'pdf')
endfunction
call add(g:vimtex#data, data)
@ -269,49 +269,25 @@ function! s:get_main_recurse(file) " {{{1
return 0
endfunction
function! s:get_main_ext(texdata, ext) " {{{1
" Create set of candidates
let candidates = [
\ a:texdata.name,
\ g:vimtex_latexmk_build_dir . '/' . a:texdata.name,
\ ]
" Search through the candidates
for f in map(candidates,
\ 'a:texdata.root . ''/'' . v:val . ''.'' . a:ext')
if filereadable(f)
return fnamemodify(f, ':p')
function! s:get_main_ext(self, ext) " {{{1
" First check build dir (latexmk -output_directory option)
if g:vimtex_latexmk_build_dir !=# ''
let cand = g:vimtex_latexmk_build_dir . '/' . a:self.name . '.' . a:ext
if g:vimtex_latexmk_build_dir[0] !=# '/'
let cand = a:self.root . '/' . cand
endif
endfor
" Return empty string if no entry is found
return ''
endfunction
function! s:get_main_out(texdata) " {{{1
" Create set of candidates
let candidates = [
\ a:texdata.name,
\ g:vimtex_latexmk_build_dir . '/' . a:texdata.name,
\ ]
" Check for pdf files
for f in map(candidates,
\ 'a:texdata.root . ''/'' . v:val . ''.pdf''')
if filereadable(f)
return fnamemodify(f, ':p')
if filereadable(cand)
return fnamemodify(cand, ':p')
endif
endfor
endif
" Check for dvi files
for f in map(candidates,
\ 'a:texdata.root . ''/'' . v:val . ''.dvi''')
if filereadable(f)
return fnamemodify(f, ':p')
endif
endfor
" Next check for file in project root folder
let cand = a:self.root . '/' . a:self.name . '.' . a:ext
if filereadable(cand)
return fnamemodify(cand, ':p')
endif
" Return empty string if no entry is found
" Finally return empty string if no entry is found
return ''
endfunction

View File

@ -6,7 +6,7 @@
function! vimtex#latexmk#init(initialized) " {{{1
call vimtex#util#set_default('g:vimtex_latexmk_enabled', 1)
call vimtex#util#set_default('g:vimtex_latexmk_build_dir', '.')
call vimtex#util#set_default('g:vimtex_latexmk_build_dir', '')
if !g:vimtex_latexmk_enabled | return | endif
if s:system_incompatible() | return | endif
@ -109,7 +109,7 @@ function! vimtex#latexmk#clean(full) " {{{1
let cmd = 'cd ' . shellescape(data.root) . '; '
endif
let cmd .= 'latexmk'
if g:vimtex_latexmk_build_dir !=# '.'
if g:vimtex_latexmk_build_dir !=# ''
let cmd .= ' -outdir=' . g:vimtex_latexmk_build_dir
endif
let cmd .= a:full ? ' -C ' : ' -c '
@ -388,7 +388,9 @@ function! s:latexmk_build_cmd(data) " {{{1
let cmd .= ' ' . g:vimtex_latexmk_options
let cmd .= ' -e ' . shellescape('$pdflatex =~ s/ / -file-line-error /')
let cmd .= ' -outdir=' . g:vimtex_latexmk_build_dir
if g:vimtex_latexmk_build_dir !=# ''
let cmd .= ' -outdir=' . g:vimtex_latexmk_build_dir
endif
if g:vimtex_latexmk_continuous
let cmd .= ' -pvc'

View File

@ -446,10 +446,12 @@ Options~
*g:vimtex_latexmk_build_dir*
This option sets the compilation build directory. It corresponds to the
`-output-directory` option in `latexmk`. Note that this option only works
with `latexmk` version 4.27 and later.
`-output-directory` option in `latexmk`. If the path is a relative path,
then it will be considered relative to the main project file.
Note that this option only works with `latexmk` version 4.27 and later.
Default value: '.'
Default value: ''
*g:vimtex_latexmk_callback*
If enabled, this option tells `latexmk` to run |vimtex#latexmk#callback| after