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