2011-09-07 10:41:43 -04:00
|
|
|
" =============================================================================
|
|
|
|
" File: autoload/ctrlp/utils.vim
|
|
|
|
" Description: Utility functions
|
|
|
|
" Author: Kien Nguyen <github.com/kien>
|
|
|
|
" =============================================================================
|
|
|
|
|
2011-11-04 03:29:10 -04:00
|
|
|
" Static variables {{{
|
|
|
|
fu! ctrlp#utils#opts()
|
|
|
|
let s:cache_dir = exists('g:ctrlp_cache_dir') ? g:ctrlp_cache_dir : $HOME
|
|
|
|
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-09-07 10:41:43 -04:00
|
|
|
retu exists('*mkdir') ? s:cache_dir.ctrlp#utils#lash().'.ctrlp_cache' : 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'
|
|
|
|
retu ctrlp#utils#cachedir().ctrlp#utils#lash().cache_file
|
|
|
|
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)
|
|
|
|
if empty(data) || type(data) != 3
|
2011-09-07 17:01:08 -04:00
|
|
|
unl data | let data = []
|
2011-11-04 03:29:10 -04:00
|
|
|
en
|
2011-09-07 10:41:43 -04:00
|
|
|
retu data
|
2011-11-04 03:29:10 -04:00
|
|
|
el
|
2011-09-07 10:41:43 -04:00
|
|
|
retu []
|
2011-11-04 03:29:10 -04:00
|
|
|
en
|
|
|
|
endf
|
2011-09-07 10:41:43 -04:00
|
|
|
|
2011-11-04 03:29:10 -04:00
|
|
|
fu! ctrlp#utils#mkdir(dir)
|
2011-09-07 10:41:43 -04:00
|
|
|
if exists('*mkdir') && !isdirectory(a:dir)
|
|
|
|
sil! cal mkdir(a:dir)
|
2011-11-04 03:29:10 -04:00
|
|
|
en
|
|
|
|
endf
|
2011-09-07 10:41:43 -04:00
|
|
|
|
2011-11-04 03:29:10 -04:00
|
|
|
fu! ctrlp#utils#writecache(lines,...)
|
|
|
|
let cache_dir = exists('a:1') ? a:1 : ctrlp#utils#cachedir()
|
2011-09-07 10:41:43 -04:00
|
|
|
cal ctrlp#utils#mkdir(cache_dir)
|
|
|
|
" write cache
|
|
|
|
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-09-07 10:41:43 -04:00
|
|
|
if !exists('a:1') || !exists('a:2')
|
|
|
|
let g:ctrlp_newcache = 0
|
2011-11-04 03:29:10 -04:00
|
|
|
en
|
|
|
|
en
|
|
|
|
endf
|
2011-09-07 10:41:43 -04:00
|
|
|
|
2011-11-04 03:29:10 -04:00
|
|
|
fu! ctrlp#utils#lash()
|
2011-09-07 10:41:43 -04:00
|
|
|
retu &ssl || !exists('+ssl') ? '/' : '\'
|
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
|
|
|
" vim:fen:fdl=0:fdc=1:ts=2:sw=2:sts=2
|