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