From 865368d4641068cb23588334a313e45632896440 Mon Sep 17 00:00:00 2001 From: Kien N Date: Fri, 26 Oct 2012 12:27:02 +0700 Subject: [PATCH] Combine the match_window options and allow more flexibility. Closes #306 --- autoload/ctrlp.vim | 59 ++++++++++++++++++++++++++++++++++++---------- doc/ctrlp.txt | 38 +++++++++++++++++------------ 2 files changed, 69 insertions(+), 28 deletions(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 830bf4f..40e9991 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -68,6 +68,7 @@ let [s:pref, s:bpref, s:opts, s:new_opts, s:lc_opts] = \ 'key_loop': ['s:keyloop', 0], \ 'lazy_update': ['s:lazy', 0], \ 'match_func': ['s:matcher', {}], + \ 'match_window': ['s:mw', ''], \ 'match_window_bottom': ['s:mwbottom', 1], \ 'match_window_reversed': ['s:mwreverse', 1], \ 'max_depth': ['s:maxdepth', 40], @@ -181,7 +182,7 @@ let s:hlgrps = { \ 'PrtText': 'Normal', \ 'PrtCursor': 'Constant', \ } -" s:opts() {{{2 +" Get the options {{{2 fu! s:opts(...) unl! s:usrign s:usrcmd s:urprtmaps for each in ['byfname', 'regexp', 'extensions'] | if exists('s:'.each) @@ -201,6 +202,9 @@ fu! s:opts(...) let {va} = {s:bpref.ke} en endfo + " Match window options + cal s:match_window_opts() + " One-time values if a:0 && a:1 != {} unl va for [ke, va] in items(a:1) @@ -217,7 +221,6 @@ fu! s:opts(...) en | endfo if !exists('g:ctrlp_newcache') | let g:ctrlp_newcache = 0 | en let s:maxdepth = min([s:maxdepth, 100]) - let s:mxheight = max([s:mxheight, 1]) let s:glob = s:showhidden ? '.*\|*' : '*' let s:igntype = empty(s:usrign) ? -1 : type(s:usrign) let s:lash = ctrlp#utils#lash() @@ -238,13 +241,32 @@ fu! s:opts(...) cal extend(s:prtmaps, s:urprtmaps) en endf + +fu! s:match_window_opts() + let s:mw_pos = + \ s:mw =~ 'top\|bottom' ? matchstr(s:mw, 'top\|bottom') : + \ exists('g:ctrlp_match_window_bottom') ? ( s:mwbottom ? 'bottom' : 'top' ) + \ : 'bottom' + let s:mw_order = + \ s:mw =~ 'order:[^,]\+' ? matchstr(s:mw, 'order:\zs[^,]\+') : + \ exists('g:ctrlp_match_window_reversed') ? ( s:mwreverse ? 'btt' : 'ttb' ) + \ : 'btt' + let s:mw_max = + \ s:mw =~ 'max:[^,]\+' ? str2nr(matchstr(s:mw, 'max:\zs\d\+')) : + \ exists('g:ctrlp_max_height') ? s:mxheight + \ : 10 + let s:mw_min = + \ s:mw =~ 'min:[^,]\+' ? str2nr(matchstr(s:mw, 'min:\zs\d\+')) : 1 + let [s:mw_max, s:mw_min] = [max([s:mw_max, 1]), max([s:mw_min, 1])] + let s:mw_min = min([s:mw_min, s:mw_max]) +endf "}}}1 " * Open & Close {{{1 fu! s:Open() cal s:log(1) cal s:getenv() cal s:execextvar('enter') - sil! exe 'keepa' ( s:mwbottom ? 'bo' : 'to' ) '1new ControlP' + sil! exe 'keepa' ( s:mw_pos == 'top' ? 'to' : 'bo' ) '1new ControlP' cal s:buffunc(1) let [s:bufnr, s:winw] = [bufnr('%'), winwidth(0)] let [s:focus, s:prompt] = [1, ['', '', '']] @@ -494,15 +516,19 @@ fu! s:SplitPattern(str) endf " * BuildPrompt() {{{1 fu! s:Render(lines, pat) - let [&ma, lines, s:height] = [1, a:lines, min([len(a:lines), s:winh])] + let [&ma, lines, s:res_count] = [1, a:lines, len(a:lines)] + let height = min([max([s:mw_min, s:res_count]), s:winmaxh]) let pat = s:byfname ? split(a:pat, '^[^;]\+\\\@ 0 ? ( repeat([''], s:offset) + a:lines ) : a:lines +endf " Directory completion {{{3 fu! s:dircompl(be, sd) if a:sd == '' | retu [] | en @@ -1914,7 +1945,7 @@ fu! s:getenv() let [s:cwd, s:winres] = [getcwd(), [winrestcmd(), &lines, winnr('$')]] let [s:crword, s:crnbword] = [expand('', 1), expand('', 1)] let [s:crgfile, s:crline] = [expand('', 1), getline('.')] - let [s:winh, s:crcursor] = [min([s:mxheight, &lines]), getpos('.')] + let [s:winmaxh, s:crcursor] = [min([s:mw_max, &lines]), getpos('.')] let [s:crbufnr, s:crvisual] = [bufnr('%'), s:lastvisual()] let s:crfile = bufname('%') == '' \ ? '['.s:crbufnr.'*No Name]' : expand('%:p', 1) @@ -2100,7 +2131,9 @@ fu! s:getextvar(key) endf fu! ctrlp#getcline() - retu !empty(s:lines) ? s:lines[line('.') - 1] : '' + let [linenr, offset] = [line('.'), ( s:offset > 0 ? s:offset : 0 )] + retu !empty(s:lines) && !( offset && linenr <= offset ) + \ ? s:lines[linenr - 1 - offset] : '' endf fu! ctrlp#getmarkedlist() diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index cf3e23a..7e3ef91 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -40,9 +40,7 @@ Overview:~ |ctrlp_cmd|...................Default command used for the default mapping. |ctrlp_by_filename|...........Default to filename mode or not. |ctrlp_regexp|................Default to regexp mode or not. - |ctrlp_match_window_bottom|...Where to show the match window. - |ctrlp_match_window_reversed|.Sort order in the match window. - |ctrlp_max_height|............Max height of the match window. + |ctrlp_match_window|..........Order, height and position of the match window. |ctrlp_switch_buffer|.........Jump to an open buffer if already opened. |ctrlp_reuse_window|..........Reuse special windows (help, quickfix, etc). |ctrlp_tabpage_position|......Where to put the new tab page. @@ -114,21 +112,27 @@ Set this to 1 to set regexp search as the default: > < Can be toggled on/off by pressing inside the prompt. - *'g:ctrlp_match_window_bottom'* -Set this to 0 to show the match window at the top of the screen: > - let g:ctrlp_match_window_bottom = 1 + *'g:ctrlp_match_window'* +Change the postion, the listing order of results, the minimum and the maximum +heights of the match window: > + let g:ctrlp_match_window = '' < +Example: > + let g:ctrlp_match_window = 'bottom,order:btt,min:1,max:10' +< +The position: (default: bottom) + top - show the match window at the top of the screen. + bottom - show the match window at the bottom of the screen. - *'g:ctrlp_match_window_reversed'* -Change the listing order of the files in the match window. The default setting -(1) is from bottom to top: > - let g:ctrlp_match_window_reversed = 1 -< +The listing order of results: (default: btt) + order:ttb - from top to bottom. + order:btt - from bottom to top. - *'g:ctrlp_max_height'* -Set the maximum height of the match window: > - let g:ctrlp_max_height = 10 -< +The minimum and maximum heights: + min:{n} - show minimum {n} lines (default: 1). + max:{n} - show maximum {n} lines (default: 10). + +Note: When a setting isn't set, its default value will be used. *'g:ctrlp_switch_buffer'* When opening a file, if it's already open in a window somewhere, CtrlP will try @@ -1253,6 +1257,10 @@ Special thanks:~ =============================================================================== CHANGELOG *ctrlp-changelog* + + Combine *g:ctrlp_match_window_bottom* *g:ctrlp_match_window_reversed* and + *g:ctrlp_max_height* into |g:ctrlp_match_window|. + + New option: |g:ctrlp_match_window|. + Before 2012/11/30~ + New options: |g:ctrlp_abbrev|,