2011-11-30 04:42:19 -05:00
|
|
|
" =============================================================================
|
|
|
|
" File: autoload/ctrlp/dir.vim
|
2011-12-13 09:42:57 -05:00
|
|
|
" Description: Directory extension
|
2011-11-30 04:42:19 -05:00
|
|
|
" Author: Kien Nguyen <github.com/kien>
|
|
|
|
" =============================================================================
|
|
|
|
|
2011-12-02 22:54:18 -05:00
|
|
|
" Init {{{1
|
2011-11-30 04:42:19 -05:00
|
|
|
if exists('g:loaded_ctrlp_dir') && g:loaded_ctrlp_dir
|
|
|
|
fini
|
|
|
|
en
|
|
|
|
let [g:loaded_ctrlp_dir, g:ctrlp_newdir] = [1, 0]
|
|
|
|
|
|
|
|
let s:ars = [
|
|
|
|
\ 's:maxdepth',
|
|
|
|
\ 's:maxfiles',
|
|
|
|
\ 's:compare_lim',
|
2012-01-19 06:33:59 -05:00
|
|
|
\ 's:glob',
|
2011-11-30 04:42:19 -05:00
|
|
|
\ ]
|
|
|
|
|
2012-01-15 12:42:14 -05:00
|
|
|
let s:dir_var = {
|
|
|
|
\ 'init': 'ctrlp#dir#init('.join(s:ars, ', ').')',
|
|
|
|
\ 'accept': 'ctrlp#dir#accept',
|
|
|
|
\ 'lname': 'dirs',
|
|
|
|
\ 'sname': 'dir',
|
|
|
|
\ 'type': 'path',
|
2012-04-02 11:06:32 -04:00
|
|
|
\ 'specinput': 1,
|
2012-01-15 12:42:14 -05:00
|
|
|
\ }
|
2011-11-30 04:42:19 -05:00
|
|
|
|
|
|
|
let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
|
|
|
|
\ ? add(g:ctrlp_ext_vars, s:dir_var) : [s:dir_var]
|
|
|
|
|
|
|
|
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
|
2011-12-02 22:54:18 -05:00
|
|
|
" Utilities {{{1
|
2011-11-30 04:42:19 -05:00
|
|
|
fu! s:globdirs(dirs, depth)
|
2012-01-19 06:33:59 -05:00
|
|
|
let entries = split(globpath(a:dirs, s:glob), "\n")
|
2011-12-21 00:12:33 -05:00
|
|
|
let [dirs, depth] = [ctrlp#dirnfile(entries)[0], a:depth + 1]
|
|
|
|
cal extend(g:ctrlp_alldirs, dirs)
|
|
|
|
if !empty(dirs) && !s:max(len(g:ctrlp_alldirs), s:maxfiles)
|
2011-11-30 04:42:19 -05:00
|
|
|
\ && depth <= s:maxdepth
|
|
|
|
sil! cal ctrlp#progress(len(g:ctrlp_alldirs))
|
2011-12-21 00:12:33 -05:00
|
|
|
cal s:globdirs(join(dirs, ','), depth)
|
2011-11-30 04:42:19 -05:00
|
|
|
en
|
|
|
|
endf
|
|
|
|
|
|
|
|
fu! s:max(len, max)
|
|
|
|
retu a:max && a:len > a:max ? 1 : 0
|
|
|
|
endf
|
2011-12-02 22:54:18 -05:00
|
|
|
" Public {{{1
|
2011-11-30 04:42:19 -05:00
|
|
|
fu! ctrlp#dir#init(...)
|
|
|
|
let s:cwd = getcwd()
|
|
|
|
for each in range(len(s:ars))
|
|
|
|
exe 'let' s:ars[each] '=' string(eval('a:'.(each + 1)))
|
|
|
|
endfo
|
2012-01-15 12:42:14 -05:00
|
|
|
let cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().s:dir_var['sname']
|
|
|
|
let cafile = cadir.ctrlp#utils#lash().ctrlp#utils#cachefile(s:dir_var['sname'])
|
2011-11-30 04:42:19 -05:00
|
|
|
if g:ctrlp_newdir || !filereadable(cafile)
|
|
|
|
let g:ctrlp_alldirs = []
|
|
|
|
cal s:globdirs(s:cwd, 0)
|
2011-12-01 04:36:21 -05:00
|
|
|
cal ctrlp#rmbasedir(g:ctrlp_alldirs)
|
2011-11-30 04:42:19 -05:00
|
|
|
let read_cache = 0
|
2012-01-29 20:54:06 -05:00
|
|
|
if len(g:ctrlp_alldirs) <= s:compare_lim
|
|
|
|
cal sort(g:ctrlp_alldirs, 'ctrlp#complen')
|
|
|
|
en
|
2011-11-30 04:42:19 -05:00
|
|
|
el
|
|
|
|
let g:ctrlp_alldirs = ctrlp#utils#readfile(cafile)
|
|
|
|
let read_cache = 1
|
|
|
|
en
|
|
|
|
if !read_cache
|
|
|
|
cal ctrlp#utils#writecache(g:ctrlp_alldirs, cadir, cafile)
|
|
|
|
let g:ctrlp_newdir = 0
|
|
|
|
en
|
|
|
|
retu g:ctrlp_alldirs
|
|
|
|
endf
|
|
|
|
|
|
|
|
fu! ctrlp#dir#accept(mode, str)
|
2011-12-01 04:36:21 -05:00
|
|
|
let path = a:mode == 'h' ? getcwd() : s:cwd.ctrlp#utils#lash().a:str
|
|
|
|
if a:mode =~ 't\|v\|h'
|
|
|
|
cal ctrlp#exit()
|
|
|
|
en
|
|
|
|
cal ctrlp#setdir(path, a:mode =~ 't\|h' ? 'chd!' : 'lc!')
|
|
|
|
if a:mode == 'e'
|
|
|
|
sil! cal ctrlp#statusline()
|
|
|
|
cal ctrlp#setlines(s:id)
|
|
|
|
cal ctrlp#recordhist()
|
|
|
|
cal ctrlp#prtclear()
|
|
|
|
en
|
2011-11-30 04:42:19 -05:00
|
|
|
endf
|
|
|
|
|
|
|
|
fu! ctrlp#dir#id()
|
|
|
|
retu s:id
|
|
|
|
endf
|
|
|
|
"}}}
|
|
|
|
|
2011-12-02 22:54:18 -05:00
|
|
|
" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2
|