Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow options for VimtexCompile #2837

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions autoload/vimtex/compiler.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ function! vimtex#compiler#init_buffer() abort " {{{1
if !g:vimtex_compiler_enabled | return | endif

" Define commands
command! -buffer VimtexCompile call vimtex#compiler#compile()
command! -buffer -bang VimtexCompileSS call vimtex#compiler#compile_ss()
command! -buffer -nargs=* VimtexCompile call vimtex#compiler#compile(<f-args>)
command! -buffer -bang -nargs=* VimtexCompileSS call vimtex#compiler#compile_ss(<f-args>)

command! -buffer -range VimtexCompileSelected <line1>,<line2>call vimtex#compiler#compile_selected('command')
command! -buffer VimtexCompileOutput call vimtex#compiler#output()
command! -buffer VimtexStop call vimtex#compiler#stop()
Expand Down Expand Up @@ -98,18 +99,18 @@ endfunction

" }}}1

function! vimtex#compiler#compile() abort " {{{1
function! vimtex#compiler#compile(...) abort " {{{1
if !b:vimtex.compiler.enabled | return | endif

if b:vimtex.compiler.is_running()
call vimtex#compiler#stop()
else
call vimtex#compiler#start()
call call('vimtex#compiler#start', a:000)
endif
endfunction

" }}}1
function! vimtex#compiler#compile_ss() abort " {{{1
function! vimtex#compiler#compile_ss(...) abort " {{{1
if !b:vimtex.compiler.enabled | return | endif

if b:vimtex.compiler.is_running()
Expand All @@ -118,7 +119,7 @@ function! vimtex#compiler#compile_ss() abort " {{{1
return
endif

call b:vimtex.compiler.start_single()
call b:vimtex.compiler.start_single(expandcmd(join(a:000)))

if g:vimtex_compiler_silent | return | endif
call vimtex#log#info('Compiler started in background!')
Expand Down Expand Up @@ -193,7 +194,7 @@ function! vimtex#compiler#output() abort " {{{1
endfunction

" }}}1
function! vimtex#compiler#start() abort " {{{1
function! vimtex#compiler#start(...) abort " {{{1
if !b:vimtex.compiler.enabled | return | endif

if !b:vimtex.is_compileable()
Expand All @@ -210,7 +211,7 @@ function! vimtex#compiler#start() abort " {{{1
return
endif

call b:vimtex.compiler.start()
call b:vimtex.compiler.start(expandcmd(join(a:000)))

if g:vimtex_compiler_silent | return | endif

Expand Down
9 changes: 5 additions & 4 deletions autoload/vimtex/compiler/_template.vim
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function! s:compiler.__init() abort dict " {{{1
endfunction

" }}}1
function! s:compiler.__build_cmd() abort dict " {{{1
function! s:compiler.__build_cmd(opts) abort dict " {{{1
throw 'VimTeX: __build_cmd method must be defined!'
endfunction

Expand Down Expand Up @@ -226,7 +226,8 @@ function! s:compiler.start(...) abort dict " {{{1
call writefile([], self.output, 'a')

" Prepare compile command
let self.cmd = self.__build_cmd()
let l:passed_options = a:0 > 0 ? ' ' . a:1 : ''
let self.cmd = self.__build_cmd(l:passed_options)
let l:cmd = has('win32')
\ ? 'cmd /s /c "' . self.cmd . '"'
\ : ['sh', '-c', self.cmd]
Expand Down Expand Up @@ -266,10 +267,10 @@ endfunction
" }}}2

" }}}1
function! s:compiler.start_single() abort dict " {{{1
function! s:compiler.start_single(...) abort dict " {{{1
let l:continuous = self.continuous
let self.continuous = 0
call self.start()
call call(self.start, a:000)
let self.continuous = l:continuous
endfunction

Expand Down
3 changes: 2 additions & 1 deletion autoload/vimtex/compiler/arara.vim
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ function! s:compiler.__check_requirements() abort dict " {{{1
endfunction

