425
|
1 " pathogen.vim - path option manipulation
|
|
2 " Maintainer: Tim Pope <http://tpo.pe/>
|
589
|
3 " Version: 2.4
|
425
|
4
|
|
5 " Install in ~/.vim/autoload (or ~\vimfiles\autoload).
|
|
6 "
|
|
7 " For management of individually installed plugins in ~/.vim/bundle (or
|
569
|
8 " ~\vimfiles\bundle), adding `execute pathogen#infect()` to the top of your
|
425
|
9 " .vimrc is the only other setup necessary.
|
|
10 "
|
569
|
11 " The API is documented inline below.
|
425
|
12
|
|
13 if exists("g:loaded_pathogen") || &cp
|
|
14 finish
|
|
15 endif
|
|
16 let g:loaded_pathogen = 1
|
|
17
|
569
|
18 " Point of entry for basic default usage. Give a relative path to invoke
|
|
19 " pathogen#interpose() (defaults to "bundle/{}"), or an absolute path to invoke
|
|
20 " pathogen#surround(). Curly braces are expanded with pathogen#expand():
|
|
21 " "bundle/{}" finds all subdirectories inside "bundle" inside all directories
|
|
22 " in the runtime path.
|
|
23 function! pathogen#infect(...) abort
|
|
24 for path in a:0 ? filter(reverse(copy(a:000)), 'type(v:val) == type("")') : ['bundle/{}']
|
|
25 if path =~# '^\%({\=[$~\\/]\|{\=\w:[\\/]\).*[{}*]'
|
|
26 call pathogen#surround(path)
|
|
27 elseif path =~# '^\%([$~\\/]\|\w:[\\/]\)'
|
|
28 call s:warn('Change pathogen#infect('.string(path).') to pathogen#infect('.string(path.'/{}').')')
|
|
29 call pathogen#surround(path . '/{}')
|
|
30 elseif path =~# '[{}*]'
|
|
31 call pathogen#interpose(path)
|
|
32 else
|
|
33 call s:warn('Change pathogen#infect('.string(path).') to pathogen#infect('.string(path.'/{}').')')
|
|
34 call pathogen#interpose(path . '/{}')
|
|
35 endif
|
|
36 endfor
|
|
37 call pathogen#cycle_filetype()
|
|
38 if pathogen#is_disabled($MYVIMRC)
|
|
39 return 'finish'
|
425
|
40 endif
|
569
|
41 return ''
|
|
42 endfunction
|
425
|
43
|
|
44 " Split a path into a list.
|
569
|
45 function! pathogen#split(path) abort
|
425
|
46 if type(a:path) == type([]) | return a:path | endif
|
569
|
47 if empty(a:path) | return [] | endif
|
425
|
48 let split = split(a:path,'\\\@<!\%(\\\\\)*\zs,')
|
|
49 return map(split,'substitute(v:val,''\\\([\\,]\)'',''\1'',"g")')
|
569
|
50 endfunction
|
425
|
51
|
|
52 " Convert a list to a path.
|
569
|
53 function! pathogen#join(...) abort
|
425
|
54 if type(a:1) == type(1) && a:1
|
|
55 let i = 1
|
|
56 let space = ' '
|
|
57 else
|
|
58 let i = 0
|
|
59 let space = ''
|
|
60 endif
|
|
61 let path = ""
|
|
62 while i < a:0
|
|
63 if type(a:000[i]) == type([])
|
|
64 let list = a:000[i]
|
|
65 let j = 0
|
|
66 while j < len(list)
|
|
67 let escaped = substitute(list[j],'[,'.space.']\|\\[\,'.space.']\@=','\\&','g')
|
|
68 let path .= ',' . escaped
|
|
69 let j += 1
|
|
70 endwhile
|
|
71 else
|
|
72 let path .= "," . a:000[i]
|
|
73 endif
|
|
74 let i += 1
|
|
75 endwhile
|
|
76 return substitute(path,'^,','','')
|
569
|
77 endfunction
|
425
|
78
|
|
79 " Convert a list to a path with escaped spaces for 'path', 'tag', etc.
|
569
|
80 function! pathogen#legacyjoin(...) abort
|
425
|
81 return call('pathogen#join',[1] + a:000)
|
569
|
82 endfunction
|
|
83
|
|
84 " Turn filetype detection off and back on again if it was already enabled.
|
|
85 function! pathogen#cycle_filetype() abort
|
|
86 if exists('g:did_load_filetypes')
|
|
87 filetype off
|
|
88 filetype on
|
|
89 endif
|
|
90 endfunction
|
|
91
|
|
92 " Check if a bundle is disabled. A bundle is considered disabled if its
|
589
|
93 " basename or full name is included in the list g:pathogen_blacklist or the
|
|
94 " comma delimited environment variable $VIMBLACKLIST.
|
569
|
95 function! pathogen#is_disabled(path) abort
|
|
96 if a:path =~# '\~$'
|
|
97 return 1
|
|
98 endif
|
|
99 let sep = pathogen#slash()
|
589
|
100 let blacklist =
|
569
|
101 \ get(g:, 'pathogen_blacklist', get(g:, 'pathogen_disabled', [])) +
|
589
|
102 \ pathogen#split($VIMBLACKLIST)
|
|
103 if !empty(blacklist)
|
|
104 call map(blacklist, 'substitute(v:val, "[\\/]$", "", "")')
|
|
105 endif
|
569
|
106 return index(blacklist, fnamemodify(a:path, ':t')) != -1 || index(blacklist, a:path) != -1
|
589
|
107 endfunction
|
569
|
108
|
|
109 " Prepend the given directory to the runtime path and append its corresponding
|
|
110 " after directory. Curly braces are expanded with pathogen#expand().
|
|
111 function! pathogen#surround(path) abort
|
|
112 let sep = pathogen#slash()
|
|
113 let rtp = pathogen#split(&rtp)
|
589
|
114 let path = fnamemodify(a:path, ':s?[\\/]\=$??')
|
569
|
115 let before = filter(pathogen#expand(path), '!pathogen#is_disabled(v:val)')
|
589
|
116 let after = filter(reverse(pathogen#expand(path, sep.'after')), '!pathogen#is_disabled(v:val[0:-7])')
|
569
|
117 call filter(rtp, 'index(before + after, v:val) == -1')
|
|
118 let &rtp = pathogen#join(before, rtp, after)
|
|
119 return &rtp
|
|
120 endfunction
|
|
121
|
|
122 " For each directory in the runtime path, add a second entry with the given
|
|
123 " argument appended. Curly braces are expanded with pathogen#expand().
|
|
124 function! pathogen#interpose(name) abort
|
|
125 let sep = pathogen#slash()
|
|
126 let name = a:name
|
|
127 if has_key(s:done_bundles, name)
|
|
128 return ""
|
|
129 endif
|
|
130 let s:done_bundles[name] = 1
|
|
131 let list = []
|
|
132 for dir in pathogen#split(&rtp)
|
|
133 if dir =~# '\<after$'
|
589
|
134 let list += reverse(filter(pathogen#expand(dir[0:-6].name, sep.'after'), '!pathogen#is_disabled(v:val[0:-7])')) + [dir]
|
569
|
135 else
|
|
136 let list += [dir] + filter(pathogen#expand(dir.sep.name), '!pathogen#is_disabled(v:val)')
|
|
137 endif
|
|
138 endfor
|
|
139 let &rtp = pathogen#join(pathogen#uniq(list))
|
|
140 return 1
|
|
141 endfunction
|
|
142
|
|
143 let s:done_bundles = {}
|
|
144
|
|
145 " Invoke :helptags on all non-$VIM doc directories in runtimepath.
|
|
146 function! pathogen#helptags() abort
|
|
147 let sep = pathogen#slash()
|
|
148 for glob in pathogen#split(&rtp)
|
|
149 for dir in map(split(glob(glob), "\n"), 'v:val.sep."/doc/".sep')
|
|
150 if (dir)[0 : strlen($VIMRUNTIME)] !=# $VIMRUNTIME.sep && filewritable(dir) == 2 && !empty(split(glob(dir.'*.txt'))) && (!filereadable(dir.'tags') || filewritable(dir.'tags'))
|
|
151 silent! execute 'helptags' pathogen#fnameescape(dir)
|
|
152 endif
|
|
153 endfor
|
|
154 endfor
|
|
155 endfunction
|
|
156
|
|
157 command! -bar Helptags :call pathogen#helptags()
|
|
158
|
|
159 " Execute the given command. This is basically a backdoor for --remote-expr.
|
|
160 function! pathogen#execute(...) abort
|
|
161 for command in a:000
|
|
162 execute command
|
|
163 endfor
|
|
164 return ''
|
|
165 endfunction
|
|
166
|
|
167 " Section: Unofficial
|
|
168
|
|
169 function! pathogen#is_absolute(path) abort
|
|
170 return a:path =~# (has('win32') ? '^\%([\\/]\|\w:\)[\\/]\|^[~$]' : '^[/~$]')
|
|
171 endfunction
|
|
172
|
|
173 " Given a string, returns all possible permutations of comma delimited braced
|
|
174 " alternatives of that string. pathogen#expand('/{a,b}/{c,d}') yields
|
|
175 " ['/a/c', '/a/d', '/b/c', '/b/d']. Empty braces are treated as a wildcard
|
|
176 " and globbed. Actual globs are preserved.
|
589
|
177 function! pathogen#expand(pattern, ...) abort
|
|
178 let after = a:0 ? a:1 : ''
|
569
|
179 if a:pattern =~# '{[^{}]\+}'
|
|
180 let [pre, pat, post] = split(substitute(a:pattern, '\(.\{-\}\){\([^{}]\+\)}\(.*\)', "\\1\001\\2\001\\3", ''), "\001", 1)
|
|
181 let found = map(split(pat, ',', 1), 'pre.v:val.post')
|
|
182 let results = []
|
|
183 for pattern in found
|
|
184 call extend(results, pathogen#expand(pattern))
|
|
185 endfor
|
|
186 elseif a:pattern =~# '{}'
|
|
187 let pat = matchstr(a:pattern, '^.*{}[^*]*\%($\|[\\/]\)')
|
|
188 let post = a:pattern[strlen(pat) : -1]
|
589
|
189 let results = map(split(glob(substitute(pat, '{}', '*', 'g')), "\n"), 'v:val.post')
|
569
|
190 else
|
589
|
191 let results = [a:pattern]
|
569
|
192 endif
|
589
|
193 let vf = pathogen#slash() . 'vimfiles'
|
|
194 call map(results, 'v:val =~# "\\*" ? v:val.after : isdirectory(v:val.vf.after) ? v:val.vf.after : isdirectory(v:val.after) ? v:val.after : ""')
|
|
195 return filter(results, '!empty(v:val)')
|
569
|
196 endfunction
|
|
197
|
|
198 " \ on Windows unless shellslash is set, / everywhere else.
|
|
199 function! pathogen#slash() abort
|
|
200 return !exists("+shellslash") || &shellslash ? '/' : '\'
|
|
201 endfunction
|
|
202
|
|
203 function! pathogen#separator() abort
|
|
204 return pathogen#slash()
|
|
205 endfunction
|
|
206
|
|
207 " Convenience wrapper around glob() which returns a list.
|
|
208 function! pathogen#glob(pattern) abort
|
|
209 let files = split(glob(a:pattern),"\n")
|
|
210 return map(files,'substitute(v:val,"[".pathogen#slash()."/]$","","")')
|
589
|
211 endfunction
|
569
|
212
|
|
213 " Like pathogen#glob(), only limit the results to directories.
|
|
214 function! pathogen#glob_directories(pattern) abort
|
|
215 return filter(pathogen#glob(a:pattern),'isdirectory(v:val)')
|
589
|
216 endfunction
|
425
|
217
|
|
218 " Remove duplicates from a list.
|
569
|
219 function! pathogen#uniq(list) abort
|
425
|
220 let i = 0
|
|
221 let seen = {}
|
|
222 while i < len(a:list)
|
|
223 if (a:list[i] ==# '' && exists('empty')) || has_key(seen,a:list[i])
|
|
224 call remove(a:list,i)
|
|
225 elseif a:list[i] ==# ''
|
|
226 let i += 1
|
|
227 let empty = 1
|
|
228 else
|
|
229 let seen[a:list[i]] = 1
|
|
230 let i += 1
|
|
231 endif
|
|
232 endwhile
|
|
233 return a:list
|
|
234 endfunction
|
|
235
|
569
|
236 " Backport of fnameescape().
|
|
237 function! pathogen#fnameescape(string) abort
|
|
238 if exists('*fnameescape')
|
|
239 return fnameescape(a:string)
|
|
240 elseif a:string ==# '-'
|
|
241 return '\-'
|
|
242 else
|
|
243 return substitute(escape(a:string," \t\n*?[{`$\\%#'\"|!<"),'^[+>]','\\&','')
|
|
244 endif
|
|
245 endfunction
|
425
|
246
|
|
247 " Like findfile(), but hardcoded to use the runtimepath.
|
589
|
248 function! pathogen#runtime_findfile(file,count) abort
|
425
|
249 let rtp = pathogen#join(1,pathogen#split(&rtp))
|
|
250 let file = findfile(a:file,rtp,a:count)
|
|
251 if file ==# ''
|
|
252 return ''
|
|
253 else
|
|
254 return fnamemodify(file,':p')
|
|
255 endif
|
569
|
256 endfunction
|
|
257
|
|
258 " Section: Deprecated
|
|
259
|
|
260 function! s:warn(msg) abort
|
|
261 echohl WarningMsg
|
|
262 echomsg a:msg
|
|
263 echohl NONE
|
|
264 endfunction
|
425
|
265
|
569
|
266 " Prepend all subdirectories of path to the rtp, and append all 'after'
|
|
267 " directories in those subdirectories. Deprecated.
|
|
268 function! pathogen#runtime_prepend_subdirectories(path) abort
|
|
269 call s:warn('Change pathogen#runtime_prepend_subdirectories('.string(a:path).') to pathogen#infect('.string(a:path.'/{}').')')
|
|
270 return pathogen#surround(a:path . pathogen#slash() . '{}')
|
|
271 endfunction
|
|
272
|
|
273 function! pathogen#incubate(...) abort
|
|
274 let name = a:0 ? a:1 : 'bundle/{}'
|
|
275 call s:warn('Change pathogen#incubate('.(a:0 ? string(a:1) : '').') to pathogen#infect('.string(name).')')
|
|
276 return pathogen#interpose(name)
|
|
277 endfunction
|
|
278
|
|
279 " Deprecated alias for pathogen#interpose().
|
|
280 function! pathogen#runtime_append_all_bundles(...) abort
|
|
281 if a:0
|
|
282 call s:warn('Change pathogen#runtime_append_all_bundles('.string(a:1).') to pathogen#infect('.string(a:1.'/{}').')')
|
425
|
283 else
|
569
|
284 call s:warn('Change pathogen#runtime_append_all_bundles() to pathogen#infect()')
|
425
|
285 endif
|
569
|
286 return pathogen#interpose(a:0 ? a:1 . '/{}' : 'bundle/{}')
|
|
287 endfunction
|
425
|
288
|
569
|
289 " vim:set et sw=2 foldmethod=expr foldexpr=getline(v\:lnum)=~'^\"\ Section\:'?'>1'\:getline(v\:lnum)=~#'^fu'?'a1'\:getline(v\:lnum)=~#'^endf'?'s1'\:'=':
|