Mercurial > public > dotfiles
comparison vim/vimfiles/bundle/ctrlp.vim/autoload/ctrlp/mrufiles.vim @ 7:86e0ac713642
Re-added the latest ctrlp.vim plugin.
The ctrlp.vim commit was e61e7d5b801ade5fcefeab3aca75c1f37d54bdf1.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 29 Apr 2012 16:20:31 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
6:ff60fbc930de | 7:86e0ac713642 |
---|---|
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 let [s:mrbs, s:mrufs] = [[], []] | |
9 | |
10 fu! ctrlp#mrufiles#opts() | |
11 let [pref, opts] = ['g:ctrlp_mruf_', { | |
12 \ 'max': ['s:max', 250], | |
13 \ 'include': ['s:in', ''], | |
14 \ 'exclude': ['s:ex', ''], | |
15 \ 'case_sensitive': ['s:cseno', 1], | |
16 \ 'relative': ['s:re', 0], | |
17 \ }] | |
18 for [ke, va] in items(opts) | |
19 let [{va[0]}, {pref.ke}] = [pref.ke, exists(pref.ke) ? {pref.ke} : va[1]] | |
20 endfo | |
21 endf | |
22 cal ctrlp#mrufiles#opts() | |
23 " Utilities {{{1 | |
24 fu! s:excl(fn) | |
25 retu !empty({s:ex}) && a:fn =~# {s:ex} | |
26 endf | |
27 | |
28 fu! s:mergelists() | |
29 let diskmrufs = ctrlp#utils#readfile(ctrlp#mrufiles#cachefile()) | |
30 cal filter(diskmrufs, 'index(s:mrufs, v:val) < 0') | |
31 let mrufs = s:mrufs + diskmrufs | |
32 retu s:chop(mrufs) | |
33 endf | |
34 | |
35 fu! s:chop(mrufs) | |
36 if len(a:mrufs) > {s:max} | cal remove(a:mrufs, {s:max}, -1) | en | |
37 retu a:mrufs | |
38 endf | |
39 | |
40 fu! s:reformat(mrufs) | |
41 if {s:re} | |
42 let cwd = exists('+ssl') ? tr(getcwd(), '/', '\') : getcwd() | |
43 cal filter(a:mrufs, '!stridx(v:val, cwd)') | |
44 en | |
45 retu map(a:mrufs, 'fnamemodify(v:val, ":.")') | |
46 endf | |
47 | |
48 fu! s:record(bufnr) | |
49 if s:locked | retu | en | |
50 let bufnr = a:bufnr + 0 | |
51 if bufnr <= 0 | retu | en | |
52 let bufname = bufname(bufnr) | |
53 if empty(bufname) | retu | en | |
54 let fn = fnamemodify(bufname, ':p') | |
55 let fn = exists('+ssl') ? tr(fn, '/', '\') : fn | |
56 cal filter(s:mrbs, 'v:val != bufnr') | |
57 cal insert(s:mrbs, bufnr) | |
58 if ( !empty({s:in}) && fn !~# {s:in} ) || ( !empty({s:ex}) && fn =~# {s:ex} ) | |
59 \ || !empty(&bt) || !filereadable(fn) | retu | |
60 en | |
61 cal filter(s:mrufs, 'v:val !='.( {s:cseno} ? '#' : '?' ).' fn') | |
62 cal insert(s:mrufs, fn) | |
63 endf | |
64 | |
65 fu! s:savetofile(mrufs) | |
66 cal ctrlp#utils#writecache(a:mrufs, s:cadir, s:cafile) | |
67 endf | |
68 " Public {{{1 | |
69 fu! ctrlp#mrufiles#refresh(...) | |
70 let s:mrufs = s:mergelists() | |
71 cal filter(s:mrufs, '!empty(ctrlp#utils#glob(v:val, 1)) && !s:excl(v:val)') | |
72 if exists('+ssl') | |
73 cal map(s:mrufs, 'tr(v:val, "/", "\\")') | |
74 cal filter(s:mrufs, 'count(s:mrufs, v:val) == 1') | |
75 en | |
76 cal s:savetofile(s:mrufs) | |
77 retu a:0 && a:1 == 'raw' ? [] : s:reformat(copy(s:mrufs)) | |
78 endf | |
79 | |
80 fu! ctrlp#mrufiles#remove(files) | |
81 let s:mrufs = [] | |
82 if a:files != [] | |
83 let s:mrufs = s:mergelists() | |
84 cal filter(s:mrufs, 'index(a:files, v:val, 0, '.(!{s:cseno}).') < 0') | |
85 en | |
86 cal s:savetofile(s:mrufs) | |
87 retu s:reformat(copy(s:mrufs)) | |
88 endf | |
89 | |
90 fu! ctrlp#mrufiles#list(...) | |
91 retu a:0 ? a:1 == 'raw' ? s:mergelists() : 0 : s:reformat(s:mergelists()) | |
92 endf | |
93 | |
94 fu! ctrlp#mrufiles#bufs() | |
95 retu s:mrbs | |
96 endf | |
97 | |
98 fu! ctrlp#mrufiles#cachefile() | |
99 if !exists('s:cadir') || !exists('s:cafile') | |
100 let s:cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'mru' | |
101 let s:cafile = s:cadir.ctrlp#utils#lash().'cache.txt' | |
102 en | |
103 retu s:cafile | |
104 endf | |
105 | |
106 fu! ctrlp#mrufiles#init() | |
107 if !has('autocmd') | retu | en | |
108 let s:locked = 0 | |
109 aug CtrlPMRUF | |
110 au! | |
111 au BufAdd,BufEnter,BufLeave,BufUnload * cal s:record(expand('<abuf>', 1)) | |
112 au QuickFixCmdPre *vimgrep* let s:locked = 1 | |
113 au QuickFixCmdPost *vimgrep* let s:locked = 0 | |
114 au VimLeavePre * cal s:savetofile(s:mergelists()) | |
115 aug END | |
116 endf | |
117 "}}} | |
118 | |
119 " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 |