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