2011-09-07 10:41:43 -04:00
|
|
|
" =============================================================================
|
|
|
|
" File: autoload/ctrlp/utils.vim
|
2011-11-14 01:58:09 -05:00
|
|
|
" Description: Utilities
|
2011-09-07 10:41:43 -04:00
|
|
|
" Author: Kien Nguyen <github.com/kien>
|
|
|
|
" =============================================================================
|
|
|
|
|
2011-11-04 03:29:10 -04:00
|
|
|
" Static variables {{{
|
2011-11-14 01:58:09 -05:00
|
|
|
fu! ctrlp#utils#lash()
|
|
|
|
retu &ssl || !exists('+ssl') ? '/' : '\'
|
|
|
|
endf
|
|
|
|
let s:lash = ctrlp#utils#lash()
|
|
|
|
|
2011-11-04 03:29:10 -04:00
|
|
|
fu! ctrlp#utils#opts()
|
2011-11-14 04:00:44 -05:00
|
|
|
let s:cache_dir = $HOME.s:lash.'.ctrlp_cache'
|
|
|
|
if exists('g:ctrlp_cache_dir')
|
|
|
|
let s:cache_dir = expand(g:ctrlp_cache_dir, 1)
|
|
|
|
if isdirectory(s:cache_dir.s:lash.'.ctrlp_cache')
|
|
|
|
let s:cache_dir = s:cache_dir.s:lash.'.ctrlp_cache'
|
|
|
|
en
|
|
|
|
en
|
2011-11-04 03:29:10 -04:00
|
|
|
endf
|
2011-09-18 07:33:37 -04:00
|
|
|
cal ctrlp#utils#opts()
|
2011-09-07 10:41:43 -04:00
|
|
|
"}}}
|
2011-10-23 06:38:03 -04:00
|
|
|
" Files and Directories {{{
|
2011-11-04 03:29:10 -04:00
|
|
|
fu! ctrlp#utils#cachedir()
|
2011-11-14 01:58:09 -05:00
|
|
|
retu s:cache_dir
|
2011-11-04 03:29:10 -04:00
|
|
|
endf
|
2011-09-07 10:41:43 -04:00
|
|
|
|
2011-11-04 03:29:10 -04:00
|
|
|
fu! ctrlp#utils#cachefile()
|
|
|
|
let cache_file = substitute(getcwd(), '\([\/]\|^\a\zs:\)', '%', 'g').'.txt'
|
2011-11-14 01:58:09 -05:00
|
|
|
retu s:cache_dir.s:lash.cache_file
|
2011-11-04 03:29:10 -04:00
|
|
|
endf
|
2011-09-07 10:41:43 -04:00
|
|
|
|
2011-11-04 03:29:10 -04:00
|
|
|
fu! ctrlp#utils#readfile(file)
|
2011-09-07 10:41:43 -04:00
|
|
|
if filereadable(a:file)
|
|
|
|
let data = readfile(a:file)
|
2011-11-14 01:58:09 -05:00
|
|
|
if empty(data) || type(data) != 3 | unl data | let data = [] | en
|
2011-09-07 10:41:43 -04:00
|
|
|
retu data
|
2011-11-04 03:29:10 -04:00
|
|
|
en
|
2011-11-12 10:00:50 -05:00
|
|
|
retu []
|
2011-11-04 03:29:10 -04:00
|
|
|
endf
|
2011-09-07 10:41:43 -04:00
|
|
|
|
2011-11-04 03:29:10 -04:00
|
|
|
fu! ctrlp#utils#mkdir(dir)
|
2011-11-14 01:58:09 -05:00
|
|
|
if exists('*mkdir') && !isdirectory(a:dir) | sil! cal mkdir(a:dir) | en
|
2011-11-04 03:29:10 -04:00
|
|
|
endf
|
2011-09-07 10:41:43 -04:00
|
|
|
|
2011-11-12 10:00:50 -05:00
|
|
|
fu! ctrlp#utils#writecache(lines, ...)
|
2011-11-14 01:58:09 -05:00
|
|
|
let cache_dir = exists('a:1') ? a:1 : s:cache_dir
|
2011-09-07 10:41:43 -04:00
|
|
|
cal ctrlp#utils#mkdir(cache_dir)
|
|
|
|
if isdirectory(cache_dir)
|
2011-11-04 03:29:10 -04:00
|
|
|
sil! cal writefile(a:lines, exists('a:2') ? a:2 : ctrlp#utils#cachefile())
|
2011-11-14 01:58:09 -05:00
|
|
|
if !exists('a:1') || !exists('a:2') | let g:ctrlp_newcache = 0 | en
|
2011-11-04 03:29:10 -04:00
|
|
|
en
|
|
|
|
endf
|
2011-09-07 10:41:43 -04:00
|
|
|
|
2011-11-12 10:00:50 -05:00
|
|
|
fu! ctrlp#utils#glob(...)
|
|
|
|
retu call('glob', v:version > 701 ? [a:1, a:2] : [a:1])
|
|
|
|
endf
|
2011-09-07 10:41:43 -04:00
|
|
|
"}}}
|
|
|
|
|
2011-11-04 03:29:10 -04:00
|
|
|
" vim:fen:fdl=0:fdc=1:ts=2:sw=2:sts=2
|