From 707f5b6269337ea5c19fc4054cd2574939f817f5 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 27 Jan 2021 10:53:14 +0900 Subject: [PATCH] Make fzf#vim#preview process g:fzf_preview_window Related #1023 Related #1225 --- autoload/fzf/vim.vim | 14 ++++++++++++-- plugin/fzf.vim | 37 ++++++++++++------------------------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index 3eccb52..4d5952f 100644 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -138,9 +138,19 @@ function! fzf#vim#with_preview(...) " Placeholder expression (TODO/TBD: undocumented) let placeholder = get(spec, 'placeholder', '{}') - " Preview window + " g:fzf_preview_window + if empty(args) + let preview_args = get(g:, 'fzf_preview_window', ['right', 'ctrl-/']) + if empty(preview_args) + let args = ['hidden'] + else + " For backward-compatiblity + let args = type(preview_args) == type('') ? [preview_args] : copy(preview_args) + endif + endif + if len(args) && type(args[0]) == s:TYPE.string - if args[0] !~# '^\(up\|down\|left\|right\)' + if args[0] !~# '^\(up\|down\|left\|right\|hidden\)' throw 'invalid preview window: '.args[0] endif let window = args[0] diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 1e78354..9719538 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -44,42 +44,29 @@ function! s:defs(commands) endfor endfunction -function! s:p(...) - let preview_args = get(g:, 'fzf_preview_window', ['right', 'ctrl-/']) - if empty(preview_args) - return { 'options': ['--preview-window', 'hidden'] } - endif - - " For backward-compatiblity - if type(preview_args) == type('') - let preview_args = [preview_args] - endif - return call('fzf#vim#with_preview', extend(copy(a:000), preview_args)) -endfunction - call s:defs([ -\'command! -bang -nargs=? -complete=dir Files call fzf#vim#files(, s:p(), 0)', -\'command! -bang -nargs=? GitFiles call fzf#vim#gitfiles(, s:p( == "?" ? { "placeholder": "" } : {}), 0)', -\'command! -bang -nargs=? GFiles call fzf#vim#gitfiles(, s:p( == "?" ? { "placeholder": "" } : {}), 0)', -\'command! -bar -bang -nargs=? -complete=buffer Buffers call fzf#vim#buffers(, s:p({ "placeholder": "{1}" }), 0)', +\'command! -bang -nargs=? -complete=dir Files call fzf#vim#files(, fzf#vim#with_preview(), 0)', +\'command! -bang -nargs=? GitFiles call fzf#vim#gitfiles(, fzf#vim#with_preview( == "?" ? { "placeholder": "" } : {}), 0)', +\'command! -bang -nargs=? GFiles call fzf#vim#gitfiles(, fzf#vim#with_preview( == "?" ? { "placeholder": "" } : {}), 0)', +\'command! -bar -bang -nargs=? -complete=buffer Buffers call fzf#vim#buffers(, fzf#vim#with_preview({ "placeholder": "{1}" }), 0)', \'command! -bang -nargs=* Lines call fzf#vim#lines(, 0)', \'command! -bang -nargs=* BLines call fzf#vim#buffer_lines(, 0)', \'command! -bar -bang Colors call fzf#vim#colors(0)', -\'command! -bang -nargs=+ -complete=dir Locate call fzf#vim#locate(, s:p(), 0)', -\'command! -bang -nargs=* Ag call fzf#vim#ag(, s:p(), 0)', -\'command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case -- ".shellescape(), 1, s:p(), 0)', -\'command! -bang -nargs=* Tags call fzf#vim#tags(, s:p({ "placeholder": "--tag {2}:{-1}:{3}" }), 0)', -\'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(, s:p({ "placeholder": "{2}:{3}" }), 0)', +\'command! -bang -nargs=+ -complete=dir Locate call fzf#vim#locate(, fzf#vim#with_preview(), 0)', +\'command! -bang -nargs=* Ag call fzf#vim#ag(, fzf#vim#with_preview(), 0)', +\'command! -bang -nargs=* Rg call fzf#vim#grep("rg --column --line-number --no-heading --color=always --smart-case -- ".shellescape(), 1, fzf#vim#with_preview(), 0)', +\'command! -bang -nargs=* Tags call fzf#vim#tags(, fzf#vim#with_preview({ "placeholder": "--tag {2}:{-1}:{3}" }), 0)', +\'command! -bang -nargs=* BTags call fzf#vim#buffer_tags(, fzf#vim#with_preview({ "placeholder": "{2}:{3}" }), 0)', \'command! -bar -bang Snippets call fzf#vim#snippets(0)', \'command! -bar -bang Commands call fzf#vim#commands(0)', \'command! -bar -bang Marks call fzf#vim#marks(0)', \'command! -bar -bang Helptags call fzf#vim#helptags(0)', \'command! -bar -bang Windows call fzf#vim#windows(0)', -\'command! -bar -bang Commits call fzf#vim#commits(s:p({ "placeholder": "" }), 0)', -\'command! -bar -bang BCommits call fzf#vim#buffer_commits(s:p({ "placeholder": "" }), 0)', +\'command! -bar -bang Commits call fzf#vim#commits(fzf#vim#with_preview({ "placeholder": "" }), 0)', +\'command! -bar -bang BCommits call fzf#vim#buffer_commits(fzf#vim#with_preview({ "placeholder": "" }), 0)', \'command! -bar -bang Maps call fzf#vim#maps("n", 0)', \'command! -bar -bang Filetypes call fzf#vim#filetypes(0)', -\'command! -bang -nargs=* History call s:history(, s:p(), 0)']) +\'command! -bang -nargs=* History call s:history(, fzf#vim#with_preview(), 0)']) function! s:history(arg, extra, bang) let bang = a:bang || a:arg[len(a:arg)-1] == '!'