707
|
1 " =============================================================================
|
|
2 " File: autoload/ctrlp/rtscript.vim
|
|
3 " Description: Runtime scripts extension
|
|
4 " Author: Kien Nguyen <github.com/kien>
|
|
5 " =============================================================================
|
|
6
|
|
7 " Init {{{1
|
|
8 if exists('g:loaded_ctrlp_rtscript') && g:loaded_ctrlp_rtscript
|
|
9 fini
|
|
10 en
|
|
11 let [g:loaded_ctrlp_rtscript, g:ctrlp_newrts] = [1, 0]
|
|
12
|
|
13 cal add(g:ctrlp_ext_vars, {
|
|
14 \ 'init': 'ctrlp#rtscript#init(s:caching)',
|
|
15 \ 'accept': 'ctrlp#acceptfile',
|
|
16 \ 'lname': 'runtime scripts',
|
|
17 \ 'sname': 'rts',
|
|
18 \ 'type': 'path',
|
|
19 \ 'opmul': 1,
|
|
20 \ })
|
|
21
|
|
22 let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
|
|
23
|
|
24 let s:filecounts = {}
|
|
25 " Utilities {{{1
|
|
26 fu! s:nocache()
|
|
27 retu g:ctrlp_newrts ||
|
|
28 \ !s:caching || ( s:caching > 1 && get(s:filecounts, s:cwd) < s:caching )
|
|
29 endf
|
|
30 " Public {{{1
|
|
31 fu! ctrlp#rtscript#init(caching)
|
|
32 let [s:caching, s:cwd] = [a:caching, getcwd()]
|
|
33 if s:nocache() ||
|
|
34 \ !( exists('g:ctrlp_rtscache') && g:ctrlp_rtscache[0] == &rtp )
|
|
35 sil! cal ctrlp#progress('Indexing...')
|
|
36 let entries = split(globpath(ctrlp#utils#fnesc(&rtp, 'g'), '**/*.*'), "\n")
|
|
37 cal filter(entries, 'count(entries, v:val) == 1')
|
|
38 let [entries, echoed] = [ctrlp#dirnfile(entries)[1], 1]
|
|
39 el
|
|
40 let [entries, results] = g:ctrlp_rtscache[2:3]
|
|
41 en
|
|
42 if s:nocache() ||
|
|
43 \ !( exists('g:ctrlp_rtscache') && g:ctrlp_rtscache[:1] == [&rtp, s:cwd] )
|
|
44 if !exists('echoed')
|
|
45 sil! cal ctrlp#progress('Processing...')
|
|
46 en
|
|
47 let results = map(copy(entries), 'fnamemodify(v:val, '':.'')')
|
|
48 en
|
|
49 let [g:ctrlp_rtscache, g:ctrlp_newrts] = [[&rtp, s:cwd, entries, results], 0]
|
|
50 cal extend(s:filecounts, { s:cwd : len(results) })
|
|
51 retu results
|
|
52 endf
|
|
53
|
|
54 fu! ctrlp#rtscript#id()
|
|
55 retu s:id
|
|
56 endf
|
|
57 "}}}
|
|
58
|
|
59 " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2
|