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],
|
2012-02-11 09:54:27 -05:00
|
|
|
\ 'g:ctrlp_mruf_include': ['s:in', ''],
|
|
|
|
\ 'g:ctrlp_mruf_exclude': ['s:ex', ''],
|
2011-11-12 10:00:50 -05:00
|
|
|
\ 'g:ctrlp_mruf_case_sensitive': ['s:csen', 1],
|
2012-02-11 09:54:27 -05:00
|
|
|
\ 'g:ctrlp_mruf_relative': ['s:re', 0],
|
2012-01-17 11:13:39 -05:00
|
|
|
\ 'g:ctrlp_mruf_last_entered': ['s:mre', 0],
|
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
|
2012-03-14 21:15:54 -04:00
|
|
|
let [s:csen, s:mrbs] = [s:csen ? '#' : '?', []]
|
2012-03-20 15:34:17 -04:00
|
|
|
if exists('s:locked')
|
|
|
|
cal ctrlp#mrufiles#init()
|
|
|
|
en
|
2011-11-04 03:29:10 -04:00
|
|
|
endf
|
2011-09-18 07:33:37 -04:00
|
|
|
cal ctrlp#mrufiles#opts()
|
2012-03-14 21:15:54 -04:00
|
|
|
" Utilities {{{1
|
|
|
|
fu! s:excl(fn)
|
|
|
|
retu !empty(s:ex) && a:fn =~# s:ex
|
|
|
|
endf
|
|
|
|
|
|
|
|
fu! s:readcache()
|
2012-01-12 21:13:39 -05:00
|
|
|
if !exists('s:cadir') || !exists('s:cafile')
|
|
|
|
let s:cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'mru'
|
|
|
|
let s:cafile = s:cadir.ctrlp#utils#lash().'cache.txt'
|
|
|
|
en
|
2012-03-14 21:15:54 -04:00
|
|
|
retu ctrlp#utils#readfile(s:cafile)
|
|
|
|
endf
|
|
|
|
|
|
|
|
fu! s:reformat(mrufs)
|
|
|
|
if s:re
|
|
|
|
let cwd = exists('+ssl') ? tr(getcwd(), '/', '\') : getcwd()
|
|
|
|
cal filter(a:mrufs, '!stridx(v:val, cwd)')
|
2011-11-04 03:29:10 -04:00
|
|
|
en
|
2012-03-14 21:15:54 -04:00
|
|
|
retu map(a:mrufs, 'fnamemodify(v:val, '':.'')')
|
|
|
|
endf
|
|
|
|
|
|
|
|
fu! s:record(bufnr, ...)
|
|
|
|
if s:locked | retu | en
|
|
|
|
let bufnr = a:bufnr + 0
|
|
|
|
if bufnr <= 0 | retu | en
|
|
|
|
let fn = fnamemodify(bufname(bufnr), ':p')
|
|
|
|
let fn = exists('+ssl') ? tr(fn, '/', '\') : fn
|
|
|
|
cal filter(s:mrbs, 'v:val !='.s:csen.' fn')
|
|
|
|
cal insert(s:mrbs, fn)
|
|
|
|
if empty(fn) || !empty(&bt) || ( !empty(s:in) && fn !~# s:in )
|
|
|
|
\ || ( !empty(s:ex) && fn =~# s:ex ) || !filereadable(fn)
|
|
|
|
\ || ( a:0 && a:1 == 1 )
|
|
|
|
retu
|
2012-01-09 17:58:59 -05:00
|
|
|
en
|
2012-03-14 21:15:54 -04:00
|
|
|
let mrufs = s:readcache()
|
2012-02-11 09:54:27 -05:00
|
|
|
cal filter(mrufs, 'v:val !='.s:csen.' fn')
|
|
|
|
cal insert(mrufs, fn)
|
2011-11-12 10:00:50 -05:00
|
|
|
if len(mrufs) > s:max | cal remove(mrufs, s:max, -1) | en
|
2012-01-09 17:58:59 -05:00
|
|
|
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile)
|
2012-03-14 21:15:54 -04:00
|
|
|
endf
|
|
|
|
" Public {{{1
|
|
|
|
fu! ctrlp#mrufiles#refresh()
|
|
|
|
let mrufs = s:readcache()
|
|
|
|
cal filter(mrufs, '!empty(ctrlp#utils#glob(v:val, 1)) && !s:excl(v:val)')
|
|
|
|
if exists('+ssl')
|
|
|
|
cal map(mrufs, 'tr(v:val, ''/'', ''\'')')
|
|
|
|
cal filter(mrufs, 'count(mrufs, v:val) == 1')
|
|
|
|
en
|
|
|
|
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile)
|
|
|
|
retu s:reformat(mrufs)
|
|
|
|
endf
|
|
|
|
|
|
|
|
fu! ctrlp#mrufiles#remove(files)
|
|
|
|
let mrufs = []
|
|
|
|
if a:files != []
|
|
|
|
let mrufs = s:readcache()
|
|
|
|
cal filter(mrufs, 'index(a:files, v:val) < 0')
|
|
|
|
en
|
|
|
|
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile)
|
|
|
|
retu map(mrufs, 'fnamemodify(v:val, '':.'')')
|
|
|
|
endf
|
|
|
|
|
2012-03-15 16:11:55 -04:00
|
|
|
fu! ctrlp#mrufiles#list(...)
|
2012-03-20 15:34:17 -04:00
|
|
|
if a:0 | cal s:record(a:1) | retu | en
|
2012-03-14 21:15:54 -04:00
|
|
|
retu s:reformat(s:readcache())
|
|
|
|
endf
|
|
|
|
|
|
|
|
fu! ctrlp#mrufiles#bufs()
|
|
|
|
retu s:mrbs
|
|
|
|
endf
|
|
|
|
|
|
|
|
fu! ctrlp#mrufiles#init()
|
|
|
|
if !has('autocmd') | retu | en
|
2011-09-07 10:41:43 -04:00
|
|
|
let s:locked = 0
|
|
|
|
aug CtrlPMRUF
|
|
|
|
au!
|
2012-03-14 21:15:54 -04:00
|
|
|
au BufReadPost,BufNewFile,BufWritePost * cal s:record(expand('<abuf>', 1))
|
2011-11-04 03:29:10 -04:00
|
|
|
au QuickFixCmdPre *vimgrep* let s:locked = 1
|
2011-09-07 10:41:43 -04:00
|
|
|
au QuickFixCmdPost *vimgrep* let s:locked = 0
|
|
|
|
aug END
|
2012-03-20 15:34:17 -04:00
|
|
|
aug CtrlPMREB
|
|
|
|
au!
|
|
|
|
au BufEnter,BufUnload * cal s:record(expand('<abuf>', 1), 1)
|
|
|
|
aug END
|
|
|
|
if exists('#CtrlPMREF')
|
|
|
|
au! CtrlPMREF
|
|
|
|
en
|
2012-03-14 21:15:54 -04:00
|
|
|
if s:mre
|
2012-03-15 16:11:55 -04:00
|
|
|
aug CtrlPMREF
|
2012-03-14 21:15:54 -04:00
|
|
|
au!
|
|
|
|
au BufEnter,BufUnload * cal s:record(expand('<abuf>', 1))
|
|
|
|
aug END
|
2012-03-15 16:11:55 -04:00
|
|
|
if exists('#CtrlPMREB')
|
|
|
|
au! CtrlPMREB
|
|
|
|
en
|
2012-03-14 21:15:54 -04:00
|
|
|
en
|
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
|