]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - .vim/autoload/pathogen.vim
.gitignore: Ignore .vim/cache/
[dotfiles.git] / .vim / autoload / pathogen.vim
1 " pathogen.vim - path option manipulation
2 " Maintainer: Tim Pope <http://tpo.pe/>
3 " Version: 2.4
4
5 " Install in ~/.vim/autoload (or ~\vimfiles\autoload).
6 "
7 " For management of individually installed plugins in ~/.vim/bundle (or
8 " ~\vimfiles\bundle), adding `execute pathogen#infect()` to the top of your
9 " .vimrc is the only other setup necessary.
10 "
11 " The API is documented inline below.
12
13 if exists("g:loaded_pathogen") || &cp
14 finish
15 endif
16 let g:loaded_pathogen = 1
17
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'
40 endif
41 return ''
42 endfunction
43
44 " Split a path into a list.
45 function! pathogen#split(path) abort
46 if type(a:path) == type([]) | return a:path | endif
47 if empty(a:path) | return [] | endif
48 let split = split(a:path,'\\\@<!\%(\\\\\)*\zs,')
49 return map(split,'substitute(v:val,''\\\([\\,]\)'',''\1'',"g")')
50 endfunction
51
52 " Convert a list to a path.
53 function! pathogen#join(...) abort
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,'^,','','')
77 endfunction
78
79 " Convert a list to a path with escaped spaces for 'path', 'tag', etc.
80 function! pathogen#legacyjoin(...) abort
81 return call('pathogen#join',[1] + a:000)
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
93 " basename or full name is included in the list g:pathogen_blacklist or the
94 " comma delimited environment variable $VIMBLACKLIST.
95 function! pathogen#is_disabled(path) abort
96 if a:path =~# '\~$'
97 return 1
98 endif
99 let sep = pathogen#slash()
100 let blacklist = map(
101 \ get(g:, 'pathogen_blacklist', get(g:, 'pathogen_disabled', [])) +
102 \ pathogen#split($VIMBLACKLIST),
103 \ 'substitute(v:val, "[\\/]$", "", "")')
104 return index(blacklist, fnamemodify(a:path, ':t')) != -1 || index(blacklist, a:path) != -1
105 endfunction
106
107 " Prepend the given directory to the runtime path and append its corresponding
108 " after directory. Curly braces are expanded with pathogen#expand().
109 function! pathogen#surround(path) abort
110 let sep = pathogen#slash()
111 let rtp = pathogen#split(&rtp)
112 let path = fnamemodify(a:path, ':p:s?[\\/]\=$??')
113 let before = filter(pathogen#expand(path), '!pathogen#is_disabled(v:val)')
114 let after = filter(reverse(pathogen#expand(path, sep.'after')), '!pathogen#is_disabled(v:val[0:-7])')
115 call filter(rtp, 'index(before + after, v:val) == -1')
116 let &rtp = pathogen#join(before, rtp, after)
117 return &rtp
118 endfunction
119
120 " For each directory in the runtime path, add a second entry with the given
121 " argument appended. Curly braces are expanded with pathogen#expand().
122 function! pathogen#interpose(name) abort
123 let sep = pathogen#slash()
124 let name = a:name
125 if has_key(s:done_bundles, name)
126 return ""
127 endif
128 let s:done_bundles[name] = 1
129 let list = []
130 for dir in pathogen#split(&rtp)
131 if dir =~# '\<after$'
132 let list += reverse(filter(pathogen#expand(dir[0:-6].name, sep.'after'), '!pathogen#is_disabled(v:val[0:-7])')) + [dir]
133 else
134 let list += [dir] + filter(pathogen#expand(dir.sep.name), '!pathogen#is_disabled(v:val)')
135 endif
136 endfor
137 let &rtp = pathogen#join(pathogen#uniq(list))
138 return 1
139 endfunction
140
141 let s:done_bundles = {}
142
143 " Invoke :helptags on all non-$VIM doc directories in runtimepath.
144 function! pathogen#helptags() abort
145 let sep = pathogen#slash()
146 for glob in pathogen#split(&rtp)
147 for dir in map(split(glob(glob), "\n"), 'v:val.sep."/doc/".sep')
148 if (dir)[0 : strlen($VIMRUNTIME)] !=# $VIMRUNTIME.sep && filewritable(dir) == 2 && !empty(split(glob(dir.'*.txt'))) && (!filereadable(dir.'tags') || filewritable(dir.'tags'))
149 silent! execute 'helptags' pathogen#fnameescape(dir)
150 endif
151 endfor
152 endfor
153 endfunction
154
155 command! -bar Helptags :call pathogen#helptags()
156
157 " Execute the given command. This is basically a backdoor for --remote-expr.
158 function! pathogen#execute(...) abort
159 for command in a:000
160 execute command
161 endfor
162 return ''
163 endfunction
164
165 " Section: Unofficial
166
167 function! pathogen#is_absolute(path) abort
168 return a:path =~# (has('win32') ? '^\%([\\/]\|\w:\)[\\/]\|^[~$]' : '^[/~$]')
169 endfunction
170
171 " Given a string, returns all possible permutations of comma delimited braced
172 " alternatives of that string. pathogen#expand('/{a,b}/{c,d}') yields
173 " ['/a/c', '/a/d', '/b/c', '/b/d']. Empty braces are treated as a wildcard
174 " and globbed. Actual globs are preserved.
175 function! pathogen#expand(pattern, ...) abort
176 let after = a:0 ? a:1 : ''
177 if a:pattern =~# '{[^{}]\+}'
178 let [pre, pat, post] = split(substitute(a:pattern, '\(.\{-\}\){\([^{}]\+\)}\(.*\)', "\\1\001\\2\001\\3", ''), "\001", 1)
179 let found = map(split(pat, ',', 1), 'pre.v:val.post')
180 let results = []
181 for pattern in found
182 call extend(results, pathogen#expand(pattern))
183 endfor
184 elseif a:pattern =~# '{}'
185 let pat = matchstr(a:pattern, '^.*{}[^*]*\%($\|[\\/]\)')
186 let post = a:pattern[strlen(pat) : -1]
187 let results = map(split(glob(substitute(pat, '{}', '*', 'g')), "\n"), 'v:val.post')
188 else
189 let results = [a:pattern]
190 endif
191 let vf = pathogen#slash() . 'vimfiles'
192 call map(results, 'v:val =~# "\\*" ? v:val.after : isdirectory(v:val.vf.after) ? v:val.vf.after : isdirectory(v:val.after) ? v:val.after : ""')
193 return filter(results, '!empty(v:val)')
194 endfunction
195
196 " \ on Windows unless shellslash is set, / everywhere else.
197 function! pathogen#slash() abort
198 return !exists("+shellslash") || &shellslash ? '/' : '\'
199 endfunction
200
201 function! pathogen#separator() abort
202 return pathogen#slash()
203 endfunction
204
205 " Convenience wrapper around glob() which returns a list.
206 function! pathogen#glob(pattern) abort
207 let files = split(glob(a:pattern),"\n")
208 return map(files,'substitute(v:val,"[".pathogen#slash()."/]$","","")')
209 endfunction
210
211 " Like pathogen#glob(), only limit the results to directories.
212 function! pathogen#glob_directories(pattern) abort
213 return filter(pathogen#glob(a:pattern),'isdirectory(v:val)')
214 endfunction
215
216 " Remove duplicates from a list.
217 function! pathogen#uniq(list) abort
218 let i = 0
219 let seen = {}
220 while i < len(a:list)
221 if (a:list[i] ==# '' && exists('empty')) || has_key(seen,a:list[i])
222 call remove(a:list,i)
223 elseif a:list[i] ==# ''
224 let i += 1
225 let empty = 1
226 else
227 let seen[a:list[i]] = 1
228 let i += 1
229 endif
230 endwhile
231 return a:list
232 endfunction
233
234 " Backport of fnameescape().
235 function! pathogen#fnameescape(string) abort
236 if exists('*fnameescape')
237 return fnameescape(a:string)
238 elseif a:string ==# '-'
239 return '\-'
240 else
241 return substitute(escape(a:string," \t\n*?[{`$\\%#'\"|!<"),'^[+>]','\\&','')
242 endif
243 endfunction
244
245 " Like findfile(), but hardcoded to use the runtimepath.
246 function! pathogen#runtime_findfile(file,count) abort
247 let rtp = pathogen#join(1,pathogen#split(&rtp))
248 let file = findfile(a:file,rtp,a:count)
249 if file ==# ''
250 return ''
251 else
252 return fnamemodify(file,':p')
253 endif
254 endfunction
255
256 " Section: Deprecated
257
258 function! s:warn(msg) abort
259 echohl WarningMsg
260 echomsg a:msg
261 echohl NONE
262 endfunction
263
264 " Prepend all subdirectories of path to the rtp, and append all 'after'
265 " directories in those subdirectories. Deprecated.
266 function! pathogen#runtime_prepend_subdirectories(path) abort
267 call s:warn('Change pathogen#runtime_prepend_subdirectories('.string(a:path).') to pathogen#infect('.string(a:path.'/{}').')')
268 return pathogen#surround(a:path . pathogen#slash() . '{}')
269 endfunction
270
271 function! pathogen#incubate(...) abort
272 let name = a:0 ? a:1 : 'bundle/{}'
273 call s:warn('Change pathogen#incubate('.(a:0 ? string(a:1) : '').') to pathogen#infect('.string(name).')')
274 return pathogen#interpose(name)
275 endfunction
276
277 " Deprecated alias for pathogen#interpose().
278 function! pathogen#runtime_append_all_bundles(...) abort
279 if a:0
280 call s:warn('Change pathogen#runtime_append_all_bundles('.string(a:1).') to pathogen#infect('.string(a:1.'/{}').')')
281 else
282 call s:warn('Change pathogen#runtime_append_all_bundles() to pathogen#infect()')
283 endif
284 return pathogen#interpose(a:0 ? a:1 . '/{}' : 'bundle/{}')
285 endfunction
286
287 if exists(':Vedit')
288 finish
289 endif
290
291 let s:vopen_warning = 0
292
293 function! s:find(count,cmd,file,lcd)
294 let rtp = pathogen#join(1,pathogen#split(&runtimepath))
295 let file = pathogen#runtime_findfile(a:file,a:count)
296 if file ==# ''
297 return "echoerr 'E345: Can''t find file \"".a:file."\" in runtimepath'"
298 endif
299 if !s:vopen_warning
300 let s:vopen_warning = 1
301 let warning = '|echohl WarningMsg|echo "Install scriptease.vim to continue using :V'.a:cmd.'"|echohl NONE'
302 else
303 let warning = ''
304 endif
305 if a:lcd
306 let path = file[0:-strlen(a:file)-2]
307 execute 'lcd `=path`'
308 return a:cmd.' '.pathogen#fnameescape(a:file) . warning
309 else
310 return a:cmd.' '.pathogen#fnameescape(file) . warning
311 endif
312 endfunction
313
314 function! s:Findcomplete(A,L,P)
315 let sep = pathogen#slash()
316 let cheats = {
317 \'a': 'autoload',
318 \'d': 'doc',
319 \'f': 'ftplugin',
320 \'i': 'indent',
321 \'p': 'plugin',
322 \'s': 'syntax'}
323 if a:A =~# '^\w[\\/]' && has_key(cheats,a:A[0])
324 let request = cheats[a:A[0]].a:A[1:-1]
325 else
326 let request = a:A
327 endif
328 let pattern = substitute(request,'/\|\'.sep,'*'.sep,'g').'*'
329 let found = {}
330 for path in pathogen#split(&runtimepath)
331 let path = expand(path, ':p')
332 let matches = split(glob(path.sep.pattern),"\n")
333 call map(matches,'isdirectory(v:val) ? v:val.sep : v:val')
334 call map(matches,'expand(v:val, ":p")[strlen(path)+1:-1]')
335 for match in matches
336 let found[match] = 1
337 endfor
338 endfor
339 return sort(keys(found))
340 endfunction
341
342 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Ve :execute s:find(<count>,'edit<bang>',<q-args>,0)
343 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vedit :execute s:find(<count>,'edit<bang>',<q-args>,0)
344 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vopen :execute s:find(<count>,'edit<bang>',<q-args>,1)
345 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vsplit :execute s:find(<count>,'split',<q-args>,<bang>1)
346 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vvsplit :execute s:find(<count>,'vsplit',<q-args>,<bang>1)
347 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vtabedit :execute s:find(<count>,'tabedit',<q-args>,<bang>1)
348 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vpedit :execute s:find(<count>,'pedit',<q-args>,<bang>1)
349 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vread :execute s:find(<count>,'read',<q-args>,<bang>1)
350
351 " vim:set et sw=2 foldmethod=expr foldexpr=getline(v\:lnum)=~'^\"\ Section\:'?'>1'\:getline(v\:lnum)=~#'^fu'?'a1'\:getline(v\:lnum)=~#'^endf'?'s1'\:'=':