bgneal@0: " ============================================================================= bgneal@0: " File: autoload/ctrlp/dir.vim bgneal@0: " Description: Directory extension bgneal@0: " Author: Kien Nguyen bgneal@0: " ============================================================================= bgneal@0: bgneal@0: " Init {{{1 bgneal@0: if exists('g:loaded_ctrlp_dir') && g:loaded_ctrlp_dir bgneal@0: fini bgneal@0: en bgneal@0: let [g:loaded_ctrlp_dir, g:ctrlp_newdir] = [1, 0] bgneal@0: bgneal@0: let s:ars = [ bgneal@0: \ 's:maxdepth', bgneal@0: \ 's:maxfiles', bgneal@0: \ 's:compare_lim', bgneal@0: \ 's:glob', bgneal@3: \ 's:usrign', bgneal@0: \ ] bgneal@0: bgneal@0: let s:dir_var = ['ctrlp#dir#init('.join(s:ars, ', ').')', 'ctrlp#dir#accept', bgneal@0: \ 'dirs', 'dir'] bgneal@0: bgneal@0: let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars) bgneal@0: \ ? add(g:ctrlp_ext_vars, s:dir_var) : [s:dir_var] bgneal@0: bgneal@0: let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) bgneal@0: " Utilities {{{1 bgneal@0: fu! s:globdirs(dirs, depth) bgneal@0: let entries = split(globpath(a:dirs, s:glob), "\n") bgneal@3: if s:usrign != '' bgneal@3: cal filter(entries, 'v:val !~ s:usrign') bgneal@0: en bgneal@3: let [dirs, depth] = [ctrlp#dirnfile(entries)[0], a:depth + 1] bgneal@3: cal extend(g:ctrlp_alldirs, dirs) bgneal@3: if !empty(dirs) && !s:max(len(g:ctrlp_alldirs), s:maxfiles) bgneal@0: \ && depth <= s:maxdepth bgneal@0: sil! cal ctrlp#progress(len(g:ctrlp_alldirs)) bgneal@3: cal s:globdirs(join(dirs, ','), depth) bgneal@0: en bgneal@0: endf bgneal@0: bgneal@0: fu! s:max(len, max) bgneal@0: retu a:max && a:len > a:max ? 1 : 0 bgneal@0: endf bgneal@0: " Public {{{1 bgneal@0: fu! ctrlp#dir#init(...) bgneal@0: let s:cwd = getcwd() bgneal@0: for each in range(len(s:ars)) bgneal@0: exe 'let' s:ars[each] '=' string(eval('a:'.(each + 1))) bgneal@0: endfo bgneal@0: let cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().s:dir_var[3] bgneal@0: let cafile = cadir.ctrlp#utils#lash().ctrlp#utils#cachefile(s:dir_var[3]) bgneal@0: if g:ctrlp_newdir || !filereadable(cafile) bgneal@0: let g:ctrlp_alldirs = [] bgneal@0: cal s:globdirs(s:cwd, 0) bgneal@0: cal ctrlp#rmbasedir(g:ctrlp_alldirs) bgneal@0: let read_cache = 0 bgneal@0: el bgneal@0: let g:ctrlp_alldirs = ctrlp#utils#readfile(cafile) bgneal@0: let read_cache = 1 bgneal@0: en bgneal@0: if len(g:ctrlp_alldirs) <= s:compare_lim bgneal@0: cal sort(g:ctrlp_alldirs, 'ctrlp#complen') bgneal@0: en bgneal@0: if !read_cache bgneal@0: cal ctrlp#utils#writecache(g:ctrlp_alldirs, cadir, cafile) bgneal@0: let g:ctrlp_newdir = 0 bgneal@0: en bgneal@0: retu g:ctrlp_alldirs bgneal@0: endf bgneal@0: bgneal@0: fu! ctrlp#dir#accept(mode, str) bgneal@0: let path = a:mode == 'h' ? getcwd() : s:cwd.ctrlp#utils#lash().a:str bgneal@0: if a:mode =~ 't\|v\|h' bgneal@0: cal ctrlp#exit() bgneal@0: en bgneal@0: cal ctrlp#setdir(path, a:mode =~ 't\|h' ? 'chd!' : 'lc!') bgneal@0: if a:mode == 'e' bgneal@0: sil! cal ctrlp#statusline() bgneal@0: cal ctrlp#setlines(s:id) bgneal@0: cal ctrlp#recordhist() bgneal@0: cal ctrlp#prtclear() bgneal@0: en bgneal@0: endf bgneal@0: bgneal@0: fu! ctrlp#dir#id() bgneal@0: retu s:id bgneal@0: endf bgneal@0: "}}} bgneal@0: bgneal@0: " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2