Skip to content

Commit

Permalink
Combine the match_window options and allow more flexibility.
Browse files Browse the repository at this point in the history
Closes #306
  • Loading branch information
kien committed Mar 29, 2013
1 parent 4815dc9 commit 865368d
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 28 deletions.
59 changes: 46 additions & 13 deletions autoload/ctrlp.vim
Expand Up @@ -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],
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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, ['', '', '']]
Expand Down Expand Up @@ -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, '^[^;]\+\\\@<!\zs;', 1)[0] : a:pat
let cur_cmd = 'keepj norm! '.( s:mw_order == 'btt' ? 'G' : 'gg' ).'1|'
" Setup the match window
sil! exe '%d _ | res' s:height
sil! exe '%d _ | res' height
" Print the new items
if empty(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
exe cur_cmd
cal s:unmarksigns()
if s:dohighlight() | cal clearmatches() | en
retu
Expand All @@ -514,12 +540,12 @@ fu! s:Render(lines, pat)
cal sort(lines, 's:mixedsort')
unl s:compat
en
if s:mwreverse | cal reverse(lines) | en
if s:mw_order == 'btt' | cal reverse(lines) | en
let s:lines = copy(lines)
cal map(lines, 's:formatline(v:val)')
cal setline(1, lines)
cal setline(1, s:offset(lines, height))
setl noma cul
exe 'keepj norm!' ( s:mwreverse ? 'G' : 'gg' ).'1|'
exe cur_cmd
cal s:unmarksigns()
cal s:remarksigns()
if exists('s:cline') && s:nolim != 1
Expand All @@ -541,7 +567,7 @@ fu! s:Update(str)
let s:martcs = &scs && str =~ '\u' ? '\C' : ''
let pat = s:matcher == {} ? s:SplitPattern(str) : str
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)
endf

Expand Down Expand Up @@ -1276,7 +1302,7 @@ fu! s:mixedsort(...)
let [cln, cml] = [ctrlp#complen(a:1, a:2), s:compmatlen(a:1, a:2)]
if s:ispath
let ms = []
if s:height < 21
if s:res_count < 21
let ms += [s:compfnlen(a:1, a:2)]
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
Expand Down Expand Up @@ -1374,6 +1400,11 @@ fu! s:pathshorten(str)
retu matchstr(a:str, '^.\{9}').'...'
\ .matchstr(a:str, '.\{'.( s:winw - 16 ).'}$')
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
fu! s:dircompl(be, sd)
if a:sd == '' | retu [] | en
Expand Down Expand Up @@ -1914,7 +1945,7 @@ fu! s:getenv()
let [s:cwd, s:winres] = [getcwd(), [winrestcmd(), &lines, winnr('$')]]
let [s:crword, s:crnbword] = [expand('<cword>', 1), expand('<cWORD>', 1)]
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:crfile = bufname('%') == ''
\ ? '['.s:crbufnr.'*No Name]' : expand('%:p', 1)
Expand Down Expand Up @@ -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()
Expand Down
38 changes: 23 additions & 15 deletions doc/ctrlp.txt
Expand Up @@ -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.
Expand Down Expand Up @@ -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.

*'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 = ''
<

*'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
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_max_height'*
Set the maximum height of the match window: >
let g:ctrlp_max_height = 10
<
The listing order of results: (default: btt)
order:ttb - from top to bottom.
order:btt - from bottom to top.

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
Expand Down Expand Up @@ -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|,
Expand Down

0 comments on commit 865368d

Please sign in to comment.