Skip to content

Commit

Permalink
feat: allow options for VimtexCompile
Browse files Browse the repository at this point in the history
refer: #2836
  • Loading branch information
lervag committed Nov 25, 2023
1 parent 283252f commit 6c4c3cd
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 21 deletions.
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 call(b:vimtex.compiler.start_single, 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 call(b:vimtex.compiler.start, a:000)

if g:vimtex_compiler_silent | return | endif

Expand Down
8 changes: 4 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,7 @@ function! s:compiler.start(...) abort dict " {{{1
call writefile([], self.output, 'a')

" Prepare compile command
let self.cmd = self.__build_cmd()
let self.cmd = self.__build_cmd(a:000)
let l:cmd = has('win32')
\ ? 'cmd /s /c "' . self.cmd . '"'
\ : ['sh', '-c', self.cmd]
Expand Down Expand Up @@ -266,10 +266,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(opts) abort dict " {{{1
return self.command . ' ' . join(a:opts)
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(opts) 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) . ' ' . join(a:opts)
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(opts) abort dict " {{{1
return 'latexrun ' . join(self.options)
\ . ' --latex-cmd ' . self.get_engine()
\ . ' -O '
\ . (empty(self.out_dir) ? '.' : fnameescape(self.out_dir))
\ . ' ' . join(a:opts)
\ . ' ' . 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(opts) 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 . '"'
\ . ' ' . join(a:opts)
\ . ' ' . vimtex#util#shellescape(self.state.base)
endfunction

Expand Down
12 changes: 10 additions & 2 deletions doc/vimtex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3500,14 +3500,22 @@ 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|.

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

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

0 comments on commit 6c4c3cd

Please sign in to comment.