From 6c4c3cd192c606507ffb44fc4cdca71dbc7c3e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Yngve=20Lerv=C3=A5g?= Date: Sun, 26 Nov 2023 00:01:41 +0100 Subject: [PATCH] feat: allow options for VimtexCompile refer: #2836 --- autoload/vimtex/compiler.vim | 17 +++++++++-------- autoload/vimtex/compiler/_template.vim | 8 ++++---- autoload/vimtex/compiler/arara.vim | 3 ++- autoload/vimtex/compiler/generic.vim | 4 ++-- autoload/vimtex/compiler/latexmk.vim | 4 ++-- autoload/vimtex/compiler/latexrun.vim | 3 ++- autoload/vimtex/compiler/tectonic.vim | 3 ++- doc/vimtex.txt | 12 ++++++++++-- 8 files changed, 33 insertions(+), 21 deletions(-) diff --git a/autoload/vimtex/compiler.vim b/autoload/vimtex/compiler.vim index a0bbbb3e6b..4ceb52d349 100644 --- a/autoload/vimtex/compiler.vim +++ b/autoload/vimtex/compiler.vim @@ -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() + command! -buffer -bang -nargs=* VimtexCompileSS call vimtex#compiler#compile_ss() + command! -buffer -range VimtexCompileSelected ,call vimtex#compiler#compile_selected('command') command! -buffer VimtexCompileOutput call vimtex#compiler#output() command! -buffer VimtexStop call vimtex#compiler#stop() @@ -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() @@ -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!') @@ -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() @@ -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 diff --git a/autoload/vimtex/compiler/_template.vim b/autoload/vimtex/compiler/_template.vim index 0760b3fa36..327cf61aab 100644 --- a/autoload/vimtex/compiler/_template.vim +++ b/autoload/vimtex/compiler/_template.vim @@ -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 @@ -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] @@ -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 diff --git a/autoload/vimtex/compiler/arara.vim b/autoload/vimtex/compiler/arara.vim index f8a5876f4c..92285a60cf 100644 --- a/autoload/vimtex/compiler/arara.vim +++ b/autoload/vimtex/compiler/arara.vim @@ -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 diff --git a/autoload/vimtex/compiler/generic.vim b/autoload/vimtex/compiler/generic.vim index f580463a59..b7854bc71c 100644 --- a/autoload/vimtex/compiler/generic.vim +++ b/autoload/vimtex/compiler/generic.vim @@ -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 diff --git a/autoload/vimtex/compiler/latexmk.vim b/autoload/vimtex/compiler/latexmk.vim index 6ab42fc5c4..c476f958f1 100644 --- a/autoload/vimtex/compiler/latexmk.vim +++ b/autoload/vimtex/compiler/latexmk.vim @@ -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) diff --git a/autoload/vimtex/compiler/latexrun.vim b/autoload/vimtex/compiler/latexrun.vim index 109c1182fd..3df184bde9 100644 --- a/autoload/vimtex/compiler/latexrun.vim +++ b/autoload/vimtex/compiler/latexrun.vim @@ -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 diff --git a/autoload/vimtex/compiler/tectonic.vim b/autoload/vimtex/compiler/tectonic.vim index ec621faeb9..e330e8ff6d 100644 --- a/autoload/vimtex/compiler/tectonic.vim +++ b/autoload/vimtex/compiler/tectonic.vim @@ -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 diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 650987220f..cc796f8464 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -3500,14 +3500,22 @@ COMMANDS *vimtex-commands* *:VimtexCompile* *(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* *(vimtex-compile-ss)* -:VimtexCompileSS Start single shot compilation. +:VimtexCompileSS [opts] Start single shot compilation. *:VimtexCompileSelected* *(vimtex-compile-selected)*