mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-07 15:42:08 -07:00
[vim] Make arguments to fzf#wrap() optional
fzf#wrap([name string,] [opts dict,] [fullscreen boolean])
This commit is contained in:
@@ -344,7 +344,7 @@ page](https://github.com/junegunn/fzf/wiki/Examples-(vim)).
|
|||||||
|
|
||||||
#### `fzf#wrap`
|
#### `fzf#wrap`
|
||||||
|
|
||||||
`fzf#wrap(name string, [opts dict, [fullscreen boolean]])` is a helper
|
`fzf#wrap([name string,] [opts dict,] [fullscreen boolean])` is a helper
|
||||||
function that decorates the options dictionary so that it understands
|
function that decorates the options dictionary so that it understands
|
||||||
`g:fzf_layout`, `g:fzf_action`, and `g:fzf_history_dir` like `:FZF`.
|
`g:fzf_layout`, `g:fzf_action`, and `g:fzf_history_dir` like `:FZF`.
|
||||||
|
|
||||||
|
@@ -154,13 +154,20 @@ function! s:common_sink(action, lines) abort
|
|||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" name string, [opts dict, [fullscreen boolean]]
|
" [name string,] [opts dict,] [fullscreen boolean]
|
||||||
function! fzf#wrap(name, ...)
|
function! fzf#wrap(...)
|
||||||
if type(a:name) != type('')
|
let args = ['', {}, 0]
|
||||||
throw 'invalid name type: string expected'
|
let expects = map(copy(args), 'type(v:val)')
|
||||||
|
let tidx = 0
|
||||||
|
for arg in copy(a:000)
|
||||||
|
let tidx = index(expects, type(arg), tidx)
|
||||||
|
if tidx < 0
|
||||||
|
throw 'invalid arguments (expected: [name string] [opts dict] [fullscreen boolean])'
|
||||||
endif
|
endif
|
||||||
let opts = copy(get(a:000, 0, {}))
|
let args[tidx] = arg
|
||||||
let bang = get(a:000, 1, 0)
|
let tidx += 1
|
||||||
|
endfor
|
||||||
|
let [name, opts, bang] = args
|
||||||
|
|
||||||
" Layout: g:fzf_layout (and deprecated g:fzf_height)
|
" Layout: g:fzf_layout (and deprecated g:fzf_height)
|
||||||
if bang
|
if bang
|
||||||
@@ -179,12 +186,12 @@ function! fzf#wrap(name, ...)
|
|||||||
|
|
||||||
" History: g:fzf_history_dir
|
" History: g:fzf_history_dir
|
||||||
let opts.options = get(opts, 'options', '')
|
let opts.options = get(opts, 'options', '')
|
||||||
if len(get(g:, 'fzf_history_dir', ''))
|
if len(name) && len(get(g:, 'fzf_history_dir', ''))
|
||||||
let dir = expand(g:fzf_history_dir)
|
let dir = expand(g:fzf_history_dir)
|
||||||
if !isdirectory(dir)
|
if !isdirectory(dir)
|
||||||
call mkdir(dir, 'p')
|
call mkdir(dir, 'p')
|
||||||
endif
|
endif
|
||||||
let opts.options = join(['--history', s:escape(dir.'/'.a:name), opts.options])
|
let opts.options = join(['--history', s:escape(dir.'/'.name), opts.options])
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Action: g:fzf_action
|
" Action: g:fzf_action
|
||||||
|
Reference in New Issue
Block a user