Add buffers into the mix

This commit is contained in:
Kien N 2012-04-07 07:58:44 +07:00
parent 2cedde3400
commit c62259c201
3 changed files with 19 additions and 18 deletions

View File

@ -1,6 +1,6 @@
" ============================================================================= " =============================================================================
" File: autoload/ctrlp/mixed.vim " File: autoload/ctrlp/mixed.vim
" Description: Files + MRU " Description: Mixing Files + MRU + Buffers
" Author: Kien Nguyen <github.com/kien> " Author: Kien Nguyen <github.com/kien>
" ============================================================================= " =============================================================================
@ -13,7 +13,7 @@ let [g:loaded_ctrlp_mixed, g:ctrlp_newmix] = [1, 0]
let s:mixed_var = { let s:mixed_var = {
\ 'init': 'ctrlp#mixed#init(s:compare_lim)', \ 'init': 'ctrlp#mixed#init(s:compare_lim)',
\ 'accept': 'ctrlp#acceptfile', \ 'accept': 'ctrlp#acceptfile',
\ 'lname': 'fil + mru', \ 'lname': 'fil + mru + buf',
\ 'sname': 'mix', \ 'sname': 'mix',
\ 'type': 'path', \ 'type': 'path',
\ 'opmul': 1, \ 'opmul': 1,
@ -40,11 +40,11 @@ fu! s:getnewmix(cwd, clim)
en en
let g:ctrlp_lines = copy(ctrlp#files()) let g:ctrlp_lines = copy(ctrlp#files())
cal ctrlp#progress('Mixing...') cal ctrlp#progress('Mixing...')
let mrufs = ctrlp#mrufiles#list('raw') let mrufs = copy(ctrlp#mrufiles#list('raw'))
if exists('+ssl') && &ssl if exists('+ssl') && &ssl
cal map(mrufs, 'tr(v:val, "\\", "/")') cal map(mrufs, 'tr(v:val, "\\", "/")')
en en
if len(mrufs) > len(g:ctrlp_lines) || v:version < 702 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
let cwd_mrufs = filter(copy(mrufs), '!stridx(v:val, a:cwd)') let cwd_mrufs = filter(copy(mrufs), '!stridx(v:val, a:cwd)')

View File

@ -25,12 +25,12 @@ 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())
cal filter(diskmrufs, 'index(s:mrufs, v:val) < 0') let mrus = a:0 && a:1 == 'raw' ? s:mrbs : s:mrufs
let mrufs = s:mrufs + diskmrufs cal filter(diskmrufs, 'index(mrus, v:val) < 0')
if v:version < 702 | cal filter(mrufs, 'count(mrufs, v:val) == 1') | en 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)
@ -50,13 +50,15 @@ fu! s:record(bufnr)
if s:locked | retu | en if s:locked | retu | en
let bufnr = a:bufnr + 0 let bufnr = a:bufnr + 0
if bufnr <= 0 | retu | en if bufnr <= 0 | retu | en
let fn = fnamemodify(bufname(bufnr), ':p') let bufname = bufname(bufnr)
if empty(bufname) | retu | en
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(fn) || !empty(&bt) || ( !empty(s:in) && fn !~# s:in ) if ( !empty(s:in) && fn !~# s:in ) || ( !empty(s:ex) && fn =~# s:ex )
\ || ( !empty(s:ex) && fn =~# s:ex ) || !filereadable(fn) \ || !filereadable(fn) | retu
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)
@ -89,8 +91,7 @@ fu! ctrlp#mrufiles#remove(files)
endf endf
fu! ctrlp#mrufiles#list(...) fu! ctrlp#mrufiles#list(...)
if a:0 && a:1 != 'raw' | retu | en retu a:0 ? a:1 == 'raw' ? s:mergelists(a:1) : 0 : s:reformat(s:mergelists())
retu a:0 && a:1 == 'raw' ? s:mergelists() : s:reformat(s:mergelists())
endf endf
fu! ctrlp#mrufiles#bufs() fu! ctrlp#mrufiles#bufs()

View File

@ -770,7 +770,7 @@ Available extensions:~
* Mixed mode:~ * Mixed mode:~
- Name: 'mixed' - Name: 'mixed'
- Command: ':CtrlPMixed' - Command: ':CtrlPMixed'
- Search in both files and MRU files. - Search in files, buffers and MRU files.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Buffer Tag mode options:~ Buffer Tag mode options:~
@ -904,9 +904,9 @@ Special thanks:~
=============================================================================== ===============================================================================
CHANGELOG *ctrlp-changelog* CHANGELOG *ctrlp-changelog*
+ Remove: g:ctrlp_mruf_last_entered, make it the default for MRU mode. + Remove: g:ctrlp_mruf_last_entered, make it a default for MRU mode.
+ New commands: |:CtrlPLastMode|, open CtrlP in the last mode used. + New commands: |:CtrlPLastMode|, open CtrlP in the last mode used.
|:CtrlPMixed|, search in both files and MRU files. |:CtrlPMixed|, search in files, buffers and MRU files.
Before 2012/03/31~ Before 2012/03/31~