bgneal@0: " ============================================================================= bgneal@0: " File: autoload/ctrlp/utils.vim bgneal@0: " Description: Utilities bgneal@0: " Author: Kien Nguyen bgneal@0: " ============================================================================= bgneal@0: bgneal@0: " Static variables {{{1 bgneal@0: fu! ctrlp#utils#lash() bgneal@0: retu &ssl || !exists('+ssl') ? '/' : '\' bgneal@0: endf bgneal@0: let s:lash = ctrlp#utils#lash() bgneal@0: bgneal@0: fu! ctrlp#utils#opts() bgneal@0: let s:cache_dir = $HOME.s:lash.'.ctrlp_cache' bgneal@0: if exists('g:ctrlp_cache_dir') bgneal@0: let s:cache_dir = expand(g:ctrlp_cache_dir, 1) bgneal@0: if isdirectory(s:cache_dir.s:lash.'.ctrlp_cache') bgneal@0: let s:cache_dir = s:cache_dir.s:lash.'.ctrlp_cache' bgneal@0: en bgneal@0: en bgneal@0: endf bgneal@0: cal ctrlp#utils#opts() bgneal@0: " Files and Directories {{{1 bgneal@0: fu! ctrlp#utils#cachedir() bgneal@0: retu s:cache_dir bgneal@0: endf bgneal@0: bgneal@0: fu! ctrlp#utils#cachefile(...) bgneal@0: let tail = exists('a:1') ? '.'.a:1 : '' bgneal@0: let cache_file = substitute(getcwd(), '\([\/]\|^\a\zs:\)', '%', 'g').tail.'.txt' bgneal@0: retu exists('a:1') ? cache_file : s:cache_dir.s:lash.cache_file bgneal@0: endf bgneal@0: bgneal@0: fu! ctrlp#utils#readfile(file) bgneal@0: if filereadable(a:file) bgneal@0: let data = readfile(a:file) bgneal@0: if empty(data) || type(data) != 3 bgneal@0: unl data bgneal@0: let data = [] bgneal@0: en bgneal@0: retu data bgneal@0: en bgneal@0: retu [] bgneal@0: endf bgneal@0: bgneal@0: fu! ctrlp#utils#mkdir(dir) bgneal@0: if exists('*mkdir') && !isdirectory(a:dir) bgneal@0: sil! cal mkdir(a:dir) bgneal@0: en bgneal@0: endf bgneal@0: bgneal@0: fu! ctrlp#utils#writecache(lines, ...) bgneal@0: let cache_dir = exists('a:1') ? a:1 : s:cache_dir bgneal@0: cal ctrlp#utils#mkdir(cache_dir) bgneal@0: if isdirectory(cache_dir) bgneal@0: sil! cal writefile(a:lines, exists('a:2') ? a:2 : ctrlp#utils#cachefile()) bgneal@0: if !exists('a:1') bgneal@0: let g:ctrlp_newcache = 0 bgneal@0: en bgneal@0: en bgneal@0: endf bgneal@0: bgneal@0: fu! ctrlp#utils#glob(...) bgneal@0: retu call('glob', v:version > 701 ? a:000 : a:1) bgneal@0: endf bgneal@0: "}}} bgneal@0: bgneal@0: " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2