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