bgneal@0
|
1 " =============================================================================
|
bgneal@0
|
2 " File: autoload/ctrlp/utils.vim
|
bgneal@0
|
3 " Description: Utilities
|
bgneal@0
|
4 " Author: Kien Nguyen <github.com/kien>
|
bgneal@0
|
5 " =============================================================================
|
bgneal@0
|
6
|
bgneal@0
|
7 " Static variables {{{1
|
bgneal@0
|
8 fu! ctrlp#utils#lash()
|
bgneal@0
|
9 retu &ssl || !exists('+ssl') ? '/' : '\'
|
bgneal@0
|
10 endf
|
bgneal@0
|
11 let s:lash = ctrlp#utils#lash()
|
bgneal@0
|
12
|
bgneal@0
|
13 fu! ctrlp#utils#opts()
|
bgneal@0
|
14 let s:cache_dir = $HOME.s:lash.'.ctrlp_cache'
|
bgneal@0
|
15 if exists('g:ctrlp_cache_dir')
|
bgneal@0
|
16 let s:cache_dir = expand(g:ctrlp_cache_dir, 1)
|
bgneal@0
|
17 if isdirectory(s:cache_dir.s:lash.'.ctrlp_cache')
|
bgneal@0
|
18 let s:cache_dir = s:cache_dir.s:lash.'.ctrlp_cache'
|
bgneal@0
|
19 en
|
bgneal@0
|
20 en
|
bgneal@0
|
21 endf
|
bgneal@0
|
22 cal ctrlp#utils#opts()
|
bgneal@0
|
23 " Files and Directories {{{1
|
bgneal@0
|
24 fu! ctrlp#utils#cachedir()
|
bgneal@0
|
25 retu s:cache_dir
|
bgneal@0
|
26 endf
|
bgneal@0
|
27
|
bgneal@0
|
28 fu! ctrlp#utils#cachefile(...)
|
bgneal@0
|
29 let tail = exists('a:1') ? '.'.a:1 : ''
|
bgneal@0
|
30 let cache_file = substitute(getcwd(), '\([\/]\|^\a\zs:\)', '%', 'g').tail.'.txt'
|
bgneal@0
|
31 retu exists('a:1') ? cache_file : s:cache_dir.s:lash.cache_file
|
bgneal@0
|
32 endf
|
bgneal@0
|
33
|
bgneal@0
|
34 fu! ctrlp#utils#readfile(file)
|
bgneal@0
|
35 if filereadable(a:file)
|
bgneal@0
|
36 let data = readfile(a:file)
|
bgneal@0
|
37 if empty(data) || type(data) != 3
|
bgneal@0
|
38 unl data
|
bgneal@0
|
39 let data = []
|
bgneal@0
|
40 en
|
bgneal@0
|
41 retu data
|
bgneal@0
|
42 en
|
bgneal@0
|
43 retu []
|
bgneal@0
|
44 endf
|
bgneal@0
|
45
|
bgneal@0
|
46 fu! ctrlp#utils#mkdir(dir)
|
bgneal@0
|
47 if exists('*mkdir') && !isdirectory(a:dir)
|
bgneal@0
|
48 sil! cal mkdir(a:dir)
|
bgneal@0
|
49 en
|
bgneal@0
|
50 endf
|
bgneal@0
|
51
|
bgneal@0
|
52 fu! ctrlp#utils#writecache(lines, ...)
|
bgneal@0
|
53 let cache_dir = exists('a:1') ? a:1 : s:cache_dir
|
bgneal@0
|
54 cal ctrlp#utils#mkdir(cache_dir)
|
bgneal@0
|
55 if isdirectory(cache_dir)
|
bgneal@0
|
56 sil! cal writefile(a:lines, exists('a:2') ? a:2 : ctrlp#utils#cachefile())
|
bgneal@0
|
57 if !exists('a:1')
|
bgneal@0
|
58 let g:ctrlp_newcache = 0
|
bgneal@0
|
59 en
|
bgneal@0
|
60 en
|
bgneal@0
|
61 endf
|
bgneal@0
|
62
|
bgneal@0
|
63 fu! ctrlp#utils#glob(...)
|
bgneal@3
|
64 retu call('glob', v:version > 701 ? a:000 : [a:1])
|
bgneal@0
|
65 endf
|
bgneal@0
|
66 "}}}
|
bgneal@0
|
67
|
bgneal@0
|
68 " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2
|