" }}}1
function! s:compiler.__build_cmd() abort dict " {{{1
function! s:compiler.__build_cmd(opts) abort dict " {{{1
return 'arara ' . join(self.options)
\ . ' ' . join(a:opts)
\ . ' ' . vimtex#util#shellescape(self.state.base)
endfunction

Expand Down
4 changes: 2 additions & 2 deletions autoload/vimtex/compiler/generic.vim
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ function! s:compiler.__check_requirements() abort dict " {{{1
endfunction

" }}}1
function! s:compiler.__build_cmd() abort dict " {{{1
return self.command
function! s:compiler.__build_cmd(passed_options) abort dict " {{{1
return self.command . a:passed_options
endfunction

" }}}1
4 changes: 2 additions & 2 deletions autoload/vimtex/compiler/latexmk.vim
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ function! s:compiler.__init() abort dict " {{{1
endfunction

" }}}1
function! s:compiler.__build_cmd() abort dict " {{{1
function! s:compiler.__build_cmd(passed_options) abort dict " {{{1
let l:cmd = (has('win32')
\ ? 'set max_print_line=2000 & '
\ : 'max_print_line=2000 ') . self.executable

let l:cmd .= ' ' . join(self.options)
let l:cmd .= ' ' . join(self.options) . a:passed_options
let l:cmd .= ' ' . self.get_engine()

if !empty(self.out_dir)
Expand Down
3 changes: 2 additions & 1 deletion autoload/vimtex/compiler/latexrun.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ function! s:compiler.__check_requirements() abort dict " {{{1
endfunction

" }}}1
function! s:compiler.__build_cmd() abort dict " {{{1
function! s:compiler.__build_cmd(passed_options) abort dict " {{{1
return 'latexrun ' . join(self.options)
\ . ' --latex-cmd ' . self.get_engine()
\ . ' -O '
\ . (empty(self.out_dir) ? '.' : fnameescape(self.out_dir))
\ . a:passed_options
\ . ' ' . vimtex#util#shellescape(self.state.base)
endfunction

Expand Down
3 changes: 2 additions & 1 deletion autoload/vimtex/compiler/tectonic.vim
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ function! s:compiler.__check_requirements() abort dict " {{{1
endfunction

" }}}1
function! s:compiler.__build_cmd() abort dict " {{{1
function! s:compiler.__build_cmd(passed_options) abort dict " {{{1
let l:outdir = !empty(self.out_dir)
\ ? self.out_dir
\ : fnamemodify(self.state.tex, ':p:h')

return 'tectonic ' . join(self.options)
\ . ' --outdir="' . l:outdir . '"'
\ . a:passed_options
\ . ' ' . vimtex#util#shellescape(self.state.base)
endfunction

Expand Down
15 changes: 13 additions & 2 deletions doc/vimtex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3500,14 +3500,25 @@ COMMANDS *vimtex-commands*

*:VimtexCompile*
*<plug>(vimtex-compile)*
:VimtexCompile If the compiler supports and is set to run in
:VimtexCompile [opts] If the compiler supports and is set to run in
continuous mode, then this command works as
a compiler toggle. If not, this command will run
a single shot compilation.

Arguments to the command will be passed on as options
when starting the compiler. This allows the user to
start the compiler with different options without
changing any configuration. That is, if the user uses
the latexmk backend, then adding any option argument
is equivalent to adding them to the `'options'` key
of |g:vimtex_compiler_latexmk|.

Note: Special items in the arguments will be
expanded as explained in |expandcmd|.

*:VimtexCompileSS*
*<plug>(vimtex-compile-ss)*
:VimtexCompileSS Start single shot compilation.
:VimtexCompileSS [opts] Start single shot compilation.

*:VimtexCompileSelected*
*<plug>(vimtex-compile-selected)*
Expand Down