2011-09-07 10:41:43 -04:00
|
|
|
" =============================================================================
|
|
|
|
" File: autoload/ctrlp/utils.vim
|
|
|
|
" Description: Utility functions
|
|
|
|
" Author: Kien Nguyen <github.com/kien>
|
|
|
|
" License: MIT
|
|
|
|
" =============================================================================
|
|
|
|
|
|
|
|
if v:version < '700' "{{{
|
|
|
|
fini
|
|
|
|
endif "}}}
|
|
|
|
|
|
|
|
" Option variables {{{
|
2011-09-18 07:33:37 -04:00
|
|
|
func! ctrlp#utils#opts()
|
|
|
|
if !exists('g:ctrlp_cache_dir')
|
|
|
|
let s:cache_dir = $HOME
|
|
|
|
else
|
|
|
|
let s:cache_dir = g:ctrlp_cache_dir
|
|
|
|
endif
|
|
|
|
endfunc
|
|
|
|
cal ctrlp#utils#opts()
|
2011-09-07 10:41:43 -04:00
|
|
|
"}}}
|
|
|
|
|
|
|
|
" Files and Directories functions {{{
|
|
|
|
func! ctrlp#utils#cachedir()
|
|
|
|
retu exists('*mkdir') ? s:cache_dir.ctrlp#utils#lash().'.ctrlp_cache' : s:cache_dir
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func! ctrlp#utils#cachefile()
|
|
|
|
retu ctrlp#utils#cachedir().ctrlp#utils#lash().substitute(getcwd(), '\([\/]\|^\a\zs:\)', '%', 'g').'.txt'
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func! ctrlp#utils#readfile(file)
|
|
|
|
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-09-07 10:41:43 -04:00
|
|
|
endif
|
|
|
|
retu data
|
|
|
|
else
|
|
|
|
retu []
|
|
|
|
endif
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func! ctrlp#utils#mkdir(dir)
|
|
|
|
if exists('*mkdir') && !isdirectory(a:dir)
|
|
|
|
sil! cal mkdir(a:dir)
|
|
|
|
endif
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func! ctrlp#utils#writecache(lines,...)
|
|
|
|
let cache_dir = ctrlp#utils#cachedir()
|
|
|
|
let cache_file = exists('a:2') ? a:2 : ctrlp#utils#cachefile()
|
|
|
|
cal ctrlp#utils#mkdir(cache_dir)
|
|
|
|
if exists('a:1')
|
|
|
|
let cache_dir = a:1
|
|
|
|
cal ctrlp#utils#mkdir(cache_dir)
|
|
|
|
endif
|
|
|
|
" write cache
|
|
|
|
if isdirectory(cache_dir)
|
|
|
|
sil! cal writefile(a:lines, cache_file)
|
|
|
|
if !exists('a:1') || !exists('a:2')
|
|
|
|
let g:ctrlp_newcache = 0
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunc
|
|
|
|
"}}}
|
|
|
|
|
|
|
|
" Generic functions {{{
|
|
|
|
func! ctrlp#utils#lash()
|
|
|
|
retu &ssl || !exists('+ssl') ? '/' : '\'
|
|
|
|
endfunc
|
|
|
|
"}}}
|
|
|
|
|
|
|
|
" vim:fen:fdl=0:ts=2:sw=2:sts=2
|