bgneal@0: " ============================================================================= bgneal@0: " File: autoload/ctrlp/mrufiles.vim bgneal@0: " Description: Most Recently Used Files extension bgneal@0: " Author: Kien Nguyen bgneal@0: " ============================================================================= bgneal@0: bgneal@0: " Static variables {{{1 bgneal@0: fu! ctrlp#mrufiles#opts() bgneal@0: let opts = { bgneal@0: \ 'g:ctrlp_mruf_max': ['s:max', 250], bgneal@0: \ 'g:ctrlp_mruf_include': ['s:include', ''], bgneal@0: \ 'g:ctrlp_mruf_exclude': ['s:exclude', ''], bgneal@0: \ 'g:ctrlp_mruf_case_sensitive': ['s:csen', 1], bgneal@0: \ } bgneal@0: for [ke, va] in items(opts) bgneal@0: exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1]) bgneal@0: endfo bgneal@0: endf bgneal@0: cal ctrlp#mrufiles#opts() bgneal@0: fu! ctrlp#mrufiles#list(bufnr, ...) "{{{1 bgneal@0: if s:locked | retu | en bgneal@0: " Get the list bgneal@0: let cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'mru' bgneal@0: let cafile = cadir.ctrlp#utils#lash().'cache.txt' bgneal@0: let mrufs = ctrlp#utils#readfile(cafile) bgneal@0: " Remove non-existent files bgneal@0: if exists('a:1') && a:1 == 1 bgneal@0: let mrufs = s:rmdeleted(mrufs, cadir, cafile) bgneal@0: elsei exists('a:1') && a:1 == 2 bgneal@0: cal ctrlp#utils#writecache([], cadir, cafile) bgneal@0: retu [] bgneal@0: en bgneal@0: " Return the list bgneal@0: if a:bufnr == -1 | retu mrufs | en bgneal@0: " Filter it bgneal@0: let filename = fnamemodify(bufname(a:bufnr + 0), ':p') bgneal@0: if empty(filename) || !empty(&bt) bgneal@0: \ || ( !empty(s:include) && filename !~# s:include ) bgneal@0: \ || ( !empty(s:exclude) && filename =~# s:exclude ) bgneal@0: \ || ( index(mrufs, filename) == -1 && !filereadable(filename) ) bgneal@0: retu bgneal@0: en bgneal@0: " Remove old matched entry bgneal@0: cal filter(mrufs, 'v:val !='.( s:csen ? "#" : "?" ).' filename') bgneal@0: " Insert new one bgneal@0: cal insert(mrufs, filename) bgneal@0: " Remove oldest entry bgneal@0: if len(mrufs) > s:max | cal remove(mrufs, s:max, -1) | en bgneal@0: cal ctrlp#utils#writecache(mrufs, cadir, cafile) bgneal@0: endf "}}} bgneal@0: fu! s:rmdeleted(mrufs, cadir, cafile) "{{{ bgneal@0: cal filter(a:mrufs, '!empty(ctrlp#utils#glob(v:val, 1))') bgneal@0: cal ctrlp#utils#writecache(a:mrufs, a:cadir, a:cafile) bgneal@0: retu a:mrufs bgneal@0: endf bgneal@0: fu! ctrlp#mrufiles#init() "{{{1 bgneal@0: let s:locked = 0 bgneal@0: aug CtrlPMRUF bgneal@0: au! bgneal@0: au BufReadPost,BufNewFile,BufWritePost * bgneal@0: \ cal ctrlp#mrufiles#list(expand('', 1)) bgneal@0: au QuickFixCmdPre *vimgrep* let s:locked = 1 bgneal@0: au QuickFixCmdPost *vimgrep* let s:locked = 0 bgneal@0: aug END bgneal@0: endf bgneal@0: "}}} bgneal@0: bgneal@0: " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2