Skip to content

Commit

Permalink
feat!: pass argument to out_dir function
Browse files Browse the repository at this point in the history
This is a breaking change for anyone who uses a vimscript function for
the `out_dir` key of g:vimtex_compiler_latexmk (or similar), because the
function is now passed a single argument.

refer: #2888
  • Loading branch information
lervag committed Feb 25, 2024
1 parent 01c4c16 commit 88eca56
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
10 changes: 4 additions & 6 deletions autoload/vimtex/compiler.vim
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,10 @@ function! s:init_compiler(options) abort " {{{1
let l:method = 'latexmk'
endif

let l:options =
\ get(g:, 'vimtex_compiler_' . l:method, {})
let l:options = extend(deepcopy(l:options), a:options)
let l:compiler
\ = vimtex#compiler#{l:method}#init(l:options)
return l:compiler
let l:options = extend(
\ deepcopy(get(g:, 'vimtex_compiler_' . l:method, {})),
\ a:options)
return vimtex#compiler#{l:method}#init(l:options)
endfunction

" }}}1
Expand Down
3 changes: 2 additions & 1 deletion autoload/vimtex/compiler/_template.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ function! s:compiler.new(options) abort dict " {{{1

call l:compiler.__check_requirements()

call vimtex#util#materialize_property(l:compiler, 'out_dir')
call vimtex#util#materialize_property(
\ l:compiler, 'out_dir', l:compiler.file_info)
call l:compiler.__init()

" $VIMTEX_OUTPUT_DIRECTORY overrides configured compiler.out_dir
Expand Down
2 changes: 1 addition & 1 deletion autoload/vimtex/compiler/latexmk.vim
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ endfunction

" }}}1
function! s:compiler.__init() abort dict " {{{1
call vimtex#util#materialize_property(self, 'aux_dir')
call vimtex#util#materialize_property(self, 'aux_dir', self.file_info)

call s:compare_with_latexmkrc(self, 'out_dir')
call s:compare_with_latexmkrc(self, 'aux_dir')
Expand Down
4 changes: 2 additions & 2 deletions autoload/vimtex/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ function! vimtex#util#extend_recursive(dict1, dict2, ...) abort " {{{1
endfunction

" }}}1
function! vimtex#util#materialize_property(dict, name) abort " {{{1
function! vimtex#util#materialize_property(dict, name, ...) abort " {{{1
if type(get(a:dict, a:name)) != v:t_func | return | endif

try
let a:dict[a:name] = a:dict[a:name]()
let a:dict[a:name] = call(a:dict[a:name], a:000)
catch
call vimtex#log#error(
\ 'Could not materialize property: ' . a:name,
Expand Down
28 changes: 15 additions & 13 deletions doc/vimtex.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1041,10 +1041,20 @@ OPTIONS *vimtex-options*

The value of this option should be either:
1) a string that represents a path, or
2) a |Funcref|. The |Funcref| type makes it possible to specify
a dynamic `aux_dir`. It may be easier to understand from an example: >vim
2) a |Funcref| with a single dictionary argument "file_info": >
file_info = {
root = …
target = …
target_basename = …
target_name = …
jobname = …
}
<
This makes it possible to specify a dynamic `aux_dir`. It may be
easier to understand from an example: >vim

let g:vimtex_compiler_latexmk = {'aux_dir': {-> expand("%:t:r")}}
let g:vimtex_compiler_latexmk = {'aux_dir': {_ -> expand("%:t:r")}}
<
With the above setting, the `aux_dir` is set to the base name of the
current file. E.g., If you do `vim test.tex`, the value becomes
Expand All @@ -1065,16 +1075,8 @@ OPTIONS *vimtex-options*
corresponds to the `$out_dir` option in `latexmk`. If the path is
a relative path, then it is considered relative to the main project file.

The value of this option should be either:
1) a string that represents a path, or
2) a |Funcref|. The |Funcref| type makes it possible to specify
a dynamic `out_dir`. It may be easier to understand from an example: >vim

let g:vimtex_compiler_latexmk = {'out_dir': {-> expand("%:t:r")}}
<
With the above setting, the `out_dir` is set to the base name of the
current file. E.g., If you do `vim test.tex`, the value becomes
`test`.
The value is either a string or a |Funcref|, similar to the above
described `aux_dir` key.

The specified output directory is created if it does not exist.

Expand Down

0 comments on commit 88eca56

Please sign in to comment.