annotate vendor/vim-packs/ctrlp.vim/autoload/ctrlp/utils.vim @ 723:440e800e9be0

Merge
author nanaya <me@nanaya.net>
date Mon, 19 Aug 2024 17:05:46 +0900
parents 4576f1471f53
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
707
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
1 " =============================================================================
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
2 " File: autoload/ctrlp/utils.vim
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
3 " Description: Utilities
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
4 " Author: Kien Nguyen <github.com/kien>
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
5 " =============================================================================
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
6
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
7 " Static variables {{{1
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
8 fu! ctrlp#utils#lash()
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
9 retu &ssl || !exists('+ssl') ? '/' : '\'
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
10 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
11
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
12 fu! s:lash(...)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
13 retu ( a:0 ? a:1 : getcwd() ) !~ '[\/]$' ? s:lash : ''
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
14 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
15
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
16 fu! ctrlp#utils#opts()
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
17 let s:lash = ctrlp#utils#lash()
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
18 let usrhome = $HOME . s:lash( $HOME )
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
19 let cahome = exists('$XDG_CACHE_HOME') ? $XDG_CACHE_HOME : usrhome.'.cache'
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
20 let cadir = isdirectory(usrhome.'.ctrlp_cache')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
21 \ ? usrhome.'.ctrlp_cache' : cahome.s:lash(cahome).'ctrlp'
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
22 if exists('g:ctrlp_cache_dir')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
23 let cadir = expand(g:ctrlp_cache_dir, 1)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
24 if isdirectory(cadir.s:lash(cadir).'.ctrlp_cache')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
25 let cadir = cadir.s:lash(cadir).'.ctrlp_cache'
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
26 en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
27 en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
28 let s:cache_dir = cadir
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
29 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
30 cal ctrlp#utils#opts()
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
31
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
32 let s:wig_cond = v:version > 702 || ( v:version == 702 && has('patch051') )
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
33 " Files and Directories {{{1
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
34 fu! ctrlp#utils#cachedir()
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
35 retu s:cache_dir
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
36 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
37
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
38 fu! ctrlp#utils#cachefile(...)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
39 let [tail, dir] = [a:0 == 1 ? '.'.a:1 : '', a:0 == 2 ? a:1 : getcwd()]
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
40 let cache_file = substitute(dir, '\([\/]\|^\a\zs:\)', '%', 'g').tail.'.txt'
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
41 retu a:0 == 1 ? cache_file : s:cache_dir.s:lash(s:cache_dir).cache_file
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
42 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
43
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
44 fu! ctrlp#utils#readfile(file)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
45 if filereadable(a:file)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
46 let data = readfile(a:file)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
47 if empty(data) || type(data) != 3
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
48 unl data
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
49 let data = []
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
50 en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
51 retu data
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
52 en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
53 retu []
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
54 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
55
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
56 fu! ctrlp#utils#mkdir(dir)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
57 if exists('*mkdir') && !isdirectory(a:dir)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
58 sil! cal mkdir(a:dir, 'p')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
59 en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
60 retu a:dir
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
61 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
62
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
63 fu! ctrlp#utils#writecache(lines, ...)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
64 if isdirectory(ctrlp#utils#mkdir(a:0 ? a:1 : s:cache_dir))
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
65 sil! cal writefile(a:lines, a:0 >= 2 ? a:2 : ctrlp#utils#cachefile())
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
66 en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
67 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
68
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
69 fu! ctrlp#utils#glob(...)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
70 let path = ctrlp#utils#fnesc(a:1, 'g')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
71 retu s:wig_cond ? glob(path, a:2) : glob(path)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
72 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
73
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
74 fu! ctrlp#utils#globpath(...)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
75 retu call('globpath', s:wig_cond ? a:000 : a:000[:1])
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
76 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
77
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
78 if exists('*fnameescape')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
79 if exists('+ssl')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
80 fu! ctrlp#utils#fnesc(path, type, ...)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
81 if a:type == 'c'
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
82 let path = escape(a:path, '%#')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
83 elsei a:type == 'f'
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
84 let path = fnameescape(a:path)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
85 elsei a:type == 'g'
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
86 let path = escape(a:path, '?*')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
87 en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
88 let path = substitute(path, '[', '[[]', 'g')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
89 retu a:0 ? escape(path, a:1) : path
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
90 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
91 el
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
92 fu! ctrlp#utils#fnesc(path, type, ...)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
93 let path = fnameescape(a:path)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
94 retu a:0 ? escape(path, a:1) : path
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
95 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
96 en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
97 el
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
98 if exists('+ssl')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
99 fu! ctrlp#utils#fnesc(path, type, ...)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
100 if a:type == 'c'
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
101 let path = escape(a:path, '%#')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
102 elsei a:type == 'f'
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
103 let path = escape(a:path, " \t\n%#*?|<\"")
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
104 elsei a:type == 'g'
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
105 let path = escape(a:path, '?*')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
106 en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
107 let path = substitute(path, '[', '[[]', 'g')
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
108 retu a:0 ? escape(path, a:1) : path
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
109 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
110 el
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
111 fu! ctrlp#utils#fnesc(path, type, ...)
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
112 let path = escape(a:path, " \t\n*?[{`$\\%#'\"|!<")
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
113 retu a:0 ? escape(path, a:1) : path
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
114 endf
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
115 en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
116 en
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
117 "}}}
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
118
4576f1471f53 [update-vendor, vim] add ctrlp
nanaya <me@nanaya.net>
parents:
diff changeset
119 " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2