Combine the match_window options and allow more flexibility.

Closes #306
This commit is contained in:
Kien N 2012-10-26 12:27:02 +07:00
parent 4815dc9ada
commit 865368d464
2 changed files with 69 additions and 28 deletions

View File

@ -68,6 +68,7 @@ let [s:pref, s:bpref, s:opts, s:new_opts, s:lc_opts] =
\ 'key_loop': ['s:keyloop', 0], \ 'key_loop': ['s:keyloop', 0],
\ 'lazy_update': ['s:lazy', 0], \ 'lazy_update': ['s:lazy', 0],
\ 'match_func': ['s:matcher', {}], \ 'match_func': ['s:matcher', {}],
\ 'match_window': ['s:mw', ''],
\ 'match_window_bottom': ['s:mwbottom', 1], \ 'match_window_bottom': ['s:mwbottom', 1],
\ 'match_window_reversed': ['s:mwreverse', 1], \ 'match_window_reversed': ['s:mwreverse', 1],
\ 'max_depth': ['s:maxdepth', 40], \ 'max_depth': ['s:maxdepth', 40],
@ -181,7 +182,7 @@ let s:hlgrps = {
\ 'PrtText': 'Normal', \ 'PrtText': 'Normal',
\ 'PrtCursor': 'Constant', \ 'PrtCursor': 'Constant',
\ } \ }
" s:opts() {{{2 " Get the options {{{2
fu! s:opts(...) fu! s:opts(...)
unl! s:usrign s:usrcmd s:urprtmaps unl! s:usrign s:usrcmd s:urprtmaps
for each in ['byfname', 'regexp', 'extensions'] | if exists('s:'.each) for each in ['byfname', 'regexp', 'extensions'] | if exists('s:'.each)
@ -201,6 +202,9 @@ fu! s:opts(...)
let {va} = {s:bpref.ke} let {va} = {s:bpref.ke}
en en
endfo endfo
" Match window options
cal s:match_window_opts()
" One-time values
if a:0 && a:1 != {} if a:0 && a:1 != {}
unl va unl va
for [ke, va] in items(a:1) for [ke, va] in items(a:1)
@ -217,7 +221,6 @@ fu! s:opts(...)
en | endfo en | endfo
if !exists('g:ctrlp_newcache') | let g:ctrlp_newcache = 0 | en if !exists('g:ctrlp_newcache') | let g:ctrlp_newcache = 0 | en
let s:maxdepth = min([s:maxdepth, 100]) let s:maxdepth = min([s:maxdepth, 100])
let s:mxheight = max([s:mxheight, 1])
let s:glob = s:showhidden ? '.*\|*' : '*' let s:glob = s:showhidden ? '.*\|*' : '*'
let s:igntype = empty(s:usrign) ? -1 : type(s:usrign) let s:igntype = empty(s:usrign) ? -1 : type(s:usrign)
let s:lash = ctrlp#utils#lash() let s:lash = ctrlp#utils#lash()
@ -238,13 +241,32 @@ fu! s:opts(...)
cal extend(s:prtmaps, s:urprtmaps) cal extend(s:prtmaps, s:urprtmaps)
en en
endf 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 "}}}1
" * Open & Close {{{1 " * Open & Close {{{1
fu! s:Open() fu! s:Open()
cal s:log(1) cal s:log(1)
cal s:getenv() cal s:getenv()
cal s:execextvar('enter') 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) cal s:buffunc(1)
let [s:bufnr, s:winw] = [bufnr('%'), winwidth(0)] let [s:bufnr, s:winw] = [bufnr('%'), winwidth(0)]
let [s:focus, s:prompt] = [1, ['', '', '']] let [s:focus, s:prompt] = [1, ['', '', '']]
@ -494,15 +516,19 @@ fu! s:SplitPattern(str)
endf endf
" * BuildPrompt() {{{1 " * BuildPrompt() {{{1
fu! s:Render(lines, pat) 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, '^[^;]\+\\\@<!\zs;', 1)[0] : a:pat let pat = s:byfname ? split(a:pat, '^[^;]\+\\\@<!\zs;', 1)[0] : a:pat
let cur_cmd = 'keepj norm! '.( s:mw_order == 'btt' ? 'G' : 'gg' ).'1|'
" Setup the match window " Setup the match window
sil! exe '%d _ | res' s:height sil! exe '%d _ | res' height
" Print the new items " Print the new items
if empty(lines) if empty(lines)
let [s:matched, s:lines] = [[], []] let [s:matched, s:lines] = [[], []]
cal setline(1, ' == NO ENTRIES ==') let lines = [' == NO ENTRIES ==']
cal setline(1, s:offset(lines, height - 1))
setl noma nocul setl noma nocul
exe cur_cmd
cal s:unmarksigns() cal s:unmarksigns()
if s:dohighlight() | cal clearmatches() | en if s:dohighlight() | cal clearmatches() | en
retu retu
@ -514,12 +540,12 @@ fu! s:Render(lines, pat)
cal sort(lines, 's:mixedsort') cal sort(lines, 's:mixedsort')
unl s:compat unl s:compat
en en
if s:mwreverse | cal reverse(lines) | en if s:mw_order == 'btt' | cal reverse(lines) | en
let s:lines = copy(lines) let s:lines = copy(lines)
cal map(lines, 's:formatline(v:val)') cal map(lines, 's:formatline(v:val)')
cal setline(1, lines) cal setline(1, s:offset(lines, height))
setl noma cul setl noma cul
exe 'keepj norm!' ( s:mwreverse ? 'G' : 'gg' ).'1|' exe cur_cmd
cal s:unmarksigns() cal s:unmarksigns()
cal s:remarksigns() cal s:remarksigns()
if exists('s:cline') && s:nolim != 1 if exists('s:cline') && s:nolim != 1
@ -541,7 +567,7 @@ fu! s:Update(str)
let s:martcs = &scs && str =~ '\u' ? '\C' : '' let s:martcs = &scs && str =~ '\u' ? '\C' : ''
let pat = s:matcher == {} ? s:SplitPattern(str) : str let pat = s:matcher == {} ? s:SplitPattern(str) : str
let lines = s:nolim == 1 && empty(str) ? copy(g:ctrlp_lines) let lines = s:nolim == 1 && empty(str) ? copy(g:ctrlp_lines)
\ : s:MatchedItems(g:ctrlp_lines, pat, s:winh) \ : s:MatchedItems(g:ctrlp_lines, pat, s:winmaxh)
cal s:Render(lines, pat) cal s:Render(lines, pat)
endf endf
@ -1276,7 +1302,7 @@ fu! s:mixedsort(...)
let [cln, cml] = [ctrlp#complen(a:1, a:2), s:compmatlen(a:1, a:2)] let [cln, cml] = [ctrlp#complen(a:1, a:2), s:compmatlen(a:1, a:2)]
if s:ispath if s:ispath
let ms = [] let ms = []
if s:height < 21 if s:res_count < 21
let ms += [s:compfnlen(a:1, a:2)] let ms += [s:compfnlen(a:1, a:2)]
if s:itemtype !~ '^[12]$' | let ms += [s:comptime(a:1, a:2)] | en if s:itemtype !~ '^[12]$' | let ms += [s:comptime(a:1, a:2)] | en
if !s:itemtype | let ms += [s:comparent(a:1, a:2)] | en if !s:itemtype | let ms += [s:comparent(a:1, a:2)] | en
@ -1374,6 +1400,11 @@ fu! s:pathshorten(str)
retu matchstr(a:str, '^.\{9}').'...' retu matchstr(a:str, '^.\{9}').'...'
\ .matchstr(a:str, '.\{'.( s:winw - 16 ).'}$') \ .matchstr(a:str, '.\{'.( s:winw - 16 ).'}$')
endf endf
fu! s:offset(lines, height)
let s:offset = s:mw_order == 'btt' ? ( a:height - s:res_count ) : 0
retu s:offset > 0 ? ( repeat([''], s:offset) + a:lines ) : a:lines
endf
" Directory completion {{{3 " Directory completion {{{3
fu! s:dircompl(be, sd) fu! s:dircompl(be, sd)
if a:sd == '' | retu [] | en if a:sd == '' | retu [] | en
@ -1914,7 +1945,7 @@ fu! s:getenv()
let [s:cwd, s:winres] = [getcwd(), [winrestcmd(), &lines, winnr('$')]] let [s:cwd, s:winres] = [getcwd(), [winrestcmd(), &lines, winnr('$')]]
let [s:crword, s:crnbword] = [expand('<cword>', 1), expand('<cWORD>', 1)] let [s:crword, s:crnbword] = [expand('<cword>', 1), expand('<cWORD>', 1)]
let [s:crgfile, s:crline] = [expand('<cfile>', 1), getline('.')] let [s:crgfile, s:crline] = [expand('<cfile>', 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:crbufnr, s:crvisual] = [bufnr('%'), s:lastvisual()]
let s:crfile = bufname('%') == '' let s:crfile = bufname('%') == ''
\ ? '['.s:crbufnr.'*No Name]' : expand('%:p', 1) \ ? '['.s:crbufnr.'*No Name]' : expand('%:p', 1)
@ -2100,7 +2131,9 @@ fu! s:getextvar(key)
endf endf
fu! ctrlp#getcline() 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 endf
fu! ctrlp#getmarkedlist() fu! ctrlp#getmarkedlist()

View File

@ -40,9 +40,7 @@ Overview:~
|ctrlp_cmd|...................Default command used for the default mapping. |ctrlp_cmd|...................Default command used for the default mapping.
|ctrlp_by_filename|...........Default to filename mode or not. |ctrlp_by_filename|...........Default to filename mode or not.
|ctrlp_regexp|................Default to regexp mode or not. |ctrlp_regexp|................Default to regexp mode or not.
|ctrlp_match_window_bottom|...Where to show the match window. |ctrlp_match_window|..........Order, height and position of the match window.
|ctrlp_match_window_reversed|.Sort order in the match window.
|ctrlp_max_height|............Max height of the match window.
|ctrlp_switch_buffer|.........Jump to an open buffer if already opened. |ctrlp_switch_buffer|.........Jump to an open buffer if already opened.
|ctrlp_reuse_window|..........Reuse special windows (help, quickfix, etc). |ctrlp_reuse_window|..........Reuse special windows (help, quickfix, etc).
|ctrlp_tabpage_position|......Where to put the new tab page. |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 <c-r> inside the prompt. Can be toggled on/off by pressing <c-r> inside the prompt.
*'g:ctrlp_match_window_bottom'* *'g:ctrlp_match_window'*
Set this to 0 to show the match window at the top of the screen: > Change the postion, the listing order of results, the minimum and the maximum
let g:ctrlp_match_window_bottom = 1 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'* The listing order of results: (default: btt)
Change the listing order of the files in the match window. The default setting order:ttb - from top to bottom.
(1) is from bottom to top: > order:btt - from bottom to top.
let g:ctrlp_match_window_reversed = 1
<
*'g:ctrlp_max_height'* The minimum and maximum heights:
Set the maximum height of the match window: > min:{n} - show minimum {n} lines (default: 1).
let g:ctrlp_max_height = 10 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'* *'g:ctrlp_switch_buffer'*
When opening a file, if it's already open in a window somewhere, CtrlP will try 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* 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~ Before 2012/11/30~
+ New options: |g:ctrlp_abbrev|, + New options: |g:ctrlp_abbrev|,