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-01-09 17:58:59 -05:00
|
|
|
let s:csen = s:csen ? '#' : '?'
|
2011-11-04 03:29:10 -04:00
|
|
|
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
|
2012-01-12 21:13:39 -05:00
|
|
|
let bufnr = a:bufnr + 0
|
|
|
|
if bufnr > 0
|
2012-02-11 09:54:27 -05:00
|
|
|
let fn = fnamemodify(bufname(bufnr), ':p')
|
|
|
|
let fn = exists('+ssl') ? tr(fn, '/', '\') : fn
|
|
|
|
if empty(fn) || !empty(&bt) || ( !empty(s:in) && fn !~# s:in )
|
|
|
|
\ || ( !empty(s:ex) && fn =~# s:ex ) || !filereadable(fn)
|
2012-01-12 21:13:39 -05:00
|
|
|
retu
|
|
|
|
en
|
|
|
|
en
|
|
|
|
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
|
|
|
|
if a:0 && a:1 == 2
|
2012-02-20 02:58:03 -05:00
|
|
|
let mrufs = []
|
|
|
|
if a:0 == 2
|
|
|
|
let mrufs = ctrlp#utils#readfile(s:cafile)
|
|
|
|
cal filter(mrufs, 'index(a:2, v:val) < 0')
|
|
|
|
en
|
|
|
|
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile)
|
|
|
|
retu map(mrufs, 'fnamemodify(v:val, '':.'')')
|
2012-01-12 21:13:39 -05:00
|
|
|
en
|
2011-11-04 03:29:10 -04:00
|
|
|
" Get the list
|
2012-01-09 17:58:59 -05:00
|
|
|
let mrufs = ctrlp#utils#readfile(s:cafile)
|
2011-11-04 03:29:10 -04:00
|
|
|
" Remove non-existent files
|
2012-01-09 17:58:59 -05:00
|
|
|
if a:0 && a:1 == 1
|
2012-01-17 11:13:39 -05:00
|
|
|
cal filter(mrufs, '!empty(ctrlp#utils#glob(v:val, 1)) && !s:excl(v:val)')
|
2012-02-11 09:54:27 -05:00
|
|
|
if exists('+ssl')
|
|
|
|
cal map(mrufs, 'tr(v:val, ''/'', ''\'')')
|
|
|
|
cal filter(mrufs, 'count(mrufs, v:val) == 1')
|
|
|
|
en
|
2012-01-12 21:13:39 -05:00
|
|
|
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile)
|
2011-11-04 03:29:10 -04:00
|
|
|
en
|
2012-01-12 21:13:39 -05:00
|
|
|
" Return the list with the active buffer removed
|
|
|
|
if bufnr == -1
|
2012-01-15 12:42:14 -05:00
|
|
|
let crf = fnamemodify(bufname(winbufnr(winnr('#'))), ':p')
|
2012-02-11 09:54:27 -05:00
|
|
|
let crf = exists('+ssl') ? tr(crf, '/', '\') : crf
|
2012-01-15 12:42:14 -05:00
|
|
|
let mrufs = empty(crf) ? mrufs : filter(mrufs, 'v:val !='.s:csen.' crf')
|
2012-02-11 09:54:27 -05:00
|
|
|
if s:re
|
|
|
|
let cwd = exists('+ssl') ? tr(getcwd(), '/', '\') : getcwd()
|
2012-01-15 12:42:14 -05:00
|
|
|
cal filter(mrufs, '!stridx(v:val, cwd)')
|
|
|
|
en
|
2012-02-20 02:58:03 -05:00
|
|
|
retu map(mrufs, 'fnamemodify(v:val, '':.'')')
|
2012-01-09 17:58:59 -05:00
|
|
|
en
|
2012-01-12 21:13:39 -05:00
|
|
|
" Remove old entry
|
2012-02-11 09:54:27 -05:00
|
|
|
cal filter(mrufs, 'v:val !='.s:csen.' fn')
|
2011-11-04 03:29:10 -04:00
|
|
|
" Insert new one
|
2012-02-11 09:54:27 -05:00
|
|
|
cal insert(mrufs, fn)
|
2012-01-12 21:13:39 -05:00
|
|
|
" Remove oldest entry or entries
|
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)
|
2011-11-04 03:29:10 -04:00
|
|
|
endf "}}}
|
2012-02-11 09:54:27 -05:00
|
|
|
fu! s:excl(fn) "{{{
|
|
|
|
retu !empty(s:ex) && a:fn =~# s:ex
|
2012-01-17 11:13:39 -05:00
|
|
|
endf "}}}
|
2011-12-02 22:54:18 -05:00
|
|
|
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))
|
2012-01-17 11:13:39 -05:00
|
|
|
if s:mre
|
|
|
|
au BufEnter,BufUnload *
|
|
|
|
\ cal ctrlp#mrufiles#list(expand('<abuf>', 1))
|
|
|
|
en
|
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
|
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
|