Get a separate buffer list

This commit is contained in:
Kien N 2012-04-08 06:33:05 +07:00
parent f1dd272388
commit ba7c2048a2
4 changed files with 21 additions and 29 deletions

View File

@ -316,10 +316,10 @@ fu! s:lsCmd()
en en
endf endf
" - Buffers {{{1 " - Buffers {{{1
fu! ctrlp#buffers() fu! ctrlp#buffers(...)
retu map(filter(range(1, bufnr('$')), 'empty(getbufvar(v:val, "&bt"))' let ids = 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))')
\ 'fnamemodify(bufname(v:val), ":.")') retu a:0 && a:1 == 'id' ? ids : map(ids, 'fnamemodify(bufname(v:val), ":.")')
endf endf
" * MatchedItems() {{{1 " * MatchedItems() {{{1
fu! s:MatchIt(items, pat, limit, exc) fu! s:MatchIt(items, pat, limit, exc)

View File

@ -52,17 +52,14 @@ fu! s:syntax()
endf endf
" Public {{{1 " Public {{{1
fu! ctrlp#changes#init(original_bufnr, fname) fu! ctrlp#changes#init(original_bufnr, fname)
let fname = exists('s:bufname') ? s:bufname : a:fname let bufnr = exists('s:bufnr') ? s:bufnr : bufnr('^'.a:fname.'$')
let bufs = exists('s:clmode') && s:clmode let bufs = exists('s:clmode') && s:clmode ? ctrlp#buffers('id') : [bufnr]
\ ? filter(ctrlp#buffers(), 'filereadable(v:val)') : [fname] cal filter(bufs, 'v:val > 0')
let [swb, &swb] = [&swb, ''] let [swb, &swb] = [&swb, '']
let lines = [] let lines = []
for each in bufs for each in bufs
let [bname, fnamet] = [fnamemodify(each, ':p'), fnamemodify(each, ':t')] let fnamet = fnamemodify(bufname(each), ':t')
let bufnr = bufnr('^'.bname.'$') cal extend(lines, s:process(s:changelist(each), each, fnamet))
if bufnr > 0
cal extend(lines, s:process(s:changelist(bufnr), bufnr, fnamet))
en
endfo endfo
sil! exe 'noa hid b' a:original_bufnr sil! exe 'noa hid b' a:original_bufnr
let &swb = swb let &swb = swb
@ -85,13 +82,13 @@ endf
fu! ctrlp#changes#cmd(mode, ...) fu! ctrlp#changes#cmd(mode, ...)
let s:clmode = a:mode let s:clmode = a:mode
if a:0 && !empty(a:1) if a:0 && !empty(a:1)
let s:bufname = fnamemodify(a:1, ':p') let s:bufnr = bufnr('^'.fnamemodify(a:1, ':p').'$')
en en
retu s:id retu s:id
endf endf
fu! ctrlp#changes#exit() fu! ctrlp#changes#exit()
unl! s:clmode s:bufname unl! s:clmode s:bufnr
endf endf
"}}} "}}}

View File

@ -27,7 +27,7 @@ fu! s:newcache(cwd)
retu g:ctrlp_allmixes['cwd'] != a:cwd retu g:ctrlp_allmixes['cwd'] != a:cwd
\ || g:ctrlp_allmixes['filtime'] < getftime(ctrlp#utils#cachefile()) \ || g:ctrlp_allmixes['filtime'] < getftime(ctrlp#utils#cachefile())
\ || g:ctrlp_allmixes['mrutime'] < getftime(ctrlp#mrufiles#cachefile()) \ || g:ctrlp_allmixes['mrutime'] < getftime(ctrlp#mrufiles#cachefile())
\ || g:ctrlp_allmixes['bufs'] < len(ctrlp#mrufiles#mrufs()) \ || g:ctrlp_allmixes['bufs'] < len(ctrlp#mrufiles#bufs())
endf endf
fu! s:getnewmix(cwd, clim) fu! s:getnewmix(cwd, clim)
@ -41,6 +41,8 @@ fu! s:getnewmix(cwd, clim)
if exists('+ssl') && &ssl if exists('+ssl') && &ssl
cal map(mrufs, 'tr(v:val, "\\", "/")') cal map(mrufs, 'tr(v:val, "\\", "/")')
en en
let bufs = map(ctrlp#buffers('id'), 'fnamemodify(bufname(v:val), ":p")')
let mrufs = bufs + filter(mrufs, 'index(bufs, v:val) < 0')
if len(mrufs) > len(g:ctrlp_lines) if len(mrufs) > len(g:ctrlp_lines)
cal filter(mrufs, 'stridx(v:val, a:cwd)') cal filter(mrufs, 'stridx(v:val, a:cwd)')
el el
@ -59,7 +61,7 @@ fu! s:getnewmix(cwd, clim)
en en
let g:ctrlp_allmixes = { 'filtime': getftime(ctrlp#utils#cachefile()), let g:ctrlp_allmixes = { 'filtime': getftime(ctrlp#utils#cachefile()),
\ 'mrutime': getftime(ctrlp#mrufiles#cachefile()), 'cwd': a:cwd, \ 'mrutime': getftime(ctrlp#mrufiles#cachefile()), 'cwd': a:cwd,
\ 'bufs': len(ctrlp#mrufiles#mrufs()), 'data': g:ctrlp_lines } \ 'bufs': len(ctrlp#mrufiles#bufs()), 'data': g:ctrlp_lines }
endf endf
" Public {{{1 " Public {{{1
fu! ctrlp#mixed#init(clim) fu! ctrlp#mixed#init(clim)

View File

@ -25,12 +25,11 @@ fu! s:excl(fn)
retu !empty(s:ex) && a:fn =~# s:ex retu !empty(s:ex) && a:fn =~# s:ex
endf endf
fu! s:mergelists(...) fu! s:mergelists()
let diskmrufs = ctrlp#utils#readfile(ctrlp#mrufiles#cachefile()) let diskmrufs = ctrlp#utils#readfile(ctrlp#mrufiles#cachefile())
let mrus = a:0 && a:1 == 'raw' ? s:mrbs : s:mrufs cal filter(diskmrufs, 'index(s:mrufs, v:val) < 0')
cal filter(diskmrufs, 'index(mrus, v:val) < 0') let mrufs = s:mrufs + diskmrufs
let mrua = mrus + diskmrufs retu s:chop(mrufs)
retu a:0 && a:1 == 'raw' ? mrua : s:chop(mrua)
endf endf
fu! s:chop(mrufs) fu! s:chop(mrufs)
@ -54,15 +53,13 @@ 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
if empty(fn) || !empty(&bt) | retu | en
cal filter(s:mrbs, 'v:val !='.s:csen.' fn') cal filter(s:mrbs, 'v:val !='.s:csen.' fn')
cal insert(s:mrbs, fn) cal insert(s:mrbs, fn)
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 )
\ || !filereadable(fn) | retu \ || !empty(&bt) || !filereadable(fn) | retu
en en
cal filter(s:mrufs, 'v:val !='.s:csen.' fn') cal filter(s:mrufs, 'v:val !='.s:csen.' fn')
cal insert(s:mrufs, fn) cal insert(s:mrufs, fn)
let s:mrufs = s:chop(s:mrufs)
endf endf
fu! s:savetofile(mrufs) fu! s:savetofile(mrufs)
@ -91,17 +88,13 @@ fu! ctrlp#mrufiles#remove(files)
endf endf
fu! ctrlp#mrufiles#list(...) fu! ctrlp#mrufiles#list(...)
retu a:0 ? a:1 == 'raw' ? s:mergelists(a:1) : 0 : s:reformat(s:mergelists()) retu a:0 ? a:1 == 'raw' ? s:mergelists() : 0 : s:reformat(s:mergelists())
endf endf
fu! ctrlp#mrufiles#bufs() fu! ctrlp#mrufiles#bufs()
retu s:mrbs retu s:mrbs
endf endf
fu! ctrlp#mrufiles#mrufs()
retu s:mrufs
endf
fu! ctrlp#mrufiles#cachefile() fu! ctrlp#mrufiles#cachefile()
if !exists('s:cadir') || !exists('s:cafile') if !exists('s:cadir') || !exists('s:cafile')
let s:cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'mru' let s:cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'mru'