summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-08-28 18:38:47 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-08-28 18:38:47 +0900
commit698e8008df42d863af01a8da81f560f295f728ea (patch)
treebee30dbf99267839cb63963da8ced67d74ca39a9 /plugin
parent1de4cc3ba862ace3f78db395a2bd1dfa21e4798e (diff)
[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%' }
Diffstat (limited to 'plugin')
-rw-r--r--plugin/fzf.vim29
1 files changed, 24 insertions, 5 deletions
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
#n120'>120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163