From 698e8008df42d863af01a8da81f560f295f728ea Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Fri, 28 Aug 2015 18:38:47 +0900 Subject: [vim] Dynamic height specification for 'up' and 'down' options Values for 'up' and 'down' can be written with ~ prefix. Only applies when the source is a Vim list. e.g. { 'source': range(10), 'down': '~40%' } --- plugin/fzf.vim | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'plugin') diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 58e481f1..f0461b20 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -164,7 +164,13 @@ function! s:fzf_tmux(dict) let size = '' for o in ['up', 'down', 'left', 'right'] if s:present(a:dict, o) - let size = '-'.o[0].(a:dict[o] == 1 ? '' : a:dict[o]) + let spec = a:dict[o] + if (o == 'up' || o == 'down') && spec[0] == '~' + let size = '-'.o[0].s:calc_size(&lines, spec[1:], a:dict) + else + " Legacy boolean option + let size = '-'.o[0].(spec == 1 ? '' : spec) + endif break endif endfor @@ -244,12 +250,21 @@ function! s:execute_tmux(dict, command, temps) return s:callback(a:dict, a:temps) endfunction -function! s:calc_size(max, val) +function! s:calc_size(max, val, dict) if a:val =~ '%$' - return a:max * str2nr(a:val[:-2]) / 100 + let size = a:max * str2nr(a:val[:-2]) / 100 else - return min([a:max, a:val]) + let size = min([a:max, str2nr(a:val)]) + endif + + let srcsz = -1 + if type(get(a:dict, 'source', 0)) == type([]) + let srcsz = len(a:dict.source) endif + + let opts = get(a:dict, 'options', '').$FZF_DEFAULT_OPTS + let margin = stridx(opts, '--inline-info') > stridx(opts, '--no-inline-info') ? 1 : 2 + return srcsz >= 0 ? min([srcsz + margin, size]) : size endfunction function! s:getpos() @@ -268,7 +283,11 @@ function! s:split(dict) let val = get(a:dict, dir, '') if !empty(val) let [cmd, resz, max] = triple - let sz = s:calc_size(max, val) + if (dir == 'up' || dir == 'down') && val[0] == '~' + let sz = s:calc_size(max, val[1:], a:dict) + else + let sz = s:calc_size(max, val, {}) + endif execute cmd sz.'new' execute resz sz return -- cgit v1.2.3