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

View File

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

View File

@ -27,7 +27,7 @@ fu! s:newcache(cwd)
retu g:ctrlp_allmixes['cwd'] != a:cwd
\ || g:ctrlp_allmixes['filtime'] < getftime(ctrlp#utils#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
fu! s:getnewmix(cwd, clim)
@ -41,6 +41,8 @@ fu! s:getnewmix(cwd, clim)
if exists('+ssl') && &ssl
cal map(mrufs, 'tr(v:val, "\\", "/")')
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)
cal filter(mrufs, 'stridx(v:val, a:cwd)')
el
@ -59,7 +61,7 @@ fu! s:getnewmix(cwd, clim)
en
let g:ctrlp_allmixes = { 'filtime': getftime(ctrlp#utils#cachefile()),
\ '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
" Public {{{1
fu! ctrlp#mixed#init(clim)

View File

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