[vim] Add 'exit' callback
Before adoption: this commit came in with the history the project adopted, so no landing records it.
A spec can have `exit` callback that is called with the exit status of fzf. This can be used to clean up temporary resources or restore the original state when fzf is closed without a selection.
authored by Junegunn Choi · committed by Junegunn Choi · parent 5cce17e · Browse files · 4 files·+15 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+15 added−15 removed
- other:+15 added−15 removed
Provenance
- Commit
8cb59e6- Tree
187f1d5- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
5cce17e
4 files changed+15 added−15 removed
modified:doc/fzf.txt+2 added-1 removed
304 unmodified lines305 ---------------------------+---------------+----------------------------------------------------------------------306 `source` | string | External command to generate input to fzf (e.g. `find .` )307 `source` | list | Vim list as input to fzf308 `sink` | string | Vim command to handle the selected item (e.g. `e` , `tabe` )309- `sink` | funcref | Reference to function to process each selected item309+ `sink` | funcref | Function to be called with each selected item310 `sinklist` (or `sink*` ) | funcref | Similar to `sink` , but takes the list of output lines at once311+ `exit` | funcref | Function to be called with the exit status of fzf (e.g. 0, 1, 2, 130)312 `options` | string/list | Options to fzf313 `dir` | string | Working directory314 `up` / `down` / `left` / `right` | number/string | (Layout) Window position and size (e.g. `20` , `50%` )315 `tmux` | string | (Layout) `--tmux` options (e.g. `90%,70%` )194 unmodified linesmodified:plugin/fzf.vim+9 added-13 removed
663 unmodified lines664 else665 let s:launcher = function('s:xterm_launcher')666 endif667 668-function! s:exit_handler(code, command, ...)669- if a:code == 130670- return 0671- elseif has('nvim') && a:code == 129672- " When deleting the terminal buffer while fzf is still running,673- " Nvim sends SIGHUP.674- return 0675- elseif a:code > 1668+function! s:exit_handler(dict, code, command, ...)669+ if has_key(a:dict, 'exit')670+ call a:dict.exit(a:code)671+ endif672+ if a:code == 2673 call s:error('Error running ' . a:command)674 if !empty(a:000)675 sleep676 endif680- return 0677 endif682- return 1678+ return a:code679 endfunction680 681 function! s:execute(dict, command, use_height, temps) abort682 call s:pushd(a:dict)43 unmodified lines726 endif727 let exit_status = v:shell_error728 redraw!729 let lines = s:collect(a:temps)734- return s:exit_handler(exit_status, command) ? lines : []730+ return s:exit_handler(a:dict, exit_status, command) == 0 ? lines : []731 endfunction732 733 function! s:execute_tmux(dict, command, temps) abort734 let command = a:command6 unmodified lines741 call system(command)742 let exit_status = v:shell_error743 redraw!744 let lines = s:collect(a:temps)749- return s:exit_handler(exit_status, command) ? lines : []745+ return s:exit_handler(a:dict, exit_status, command) == 0 ? lines : []746 endfunction747 748 function! s:calc_size(max, val, dict)749 let val = substitute(a:val, '^\~', '', '')157 unmodified lines907 execute self.winrest908 endif909 910 let lines = s:collect(self.temps)915- if !s:exit_handler(a:code, self.command, 1)911+ if s:exit_handler(self.dict, a:code, self.command, 1) != 0912 return913 endif914 915 call s:pushd(self.dict)183 unmodified linesmodified:CHANGELOG.md+2 added
21 unmodified lines22 printf '<< \e]8;;http://github.com/junegunn/fzf\e\\Link to \e[32mfz\e[0mf\e]8;;\e\\ >>' | fzf --ansi23 24 fzf --preview "printf '<< \e]8;;http://github.com/junegunn/fzf\e\\Link to \e[32mfz\e[0mf\e]8;;\e\\ >>'"25 ```26+- [vim] A spec can have `exit` callback that is called with the exit status of fzf27+ - This can be used to clean up temporary resources or restore the original state when fzf is closed without a selection28 - Fixed `--tmux bottom` when the status line is not at the bottom29 - Fixed extra scroll offset in multi-line mode (`--read0` or `--wrap`)30 - Added fallback `ps` command for `kill` completion on Cygwin31 2240 unmodified linesmodified:README-VIM.md+2 added-1 removed
287 unmodified lines288 | -------------------------- | ------------- | ---------------------------------------------------------------- |289 | `source` | string | External command to generate input to fzf (e.g. `find .`) |290 | `source` | list | Vim list as input to fzf |291 | `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) |292-| `sink` | funcref | Reference to function to process each selected item |292+| `sink` | funcref | Function to be called with each selected item |293 | `sinklist` (or `sink*`) | funcref | Similar to `sink`, but takes the list of output lines at once |294+| `exit` | funcref | Function to be called with the exit status of fzf (e.g. 0, 1, 2, 130) |295 | `options` | string/list | Options to fzf |296 | `dir` | string | Working directory |297 | `up`/`down`/`left`/`right` | number/string | (Layout) Window position and size (e.g. `20`, `50%`) |298 | `tmux` | string | (Layout) `--tmux` options (e.g. `90%,70%`) |197 unmodified lines