mirror of
https://github.com/junegunn/fzf.vim.git
synced 2025-12-06 12:44:24 +08:00
Allow fzf#complete to take hash argument with sink
This allows us to use the return value of fzf#wrap function with fzf#complete. This commit also removes obsolete g:fzf#vim#default_layout and fzf#vim#layout.
This commit is contained in:
@@ -245,7 +245,7 @@ following exceptions:
|
||||
- Or a function to extract completion prefix
|
||||
- Both `source` and `options` can be given as funcrefs that take the
|
||||
completion prefix as the argument and return the final value
|
||||
- `sink` or `sink*` are not allowed
|
||||
- `sink` or `sink*` are ignored
|
||||
|
||||
#### Reducer example
|
||||
|
||||
|
||||
@@ -82,11 +82,6 @@ function! fzf#vim#wrap(opts)
|
||||
return fzf#wrap(a:opts)
|
||||
endfunction
|
||||
|
||||
" Deprecated
|
||||
function! fzf#vim#layout(...)
|
||||
return (a:0 && a:1) ? {} : copy(get(g:, 'fzf_layout', g:fzf#vim#default_layout))
|
||||
endfunction
|
||||
|
||||
function! s:wrap(name, opts, bang)
|
||||
" fzf#wrap does not append --expect if sink or sink* is found
|
||||
let opts = copy(a:opts)
|
||||
@@ -1164,16 +1159,20 @@ endfunction
|
||||
|
||||
function! fzf#vim#complete(...)
|
||||
if a:0 == 0
|
||||
let s:opts = g:fzf#vim#default_layout
|
||||
let s:opts = fzf#wrap()
|
||||
elseif type(a:1) == s:TYPE.dict
|
||||
if has_key(a:1, 'sink') || has_key(a:1, 'sink*')
|
||||
echoerr 'sink not allowed'
|
||||
let s:opts = copy(a:1)
|
||||
elseif type(a:1) == s:TYPE.string
|
||||
let s:opts = extend({'source': a:1}, get(a:000, 1, fzf#wrap()))
|
||||
else
|
||||
echoerr 'Invalid argument: '.string(a:000)
|
||||
return ''
|
||||
endif
|
||||
let s:opts = copy(a:1)
|
||||
else
|
||||
let s:opts = extend({'source': a:1}, g:fzf#vim#default_layout)
|
||||
for s in ['sink', 'sink*']
|
||||
if has_key(s:opts, s)
|
||||
call remove(s:opts, s)
|
||||
endif
|
||||
endfor
|
||||
|
||||
let eol = col('$')
|
||||
let ve = &ve
|
||||
@@ -1199,6 +1198,10 @@ function! fzf#vim#complete(...)
|
||||
let s:opts.options =
|
||||
\ join(filter([get(s:opts, 'options', ''), remove(s:opts, 'extra_options')], '!empty(v:val)'))
|
||||
endif
|
||||
if has_key(s:opts, 'options')
|
||||
" FIXME: fzf currently doesn't have --no-expect option
|
||||
let s:opts.options = substitute(s:opts.options, '--expect=[^ ]*', '', 'g')
|
||||
endif
|
||||
|
||||
call feedkeys("\<Plug>(-fzf-complete-trigger)")
|
||||
return ''
|
||||
|
||||
@@ -48,7 +48,7 @@ endif
|
||||
function! fzf#vim#complete#word(...)
|
||||
return fzf#vim#complete(s:extend({
|
||||
\ 'source': 'cat /usr/share/dict/words'},
|
||||
\ get(a:000, 0, g:fzf#vim#default_layout)))
|
||||
\ get(a:000, 0, fzf#wrap())))
|
||||
endfunction
|
||||
|
||||
" ----------------------------------------------------------------------------
|
||||
@@ -128,7 +128,7 @@ function! fzf#vim#complete#path(command, ...)
|
||||
return fzf#vim#complete(s:extend({
|
||||
\ 'prefix': s:function('s:fname_prefix'),
|
||||
\ 'source': s:function('s:file_source'),
|
||||
\ 'options': s:function('s:file_options')}, get(a:000, 0, g:fzf#vim#default_layout)))
|
||||
\ 'options': s:function('s:file_options')}, get(a:000, 0, fzf#wrap())))
|
||||
endfunction
|
||||
|
||||
" ----------------------------------------------------------------------------
|
||||
@@ -147,13 +147,13 @@ function! fzf#vim#complete#line(...)
|
||||
\ 'prefix': '^.*$',
|
||||
\ 'source': lines,
|
||||
\ 'options': '--tiebreak=index --ansi --nth '.nth.'.. --tabstop=1',
|
||||
\ 'reducer': s:function('s:reduce_line')}, get(a:000, 0, g:fzf#vim#default_layout)))
|
||||
\ 'reducer': s:function('s:reduce_line')}, get(a:000, 0, fzf#wrap())))
|
||||
endfunction
|
||||
|
||||
function! fzf#vim#complete#buffer_line(...)
|
||||
return fzf#vim#complete(s:extend({
|
||||
\ 'prefix': '^.*$',
|
||||
\ 'source': fzf#vim#_uniq(getline(1, '$'))}, get(a:000, 0, g:fzf#vim#default_layout)))
|
||||
\ 'source': fzf#vim#_uniq(getline(1, '$'))}, get(a:000, 0, fzf#wrap())))
|
||||
endfunction
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
|
||||
@@ -274,7 +274,7 @@ following exceptions:
|
||||
- Or a function to extract completion prefix
|
||||
- Both `source` and `options` can be given as funcrefs that take the completion
|
||||
prefix as the argument and return the final value
|
||||
- `sink` or `sink*` are not allowed
|
||||
- `sink` or `sink*` are ignored
|
||||
|
||||
|
||||
Reducer example~
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
let g:fzf#vim#default_layout = {'down': '~40%'}
|
||||
|
||||
function! s:defs(commands)
|
||||
let prefix = get(g:, 'fzf_command_prefix', '')
|
||||
if prefix =~# '^[^A-Z]'
|
||||
|
||||
Reference in New Issue
Block a user