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