bgneal@0
|
1 " =============================================================================
|
bgneal@0
|
2 " File: autoload/ctrlp/dir.vim
|
bgneal@0
|
3 " Description: Directory extension
|
bgneal@0
|
4 " Author: Kien Nguyen <github.com/kien>
|
bgneal@0
|
5 " =============================================================================
|
bgneal@0
|
6
|
bgneal@0
|
7 " Init {{{1
|
bgneal@0
|
8 if exists('g:loaded_ctrlp_dir') && g:loaded_ctrlp_dir
|
bgneal@0
|
9 fini
|
bgneal@0
|
10 en
|
bgneal@0
|
11 let [g:loaded_ctrlp_dir, g:ctrlp_newdir] = [1, 0]
|
bgneal@0
|
12
|
bgneal@0
|
13 let s:ars = [
|
bgneal@0
|
14 \ 's:maxdepth',
|
bgneal@0
|
15 \ 's:maxfiles',
|
bgneal@0
|
16 \ 's:compare_lim',
|
bgneal@0
|
17 \ 's:glob',
|
bgneal@3
|
18 \ 's:usrign',
|
bgneal@0
|
19 \ ]
|
bgneal@0
|
20
|
bgneal@0
|
21 let s:dir_var = ['ctrlp#dir#init('.join(s:ars, ', ').')', 'ctrlp#dir#accept',
|
bgneal@0
|
22 \ 'dirs', 'dir']
|
bgneal@0
|
23
|
bgneal@0
|
24 let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
|
bgneal@0
|
25 \ ? add(g:ctrlp_ext_vars, s:dir_var) : [s:dir_var]
|
bgneal@0
|
26
|
bgneal@0
|
27 let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
|
bgneal@0
|
28 " Utilities {{{1
|
bgneal@0
|
29 fu! s:globdirs(dirs, depth)
|
bgneal@0
|
30 let entries = split(globpath(a:dirs, s:glob), "\n")
|
bgneal@3
|
31 if s:usrign != ''
|
bgneal@3
|
32 cal filter(entries, 'v:val !~ s:usrign')
|
bgneal@0
|
33 en
|
bgneal@3
|
34 let [dirs, depth] = [ctrlp#dirnfile(entries)[0], a:depth + 1]
|
bgneal@3
|
35 cal extend(g:ctrlp_alldirs, dirs)
|
bgneal@3
|
36 if !empty(dirs) && !s:max(len(g:ctrlp_alldirs), s:maxfiles)
|
bgneal@0
|
37 \ && depth <= s:maxdepth
|
bgneal@0
|
38 sil! cal ctrlp#progress(len(g:ctrlp_alldirs))
|
bgneal@3
|
39 cal s:globdirs(join(dirs, ','), depth)
|
bgneal@0
|
40 en
|
bgneal@0
|
41 endf
|
bgneal@0
|
42
|
bgneal@0
|
43 fu! s:max(len, max)
|
bgneal@0
|
44 retu a:max && a:len > a:max ? 1 : 0
|
bgneal@0
|
45 endf
|
bgneal@0
|
46 " Public {{{1
|
bgneal@0
|
47 fu! ctrlp#dir#init(...)
|
bgneal@0
|
48 let s:cwd = getcwd()
|
bgneal@0
|
49 for each in range(len(s:ars))
|
bgneal@0
|
50 exe 'let' s:ars[each] '=' string(eval('a:'.(each + 1)))
|
bgneal@0
|
51 endfo
|
bgneal@0
|
52 let cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().s:dir_var[3]
|
bgneal@0
|
53 let cafile = cadir.ctrlp#utils#lash().ctrlp#utils#cachefile(s:dir_var[3])
|
bgneal@0
|
54 if g:ctrlp_newdir || !filereadable(cafile)
|
bgneal@0
|
55 let g:ctrlp_alldirs = []
|
bgneal@0
|
56 cal s:globdirs(s:cwd, 0)
|
bgneal@0
|
57 cal ctrlp#rmbasedir(g:ctrlp_alldirs)
|
bgneal@0
|
58 let read_cache = 0
|
bgneal@0
|
59 el
|
bgneal@0
|
60 let g:ctrlp_alldirs = ctrlp#utils#readfile(cafile)
|
bgneal@0
|
61 let read_cache = 1
|
bgneal@0
|
62 en
|
bgneal@0
|
63 if len(g:ctrlp_alldirs) <= s:compare_lim
|
bgneal@0
|
64 cal sort(g:ctrlp_alldirs, 'ctrlp#complen')
|
bgneal@0
|
65 en
|
bgneal@0
|
66 if !read_cache
|
bgneal@0
|
67 cal ctrlp#utils#writecache(g:ctrlp_alldirs, cadir, cafile)
|
bgneal@0
|
68 let g:ctrlp_newdir = 0
|
bgneal@0
|
69 en
|
bgneal@0
|
70 retu g:ctrlp_alldirs
|
bgneal@0
|
71 endf
|
bgneal@0
|
72
|
bgneal@0
|
73 fu! ctrlp#dir#accept(mode, str)
|
bgneal@0
|
74 let path = a:mode == 'h' ? getcwd() : s:cwd.ctrlp#utils#lash().a:str
|
bgneal@0
|
75 if a:mode =~ 't\|v\|h'
|
bgneal@0
|
76 cal ctrlp#exit()
|
bgneal@0
|
77 en
|
bgneal@0
|
78 cal ctrlp#setdir(path, a:mode =~ 't\|h' ? 'chd!' : 'lc!')
|
bgneal@0
|
79 if a:mode == 'e'
|
bgneal@0
|
80 sil! cal ctrlp#statusline()
|
bgneal@0
|
81 cal ctrlp#setlines(s:id)
|
bgneal@0
|
82 cal ctrlp#recordhist()
|
bgneal@0
|
83 cal ctrlp#prtclear()
|
bgneal@0
|
84 en
|
bgneal@0
|
85 endf
|
bgneal@0
|
86
|
bgneal@0
|
87 fu! ctrlp#dir#id()
|
bgneal@0
|
88 retu s:id
|
bgneal@0
|
89 endf
|
bgneal@0
|
90 "}}}
|
bgneal@0
|
91
|
bgneal@0
|
92 " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2
|