[vim] Add 'sinklist' as a synonym to 'sink*'

So that it's easier to add a sinklist function to a spec dictionary.

  let spec = { 'source': source, 'options': ['--preview', preview] }
  function spec.sinklist(matches)
    echom string(a:matches)
  endfunction

  call fzf#run(fzf#wrap(spec))
This commit is contained in:
Junegunn Choi 2021-06-04 22:04:20 +09:00
parent e086f0b3fe
commit a74731d7f5
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
3 changed files with 8 additions and 6 deletions

View File

@ -283,7 +283,7 @@ The following table summarizes the available options.
| `source` | list | Vim list as input to fzf | | `source` | list | Vim list as input to fzf |
| `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) | | `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) |
| `sink` | funcref | Reference to function to process each selected item | | `sink` | funcref | Reference to function to process each selected item |
| `sink*` | funcref | Similar to `sink`, but takes the list of output lines at once | | `sinklist` (or `sink*`) | funcref | Similar to `sink`, but takes the list of output lines at once |
| `options` | string/list | Options to fzf | | `options` | string/list | Options to fzf |
| `dir` | string | Working directory | | `dir` | string | Working directory |
| `up`/`down`/`left`/`right` | number/string | (Layout) Window position and size (e.g. `20`, `50%`) | | `up`/`down`/`left`/`right` | number/string | (Layout) Window position and size (e.g. `20`, `50%`) |
@ -387,7 +387,7 @@ command! -bang -complete=dir -nargs=? LS
- `g:fzf_layout` - `g:fzf_layout`
- `g:fzf_action` - `g:fzf_action`
- **Works only when no custom `sink` (or `sink*`) is provided** - **Works only when no custom `sink` (or `sinklist`) is provided**
- Having custom sink usually means that each entry is not an ordinary - Having custom sink usually means that each entry is not an ordinary
file path (e.g. name of color scheme), so we can't blindly apply the file path (e.g. name of color scheme), so we can't blindly apply the
same strategy (i.e. `tabedit some-color-scheme` doesn't make sense) same strategy (i.e. `tabedit some-color-scheme` doesn't make sense)

View File

@ -300,7 +300,7 @@ The following table summarizes the available options.
`source` | list | Vim list as input to fzf `source` | list | Vim list as input to fzf
`sink` | string | Vim command to handle the selected item (e.g. `e` , `tabe` ) `sink` | string | Vim command to handle the selected item (e.g. `e` , `tabe` )
`sink` | funcref | Reference to function to process each selected item `sink` | funcref | Reference to function to process each selected item
`sink*` | funcref | Similar to `sink` , but takes the list of output lines at once `sinklist` (or `sink*` ) | funcref | Similar to `sink` , but takes the list of output lines at once
`options` | string/list | Options to fzf `options` | string/list | Options to fzf
`dir` | string | Working directory `dir` | string | Working directory
`up` / `down` / `left` / `right` | number/string | (Layout) Window position and size (e.g. `20` , `50%` ) `up` / `down` / `left` / `right` | number/string | (Layout) Window position and size (e.g. `20` , `50%` )

View File

@ -419,13 +419,13 @@ function! fzf#wrap(...)
endif endif
" Action: g:fzf_action " Action: g:fzf_action
if !s:has_any(opts, ['sink', 'sink*']) if !s:has_any(opts, ['sink', 'sinklist', 'sink*'])
let opts._action = get(g:, 'fzf_action', s:default_action) let opts._action = get(g:, 'fzf_action', s:default_action)
let opts.options .= ' --expect='.join(keys(opts._action), ',') let opts.options .= ' --expect='.join(keys(opts._action), ',')
function! opts.sink(lines) abort function! opts.sinklist(lines) abort
return s:common_sink(self._action, a:lines) return s:common_sink(self._action, a:lines)
endfunction endfunction
let opts['sink*'] = remove(opts, 'sink') let opts['sink*'] = opts.sinklist " For backward compatibility
endif endif
return opts return opts
@ -943,6 +943,8 @@ function! s:callback(dict, lines) abort
endif endif
if has_key(a:dict, 'sink*') if has_key(a:dict, 'sink*')
call a:dict['sink*'](a:lines) call a:dict['sink*'](a:lines)
elseif has_key(a:dict, 'sinklist')
call a:dict['sinklist'](a:lines)
endif endif
catch catch
if stridx(v:exception, ':E325:') < 0 if stridx(v:exception, ':E325:') < 0