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-12-02 22:54:18 -05:00
|
|
|
" Static variables {{{1
|
2011-11-14 01:58:09 -05:00
|
|
|
fu! ctrlp#utils#lash()
|
|
|
|
retu &ssl || !exists('+ssl') ? '/' : '\'
|
|
|
|
endf
|
|
|
|
let s:lash = ctrlp#utils#lash()
|
|
|
|
|
2012-01-18 12:58:15 -05:00
|
|
|
fu! s:lash(...)
|
|
|
|
retu match(a:0 ? a:1 : getcwd(), '[\/]$') < 0 ? s:lash : ''
|
|
|
|
endf
|
|
|
|
|
2011-11-04 03:29:10 -04:00
|
|
|
fu! ctrlp#utils#opts()
|
2012-01-22 10:51:08 -05:00
|
|
|
let usrhome = $HOME.s:lash($HOME)
|
|
|
|
let cahome = exists('$XDG_CACHE_HOME') ? $XDG_CACHE_HOME : usrhome.'.cache'
|
|
|
|
let s:cache_dir = isdirectory(usrhome.'.ctrlp_cache')
|
|
|
|
\ ? usrhome.'.ctrlp_cache' : cahome.s:lash(cahome).'ctrlp'
|
2011-11-14 04:00:44 -05:00
|
|
|
if exists('g:ctrlp_cache_dir')
|
|
|
|
let s:cache_dir = expand(g:ctrlp_cache_dir, 1)
|
2012-01-18 12:58:15 -05:00
|
|
|
if isdirectory(s:cache_dir.s:lash(s:cache_dir).'.ctrlp_cache')
|
|
|
|
let s:cache_dir = s:cache_dir.s:lash(s:cache_dir).'.ctrlp_cache'
|
2011-11-14 04:00:44 -05:00
|
|
|
en
|
|
|
|
en
|
2011-11-04 03:29:10 -04:00
|
|
|
endf
|
2011-09-18 07:33:37 -04:00
|
|
|
cal ctrlp#utils#opts()
|
2011-12-02 22:54:18 -05:00
|
|
|
" Files and Directories {{{1
|
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-28 07:52:28 -05:00
|
|
|
fu! ctrlp#utils#cachefile(...)
|
2012-02-12 06:50:15 -05:00
|
|
|
let tail = a:0 ? '.'.a:1 : ''
|
2011-11-28 07:52:28 -05:00
|
|
|
let cache_file = substitute(getcwd(), '\([\/]\|^\a\zs:\)', '%', 'g').tail.'.txt'
|
2012-02-12 06:50:15 -05:00
|
|
|
retu a:0 ? cache_file : s:cache_dir.s:lash(s:cache_dir).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-12-01 04:36:21 -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)
|
2012-01-26 04:27:01 -05:00
|
|
|
if exists('*mkdir') && !isdirectory(a:dir)
|
2012-01-22 10:51:08 -05:00
|
|
|
sil! cal mkdir(a:dir, 'p')
|
2011-12-01 04:36:21 -05:00
|
|
|
en
|
2012-01-23 21:13:51 -05:00
|
|
|
retu a:dir
|
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, ...)
|
2012-02-12 06:50:15 -05:00
|
|
|
if isdirectory(ctrlp#utils#mkdir(a:0 ? a:1 : s:cache_dir))
|
|
|
|
sil! cal writefile(a:lines, a:0 >= 2 ? a:2 : ctrlp#utils#cachefile())
|
|
|
|
if !a:0
|
2011-12-01 04:36:21 -05:00
|
|
|
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(...)
|
2012-01-18 08:56:18 -05:00
|
|
|
let cond = v:version > 702 || ( v:version == 702 && has('patch051') )
|
|
|
|
retu call('glob', cond ? a:000 : [a:1])
|
2011-11-12 10:00:50 -05:00
|
|
|
endf
|
2011-09-07 10:41:43 -04:00
|
|
|
"}}}
|
|
|
|
|
2011-12-02 22:54:18 -05:00
|
|
|
" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2
|