Allow extensions to disable sorting

Close #170
This commit is contained in:
Kien N 2012-03-31 01:58:51 +07:00
parent e461712daf
commit 8b5bb1a6dd
4 changed files with 31 additions and 9 deletions

View File

@ -389,21 +389,22 @@ fu! s:Render(lines, pat, ipt)
sil! exe '%d _ | res' s:height sil! exe '%d _ | res' s:height
" Print the new items " Print the new items
if empty(lines) if empty(lines)
let s:matched = [] let [s:matched, s:lines] = [[], []]
cal setline(1, ' == NO ENTRIES ==') cal setline(1, ' == NO ENTRIES ==')
setl noma nocul setl noma nocul
cal s:unmarksigns() cal s:unmarksigns()
if s:dohighlight() | cal clearmatches() | en if s:dohighlight() | cal clearmatches() | en
retu retu
en en
if ( ( s:itemtype != 2 && !exists('g:ctrlp_nolimit') ) " Sorting
\ || s:prompt != ['', '', ''] ) && s:matcher == {} if s:dosort()
let s:compat = a:pat let s:compat = a: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
let s:matched = copy(lines) let s:matched = copy(lines)
if s:mwreverse | cal reverse(lines) | en
let s:lines = copy(lines)
cal map(lines, 's:formatline(v:val, a:ipt)') cal map(lines, 's:formatline(v:val, a:ipt)')
cal setline(1, lines) cal setline(1, lines)
setl noma cul setl noma cul
@ -518,16 +519,20 @@ endf
fu! s:PrtInsert(type) fu! s:PrtInsert(type)
unl! s:hstgot unl! s:hstgot
let s:act_add = 1
let s:prompt[0] .= a:type == 'w' ? s:crword let s:prompt[0] .= a:type == 'w' ? s:crword
\ : a:type == 's' ? getreg('/') \ : a:type == 's' ? getreg('/')
\ : a:type == 'v' ? s:crvisual \ : a:type == 'v' ? s:crvisual
\ : a:type == '+' ? substitute(getreg('+'), '\n', '\\n', 'g') : s:prompt[0] \ : a:type == '+' ? substitute(getreg('+'), '\n', '\\n', 'g') : s:prompt[0]
cal s:BuildPrompt(1) cal s:BuildPrompt(1)
unl s:act_add
endf endf
fu! s:PrtExpandDir() fu! s:PrtExpandDir()
let prt = s:prompt let prt = s:prompt
if prt[0] == '' | retu | en if prt[0] == '' | retu | en
unl! s:hstgot
let s:act_add = 1
let [base, seed] = s:headntail(prt[0]) let [base, seed] = s:headntail(prt[0])
let dirs = s:dircompl(base, seed) let dirs = s:dircompl(base, seed)
if len(dirs) == 1 if len(dirs) == 1
@ -536,6 +541,7 @@ fu! s:PrtExpandDir()
let prt[0] .= s:findcommon(dirs, prt[0]) let prt[0] .= s:findcommon(dirs, prt[0])
en en
cal s:BuildPrompt(1) cal s:BuildPrompt(1)
unl s:act_add
endf endf
" Movement {{{2 " Movement {{{2
fu! s:PrtCurLeft() fu! s:PrtCurLeft()
@ -574,7 +580,7 @@ fu! s:PrtSelectMove(dir)
endf endf
fu! s:PrtSelectJump(char, ...) fu! s:PrtSelectJump(char, ...)
let lines = copy(s:matched) let lines = copy(s:lines)
if a:0 if a:0
cal map(lines, 'split(v:val, ''[\/]\ze[^\/]\+$'')[-1]') cal map(lines, 'split(v:val, ''[\/]\ze[^\/]\+$'')[-1]')
en en
@ -816,7 +822,7 @@ fu! s:AcceptSelection(mode)
let str = join(s:prompt, '') let str = join(s:prompt, '')
if a:mode == 'e' | if s:SpecInputs(str) | retu | en | en if a:mode == 'e' | if s:SpecInputs(str) | retu | en | en
" Get the selected line " Get the selected line
let line = !empty(s:matched) ? s:matched[line('.') - 1] : '' let line = !empty(s:lines) ? s:lines[line('.') - 1] : ''
if a:mode != 'e' && s:itemtype < 3 && line == '' if a:mode != 'e' && s:itemtype < 3 && line == ''
\ && str !~ '\v^(\.\.|/|\\|\?)$' \ && str !~ '\v^(\.\.|/|\\|\?)$'
cal s:CreateNewFile(a:mode) | retu cal s:CreateNewFile(a:mode) | retu
@ -864,7 +870,7 @@ fu! s:MarkToOpen()
if s:bufnr <= 0 || s:opmul == '0' || ( s:itemtype > 2 && s:type() !~ 'rts' ) if s:bufnr <= 0 || s:opmul == '0' || ( s:itemtype > 2 && s:type() !~ 'rts' )
retu retu
en en
let line = !empty(s:matched) ? s:matched[line('.') - 1] : '' let line = !empty(s:lines) ? s:lines[line('.') - 1] : ''
if empty(line) | retu | en if empty(line) | retu | en
let filpath = fnamemodify(line, ':p') let filpath = fnamemodify(line, ':p')
if exists('s:marked') && s:dictindex(s:marked, filpath) > 0 if exists('s:marked') && s:dictindex(s:marked, filpath) > 0
@ -1272,8 +1278,8 @@ endf
fu! s:remarksigns() fu! s:remarksigns()
if !s:dosigns() | retu | en if !s:dosigns() | retu | en
for ic in range(1, len(s:matched)) for ic in range(1, len(s:lines))
let key = s:dictindex(s:marked, fnamemodify(s:matched[ic - 1], ':p')) let key = s:dictindex(s:marked, fnamemodify(s:lines[ic - 1], ':p'))
if key > 0 if key > 0
exe 'sign place' key 'line='.ic.' name=ctrlpmark buffer='.s:bufnr exe 'sign place' key 'line='.ic.' name=ctrlpmark buffer='.s:bufnr
en en
@ -1386,6 +1392,11 @@ fu! s:argmaps(md, ...)
retu a:md retu a:md
endf endf
" Misc {{{2 " Misc {{{2
fu! s:dosort()
retu s:matcher == {} && ( ( s:itemtype != 2 && !exists('g:ctrlp_nolimit') )
\ || s:prompt != ['', '', ''] ) && s:getextvar('sort')
endf
fu! s:narrowable() fu! s:narrowable()
retu exists('s:act_add') && exists('s:matched') && s:matched != [] retu exists('s:act_add') && exists('s:matched') && s:matched != []
\ && exists('s:mdata') && s:mdata[:2] == [s:dyncwd, s:itemtype, s:regexp] \ && exists('s:mdata') && s:mdata[:2] == [s:dyncwd, s:itemtype, s:regexp]
@ -1540,6 +1551,14 @@ fu! s:extvar(key)
en en
endf endf
fu! s:getextvar(key)
if s:itemtype > 2
let vars = g:ctrlp_ext_vars[s:itemtype - 3]
retu has_key(vars, a:key) ? vars[a:key] : -1
en
retu -1
endf
fu! ctrlp#exit() fu! ctrlp#exit()
cal s:PrtExit() cal s:PrtExit()
endf endf

View File

@ -17,6 +17,7 @@ let s:changes_var = {
\ 'sname': 'chs', \ 'sname': 'chs',
\ 'exit': 'ctrlp#changes#exit()', \ 'exit': 'ctrlp#changes#exit()',
\ 'type': 'tabe', \ 'type': 'tabe',
\ 'sort': 0,
\ } \ }
let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars) let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)

View File

@ -16,6 +16,7 @@ let s:var_qf = {
\ 'lname': 'quickfix', \ 'lname': 'quickfix',
\ 'sname': 'qfx', \ 'sname': 'qfx',
\ 'type': 'line', \ 'type': 'line',
\ 'sort': 0,
\ } \ }
let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars) let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)

View File

@ -18,6 +18,7 @@ let s:undo_var = {
\ 'enter': 'ctrlp#undo#enter()', \ 'enter': 'ctrlp#undo#enter()',
\ 'exit': 'ctrlp#undo#exit()', \ 'exit': 'ctrlp#undo#exit()',
\ 'type': 'line', \ 'type': 'line',
\ 'sort': 0,
\ } \ }
let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars) let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)