Tweak MRE buffer sorting

This commit is contained in:
Kien N 2012-04-19 10:59:56 +07:00
parent 75ef943c35
commit c747af3ae6
2 changed files with 15 additions and 21 deletions

View File

@ -320,8 +320,8 @@ fu! s:lsCmd()
endf endf
" - Buffers {{{1 " - Buffers {{{1
fu! ctrlp#buffers(...) fu! ctrlp#buffers(...)
let ids = filter(range(1, bufnr('$')), 'empty(getbufvar(v:val, "&bt"))' let ids = sort(filter(range(1, bufnr('$')), 'empty(getbufvar(v:val, "&bt"))'
\ .' && getbufvar(v:val, "&bl") && strlen(bufname(v:val))') \ .' && getbufvar(v:val, "&bl") && strlen(bufname(v:val))'), 's:compmreb')
retu a:0 && a:1 == 'id' ? ids : map(ids, 'fnamemodify(bufname(v:val), ":.")') retu a:0 && a:1 == 'id' ? ids : map(ids, 'fnamemodify(bufname(v:val), ":.")')
endf endf
" * MatchedItems() {{{1 " * MatchedItems() {{{1
@ -394,7 +394,7 @@ fu! s:Render(lines, pat)
retu retu
en en
" Sorting " Sorting
if s:dosort() if !s:nosort()
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
@ -958,19 +958,14 @@ fu! s:comptime(...)
endf endf
fu! s:compmreb(...) fu! s:compmreb(...)
" By last entered time (buffer) " By last entered time (bufnr)
if !exists('s:mrbs') let [id1, id2] = [index(s:mrbs, a:1), index(s:mrbs, a:2)]
let s:mrbs = ctrlp#mrufiles#bufs()
en
let id1 = index(s:mrbs, fnamemodify(a:1, ':p'))
let id2 = index(s:mrbs, fnamemodify(a:2, ':p'))
retu id1 == id2 ? 0 : id1 > id2 ? 1 : -1 retu id1 == id2 ? 0 : id1 > id2 ? 1 : -1
endf endf
fu! s:compmref(...) fu! s:compmref(...)
" By last entered time (MRU) " By last entered time (MRU)
let id1 = index(g:ctrlp_lines, a:1) let [id1, id2] = [index(g:ctrlp_lines, a:1), index(g:ctrlp_lines, a:2)]
let id2 = index(g:ctrlp_lines, a:2)
retu id1 == id2 ? 0 : id1 > id2 ? 1 : -1 retu id1 == id2 ? 0 : id1 > id2 ? 1 : -1
endf endf
@ -1013,14 +1008,13 @@ endf
fu! s:mixedsort(...) 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 && s:height < 51 if s:ispath
let ms = [] let ms = []
if s:height < 21 if s:height < 21
if s:itemtype !~ '\v^(1|2)$' | let ms += [s:comptime(a:1, a:2)] | en if s:itemtype !~ '\v^(1|2)$' | let ms += [s:comptime(a:1, a:2)] | en
let ms += [s:compfnlen(a:1, a:2), s:comparent(a:1, a:2)] let ms += [s:compfnlen(a:1, a:2), s:comparent(a:1, a:2)]
en en
let time = s:itemtype == 1 ? [s:compmreb(a:1, a:2)] let time = s:itemtype =~ '\v^(1|2)$' ? [s:compmref(a:1, a:2)] : []
\ : s:itemtype == 2 ? [s:compmref(a:1, a:2)] : []
let ms += time + [cml] + [0, 0, 0, 0] let ms += time + [cml] + [0, 0, 0, 0]
let mp = call('s:multipliers', ms[:3]) let mp = call('s:multipliers', ms[:3])
retu cln + ms[0] * mp[0] + ms[1] * mp[1] + ms[2] * mp[2] + ms[3] * mp[3] retu cln + ms[0] * mp[0] + ms[1] * mp[1] + ms[2] * mp[2] + ms[3] * mp[3]
@ -1422,10 +1416,9 @@ fu! s:modevar()
let s:dosort = s:getextvar('sort') let s:dosort = s:getextvar('sort')
endf endf
fu! s:dosort() fu! s:nosort()
retu s:matcher == {} && ( ( s:itemtype != 2 && s:nolim != 1 ) retu s:matcher != {} || s:nolim == 1 || s:prompt == ['', '', ''] || !s:dosort
\ || s:prompt != ['', '', ''] ) && !( s:itemtype == 2 && s:mrudef ) \ || ( s:itemtype == 2 && s:mrudef )
\ && s:dosort
endf endf
fu! s:narrowable() fu! s:narrowable()
@ -1503,6 +1496,7 @@ fu! s:getenv()
let s:currwin = s:mwbottom ? winnr() : winnr() + has('autocmd') let s:currwin = s:mwbottom ? winnr() : winnr() + has('autocmd')
let s:wpmode = exists('b:ctrlp_working_path_mode') let s:wpmode = exists('b:ctrlp_working_path_mode')
\ ? b:ctrlp_working_path_mode : s:pathmode \ ? b:ctrlp_working_path_mode : s:pathmode
let s:mrbs = ctrlp#mrufiles#bufs()
endf endf
fu! s:lastvisual() fu! s:lastvisual()

View File

@ -53,8 +53,8 @@ fu! s:record(bufnr)
if empty(bufname) | retu | en if empty(bufname) | retu | en
let fn = fnamemodify(bufname, ':p') let fn = fnamemodify(bufname, ':p')
let fn = exists('+ssl') ? tr(fn, '/', '\') : fn let fn = exists('+ssl') ? tr(fn, '/', '\') : fn
cal filter(s:mrbs, 'v:val !='.s:csen.' fn') cal filter(s:mrbs, 'v:val != bufnr')
cal insert(s:mrbs, fn) cal insert(s:mrbs, bufnr)
if ( !empty(s:in) && fn !~# s:in ) || ( !empty(s:ex) && fn =~# s:ex ) if ( !empty(s:in) && fn !~# s:in ) || ( !empty(s:ex) && fn =~# s:ex )
\ || !empty(&bt) || !filereadable(fn) | retu \ || !empty(&bt) || !filereadable(fn) | retu
en en
@ -108,7 +108,7 @@ fu! ctrlp#mrufiles#init()
let s:locked = 0 let s:locked = 0
aug CtrlPMRUF aug CtrlPMRUF
au! au!
au BufAdd,BufEnter,BufUnload * cal s:record(expand('<abuf>', 1)) au BufAdd,BufEnter,BufLeave,BufUnload * cal s:record(expand('<abuf>', 1))
au QuickFixCmdPre *vimgrep* let s:locked = 1 au QuickFixCmdPre *vimgrep* let s:locked = 1
au QuickFixCmdPost *vimgrep* let s:locked = 0 au QuickFixCmdPost *vimgrep* let s:locked = 0
au VimLeavePre * cal s:savetofile(s:mergelists()) au VimLeavePre * cal s:savetofile(s:mergelists())