bgneal@7: " ============================================================================= bgneal@7: " File: autoload/ctrlp/mixed.vim bgneal@7: " Description: Mixing Files + MRU + Buffers bgneal@7: " Author: Kien Nguyen bgneal@7: " ============================================================================= bgneal@7: bgneal@7: " Init {{{1 bgneal@7: if exists('g:loaded_ctrlp_mixed') && g:loaded_ctrlp_mixed bgneal@7: fini bgneal@7: en bgneal@7: let [g:loaded_ctrlp_mixed, g:ctrlp_newmix] = [1, 0] bgneal@7: bgneal@7: cal add(g:ctrlp_ext_vars, { bgneal@7: \ 'init': 'ctrlp#mixed#init(s:compare_lim)', bgneal@7: \ 'accept': 'ctrlp#acceptfile', bgneal@7: \ 'lname': 'fil + mru + buf', bgneal@7: \ 'sname': 'mix', bgneal@7: \ 'type': 'path', bgneal@7: \ 'opmul': 1, bgneal@7: \ 'specinput': 1, bgneal@7: \ }) bgneal@7: bgneal@7: let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) bgneal@7: " Utilities {{{1 bgneal@7: fu! s:newcache(cwd) bgneal@7: if g:ctrlp_newmix || !has_key(g:ctrlp_allmixes, 'data') | retu 1 | en bgneal@7: retu g:ctrlp_allmixes['cwd'] != a:cwd bgneal@7: \ || g:ctrlp_allmixes['filtime'] < getftime(ctrlp#utils#cachefile()) bgneal@7: \ || g:ctrlp_allmixes['mrutime'] < getftime(ctrlp#mrufiles#cachefile()) bgneal@7: \ || g:ctrlp_allmixes['bufs'] < len(ctrlp#mrufiles#bufs()) bgneal@7: endf bgneal@7: bgneal@7: fu! s:getnewmix(cwd, clim) bgneal@7: if g:ctrlp_newmix bgneal@7: cal ctrlp#mrufiles#refresh('raw') bgneal@7: let g:ctrlp_newcache = 1 bgneal@7: en bgneal@7: let g:ctrlp_lines = copy(ctrlp#files()) bgneal@7: cal ctrlp#progress('Mixing...') bgneal@7: let mrufs = copy(ctrlp#mrufiles#list('raw')) bgneal@7: if exists('+ssl') && &ssl bgneal@7: cal map(mrufs, 'tr(v:val, "\\", "/")') bgneal@7: en bgneal@7: let bufs = map(ctrlp#buffers('id'), 'fnamemodify(bufname(v:val), ":p")') bgneal@7: let mrufs = bufs + filter(mrufs, 'index(bufs, v:val) < 0') bgneal@7: if len(mrufs) > len(g:ctrlp_lines) bgneal@7: cal filter(mrufs, 'stridx(v:val, a:cwd)') bgneal@7: el bgneal@7: let cwd_mrufs = filter(copy(mrufs), '!stridx(v:val, a:cwd)') bgneal@7: let cwd_mrufs = ctrlp#rmbasedir(cwd_mrufs) bgneal@7: for each in cwd_mrufs bgneal@7: let id = index(g:ctrlp_lines, each) bgneal@7: if id >= 0 | cal remove(g:ctrlp_lines, id) | en bgneal@7: endfo bgneal@7: en bgneal@7: cal map(mrufs, 'fnamemodify(v:val, ":.")') bgneal@7: let g:ctrlp_lines = len(mrufs) > len(g:ctrlp_lines) bgneal@7: \ ? g:ctrlp_lines + mrufs : mrufs + g:ctrlp_lines bgneal@7: if len(g:ctrlp_lines) <= a:clim bgneal@7: cal sort(g:ctrlp_lines, 'ctrlp#complen') bgneal@7: en bgneal@7: let g:ctrlp_allmixes = { 'filtime': getftime(ctrlp#utils#cachefile()), bgneal@7: \ 'mrutime': getftime(ctrlp#mrufiles#cachefile()), 'cwd': a:cwd, bgneal@7: \ 'bufs': len(ctrlp#mrufiles#bufs()), 'data': g:ctrlp_lines } bgneal@7: endf bgneal@7: " Public {{{1 bgneal@7: fu! ctrlp#mixed#init(clim) bgneal@7: let cwd = getcwd() bgneal@7: if s:newcache(cwd) bgneal@7: cal s:getnewmix(cwd, a:clim) bgneal@7: el bgneal@7: let g:ctrlp_lines = g:ctrlp_allmixes['data'] bgneal@7: en bgneal@7: let g:ctrlp_newmix = 0 bgneal@7: retu g:ctrlp_lines bgneal@7: endf bgneal@7: bgneal@7: fu! ctrlp#mixed#id() bgneal@7: retu s:id bgneal@7: endf bgneal@7: "}}} bgneal@7: bgneal@7: " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2