comparison vendor/vim-packs/ctrlp.vim/autoload/ctrlp/mixed.vim @ 707:4576f1471f53

[update-vendor, vim] add ctrlp
author nanaya <me@nanaya.net>
date Sun, 18 Dec 2022 22:27:56 +0900
parents
children
comparison
equal deleted inserted replaced
706:4b30df382167 707:4576f1471f53
1 " =============================================================================
2 " File: autoload/ctrlp/mixed.vim
3 " Description: Mixing Files + MRU + Buffers
4 " Author: Kien Nguyen <github.com/kien>
5 " =============================================================================
6
7 " Init {{{1
8 if exists('g:loaded_ctrlp_mixed') && g:loaded_ctrlp_mixed
9 fini
10 en
11 let [g:loaded_ctrlp_mixed, g:ctrlp_newmix] = [1, 0]
12
13 cal add(g:ctrlp_ext_vars, {
14 \ 'init': 'ctrlp#mixed#init(s:compare_lim)',
15 \ 'accept': 'ctrlp#acceptfile',
16 \ 'lname': 'fil + mru + buf',
17 \ 'sname': 'mix',
18 \ 'type': 'path',
19 \ 'opmul': 1,
20 \ 'specinput': 1,
21 \ })
22
23 let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
24 " Utilities {{{1
25 fu! s:newcache(cwd)
26 if g:ctrlp_newmix || !has_key(g:ctrlp_allmixes, 'data') | retu 1 | en
27 retu g:ctrlp_allmixes['cwd'] != a:cwd
28 \ || g:ctrlp_allmixes['filtime'] < getftime(ctrlp#utils#cachefile())
29 \ || g:ctrlp_allmixes['mrutime'] < getftime(ctrlp#mrufiles#cachefile())
30 \ || g:ctrlp_allmixes['bufs'] < len(ctrlp#mrufiles#bufs())
31 endf
32
33 fu! s:getnewmix(cwd, clim)
34 if g:ctrlp_newmix
35 cal ctrlp#mrufiles#refresh('raw')
36 let g:ctrlp_newcache = 1
37 en
38 let g:ctrlp_lines = copy(ctrlp#files())
39 cal ctrlp#progress('Mixing...')
40 let mrufs = copy(ctrlp#mrufiles#list('raw'))
41 if exists('+ssl') && &ssl
42 cal map(mrufs, 'tr(v:val, "\\", "/")')
43 en
44 let allbufs = map(ctrlp#buffers(), 'fnamemodify(v:val, ":p")')
45 let [bufs, ubufs] = [[], []]
46 for each in allbufs
47 cal add(filereadable(each) ? bufs : ubufs, each)
48 endfo
49 let mrufs = bufs + filter(mrufs, 'index(bufs, v:val) < 0')
50 if len(mrufs) > len(g:ctrlp_lines)
51 cal filter(mrufs, 'stridx(v:val, a:cwd)')
52 el
53 let cwd_mrufs = filter(copy(mrufs), '!stridx(v:val, a:cwd)')
54 let cwd_mrufs = ctrlp#rmbasedir(cwd_mrufs)
55 for each in cwd_mrufs
56 let id = index(g:ctrlp_lines, each)
57 if id >= 0 | cal remove(g:ctrlp_lines, id) | en
58 endfo
59 en
60 let mrufs += ubufs
61 cal map(mrufs, 'fnamemodify(v:val, ":.")')
62 let g:ctrlp_lines = len(mrufs) > len(g:ctrlp_lines)
63 \ ? g:ctrlp_lines + mrufs : mrufs + g:ctrlp_lines
64 if len(g:ctrlp_lines) <= a:clim
65 cal sort(g:ctrlp_lines, 'ctrlp#complen')
66 en
67 let g:ctrlp_allmixes = { 'filtime': getftime(ctrlp#utils#cachefile()),
68 \ 'mrutime': getftime(ctrlp#mrufiles#cachefile()), 'cwd': a:cwd,
69 \ 'bufs': len(ctrlp#mrufiles#bufs()), 'data': g:ctrlp_lines }
70 endf
71 " Public {{{1
72 fu! ctrlp#mixed#init(clim)
73 let cwd = getcwd()
74 if s:newcache(cwd)
75 cal s:getnewmix(cwd, a:clim)
76 el
77 let g:ctrlp_lines = g:ctrlp_allmixes['data']
78 en
79 let g:ctrlp_newmix = 0
80 retu g:ctrlp_lines
81 endf
82
83 fu! ctrlp#mixed#id()
84 retu s:id
85 endf
86 "}}}
87
88 " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2