annotate vim/vimfiles/autoload/ctrlp/mrufiles.vim @ 0:48859d9c82c5

Initial commit, based on settings used at work (minus NERD tree & some tagging plugins).
author Brian Neal <bgneal@gmail.com>
date Tue, 03 Jan 2012 20:53:13 -0600
parents
children
rev   line source
bgneal@0 1 " =============================================================================
bgneal@0 2 " File: autoload/ctrlp/mrufiles.vim
bgneal@0 3 " Description: Most Recently Used Files extension
bgneal@0 4 " Author: Kien Nguyen <github.com/kien>
bgneal@0 5 " =============================================================================
bgneal@0 6
bgneal@0 7 " Static variables {{{1
bgneal@0 8 fu! ctrlp#mrufiles#opts()
bgneal@0 9 let opts = {
bgneal@0 10 \ 'g:ctrlp_mruf_max': ['s:max', 250],
bgneal@0 11 \ 'g:ctrlp_mruf_include': ['s:include', ''],
bgneal@0 12 \ 'g:ctrlp_mruf_exclude': ['s:exclude', ''],
bgneal@0 13 \ 'g:ctrlp_mruf_case_sensitive': ['s:csen', 1],
bgneal@0 14 \ }
bgneal@0 15 for [ke, va] in items(opts)
bgneal@0 16 exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1])
bgneal@0 17 endfo
bgneal@0 18 endf
bgneal@0 19 cal ctrlp#mrufiles#opts()
bgneal@0 20 fu! ctrlp#mrufiles#list(bufnr, ...) "{{{1
bgneal@0 21 if s:locked | retu | en
bgneal@0 22 " Get the list
bgneal@0 23 let cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'mru'
bgneal@0 24 let cafile = cadir.ctrlp#utils#lash().'cache.txt'
bgneal@0 25 let mrufs = ctrlp#utils#readfile(cafile)
bgneal@0 26 " Remove non-existent files
bgneal@0 27 if exists('a:1') && a:1 == 1
bgneal@0 28 let mrufs = s:rmdeleted(mrufs, cadir, cafile)
bgneal@0 29 elsei exists('a:1') && a:1 == 2
bgneal@0 30 cal ctrlp#utils#writecache([], cadir, cafile)
bgneal@0 31 retu []
bgneal@0 32 en
bgneal@0 33 " Return the list
bgneal@0 34 if a:bufnr == -1 | retu mrufs | en
bgneal@0 35 " Filter it
bgneal@0 36 let filename = fnamemodify(bufname(a:bufnr + 0), ':p')
bgneal@0 37 if empty(filename) || !empty(&bt)
bgneal@0 38 \ || ( !empty(s:include) && filename !~# s:include )
bgneal@0 39 \ || ( !empty(s:exclude) && filename =~# s:exclude )
bgneal@0 40 \ || ( index(mrufs, filename) == -1 && !filereadable(filename) )
bgneal@0 41 retu
bgneal@0 42 en
bgneal@0 43 " Remove old matched entry
bgneal@0 44 cal filter(mrufs, 'v:val !='.( s:csen ? "#" : "?" ).' filename')
bgneal@0 45 " Insert new one
bgneal@0 46 cal insert(mrufs, filename)
bgneal@0 47 " Remove oldest entry
bgneal@0 48 if len(mrufs) > s:max | cal remove(mrufs, s:max, -1) | en
bgneal@0 49 cal ctrlp#utils#writecache(mrufs, cadir, cafile)
bgneal@0 50 endf "}}}
bgneal@0 51 fu! s:rmdeleted(mrufs, cadir, cafile) "{{{
bgneal@0 52 cal filter(a:mrufs, '!empty(ctrlp#utils#glob(v:val, 1))')
bgneal@0 53 cal ctrlp#utils#writecache(a:mrufs, a:cadir, a:cafile)
bgneal@0 54 retu a:mrufs
bgneal@0 55 endf
bgneal@0 56 fu! ctrlp#mrufiles#init() "{{{1
bgneal@0 57 let s:locked = 0
bgneal@0 58 aug CtrlPMRUF
bgneal@0 59 au!
bgneal@0 60 au BufReadPost,BufNewFile,BufWritePost *
bgneal@0 61 \ cal ctrlp#mrufiles#list(expand('<abuf>', 1))
bgneal@0 62 au QuickFixCmdPre *vimgrep* let s:locked = 1
bgneal@0 63 au QuickFixCmdPost *vimgrep* let s:locked = 0
bgneal@0 64 aug END
bgneal@0 65 endf
bgneal@0 66 "}}}
bgneal@0 67
bgneal@0 68 " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2