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