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