Merge branch 'master' of github.com:dopefishh/dotfiles
[dotfiles.git] / .vim / autoload / pathogen.vim
1 " pathogen.vim - path option manipulation
2 " Maintainer: Tim Pope <http://tpo.pe/>
3 " Version: 2.3
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. For maximum ease of reading,
12 " :set foldmethod=marker
13
14 if exists("g:loaded_pathogen") || &cp
15 finish
16 endif
17 let g:loaded_pathogen = 1
18
19 " Point of entry for basic default usage. Give a relative path to invoke
20 " pathogen#interpose() (defaults to "bundle/{}"), or an absolute path to invoke
21 " pathogen#surround(). For backwards compatibility purposes, a full path that
22 " does not end in {} or * is given to pathogen#runtime_prepend_subdirectories()
23 " instead.
24 function! pathogen#infect(...) abort " {{{1
25 for path in a:0 ? filter(reverse(copy(a:000)), 'type(v:val) == type("")') : ['bundle/{}']
26 if path =~# '^[^\\/]\+$'
27 call s:warn('Change pathogen#infect('.string(path).') to pathogen#infect('.string(path.'/{}').')')
28 call pathogen#interpose(path . '/{}')
29 elseif path =~# '^[^\\/]\+[\\/]\%({}\|\*\)$'
30 call pathogen#interpose(path)
31 elseif path =~# '[\\/]\%({}\|\*\)$'
32 call pathogen#surround(path)
33 else
34 call s:warn('Change pathogen#infect('.string(path).') to pathogen#infect('.string(path.'/{}').')')
35 call pathogen#surround(path . '/{}')
36 endif
37 endfor
38 call pathogen#cycle_filetype()
39 return ''
40 endfunction " }}}1
41
42 " Split a path into a list.
43 function! pathogen#split(path) abort " {{{1
44 if type(a:path) == type([]) | return a:path | endif
45 let split = split(a:path,'\\\@<!\%(\\\\\)*\zs,')
46 return map(split,'substitute(v:val,''\\\([\\,]\)'',''\1'',"g")')
47 endfunction " }}}1
48
49 " Convert a list to a path.
50 function! pathogen#join(...) abort " {{{1
51 if type(a:1) == type(1) && a:1
52 let i = 1
53 let space = ' '
54 else
55 let i = 0
56 let space = ''
57 endif
58 let path = ""
59 while i < a:0
60 if type(a:000[i]) == type([])
61 let list = a:000[i]
62 let j = 0
63 while j < len(list)
64 let escaped = substitute(list[j],'[,'.space.']\|\\[\,'.space.']\@=','\\&','g')
65 let path .= ',' . escaped
66 let j += 1
67 endwhile
68 else
69 let path .= "," . a:000[i]
70 endif
71 let i += 1
72 endwhile
73 return substitute(path,'^,','','')
74 endfunction " }}}1
75
76 " Convert a list to a path with escaped spaces for 'path', 'tag', etc.
77 function! pathogen#legacyjoin(...) abort " {{{1
78 return call('pathogen#join',[1] + a:000)
79 endfunction " }}}1
80
81 " Turn filetype detection off and back on again if it was already enabled.
82 function! pathogen#cycle_filetype() " {{{1
83 if exists('g:did_load_filetypes')
84 filetype off
85 filetype on
86 endif
87 endfunction " }}}1
88
89 " Check if a bundle is disabled. A bundle is considered disabled if its
90 " basename or full name is included in the list g:pathogen_disabled.
91 function! pathogen#is_disabled(path) abort " {{{1
92 let sep = pathogen#slash()
93 let blacklist = get(g:, 'pathogen_blacklist', get(g:, 'pathogen_disabled', []))
94 return index(blacklist, fnamemodify(a:path, ':t')) != -1 || index(blacklist, a:path) != -1
95 endfunction "}}}1
96
97 " Prepend the given directory to the runtime path and append its corresponding
98 " after directory. If the directory is already included, move it to the
99 " outermost position. Wildcards are added as is. Ending a path in /{} causes
100 " all subdirectories to be added (except those in g:pathogen_disabled).
101 function! pathogen#surround(path) abort " {{{1
102 let sep = pathogen#slash()
103 let rtp = pathogen#split(&rtp)
104 if a:path =~# '[\\/]{}$'
105 let path = fnamemodify(a:path[0:-4], ':p:s?[\\/]\=$??')
106 let before = filter(pathogen#glob_directories(path.sep.'*'), '!pathogen#is_disabled(v:val)')
107 let after = filter(reverse(pathogen#glob_directories(path.sep."*".sep."after")), '!pathogen#is_disabled(v:val[0:-7])')
108 call filter(rtp,'v:val[0:strlen(path)-1] !=# path')
109 else
110 let path = fnamemodify(a:path, ':p:s?[\\/]\=$??')
111 let before = [path]
112 let after = [path . sep . 'after']
113 call filter(rtp, 'index(before + after, v:val) == -1')
114 endif
115 let &rtp = pathogen#join(before, rtp, after)
116 return &rtp
117 endfunction " }}}1
118
119 " For each directory in the runtime path, add a second entry with the given
120 " argument appended. If the argument ends in '/{}', add a separate entry for
121 " each subdirectory.
122 function! pathogen#interpose(name) abort " {{{1
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 if name =~# '{}$'
133 let list += filter(pathogen#glob_directories(substitute(dir,'after$',name[0:-3],'').'*'.sep.'after'), '!pathogen#is_disabled(v:val[0:-7])') + [dir]
134 else
135 let list += [dir, substitute(dir, 'after$', '', '') . name . sep . 'after']
136 endif
137 else
138 if name =~# '{}$'
139 let list += [dir] + filter(pathogen#glob_directories(dir.sep.name[0:-3].'*'), '!pathogen#is_disabled(v:val)')
140 else
141 let list += [dir . sep . name, dir]
142 endif
143 endif
144 endfor
145 let &rtp = pathogen#join(pathogen#uniq(list))
146 return 1
147 endfunction
148
149 let s:done_bundles = {}
150
151 " }}}1
152
153 " Invoke :helptags on all non-$VIM doc directories in runtimepath.
154 function! pathogen#helptags() abort " {{{1
155 let sep = pathogen#slash()
156 for glob in pathogen#split(&rtp)
157 for dir in map(split(glob(glob), "\n"), 'v:val.sep."/doc/".sep')
158 if (dir)[0 : strlen($VIMRUNTIME)] !=# $VIMRUNTIME.sep && filewritable(dir) == 2 && !empty(split(glob(dir.'*.txt'))) && (!filereadable(dir.'tags') || filewritable(dir.'tags'))
159 silent! execute 'helptags' pathogen#fnameescape(dir)
160 endif
161 endfor
162 endfor
163 endfunction " }}}1
164
165 command! -bar Helptags :call pathogen#helptags()
166
167 " Execute the given command. This is basically a backdoor for --remote-expr.
168 function! pathogen#execute(...) abort " {{{1
169 for command in a:000
170 execute command
171 endfor
172 return ''
173 endfunction " }}}1
174
175 " Section: Unofficial
176
177 " \ on Windows unless shellslash is set, / everywhere else.
178 function! pathogen#slash() abort " {{{1
179 return !exists("+shellslash") || &shellslash ? '/' : '\'
180 endfunction " }}}1
181
182 function! pathogen#separator() abort " {{{1
183 return pathogen#slash()
184 endfunction " }}}1
185
186 " Convenience wrapper around glob() which returns a list.
187 function! pathogen#glob(pattern) abort " {{{1
188 let files = split(glob(a:pattern),"\n")
189 return map(files,'substitute(v:val,"[".pathogen#slash()."/]$","","")')
190 endfunction "}}}1
191
192 " Like pathogen#glob(), only limit the results to directories.
193 function! pathogen#glob_directories(pattern) abort " {{{1
194 return filter(pathogen#glob(a:pattern),'isdirectory(v:val)')
195 endfunction "}}}1
196
197 " Remove duplicates from a list.
198 function! pathogen#uniq(list) abort " {{{1
199 let i = 0
200 let seen = {}
201 while i < len(a:list)
202 if (a:list[i] ==# '' && exists('empty')) || has_key(seen,a:list[i])
203 call remove(a:list,i)
204 elseif a:list[i] ==# ''
205 let i += 1
206 let empty = 1
207 else
208 let seen[a:list[i]] = 1
209 let i += 1
210 endif
211 endwhile
212 return a:list
213 endfunction " }}}1
214
215 " Backport of fnameescape().
216 function! pathogen#fnameescape(string) abort " {{{1
217 if exists('*fnameescape')
218 return fnameescape(a:string)
219 elseif a:string ==# '-'
220 return '\-'
221 else
222 return substitute(escape(a:string," \t\n*?[{`$\\%#'\"|!<"),'^[+>]','\\&','')
223 endif
224 endfunction " }}}1
225
226 " Like findfile(), but hardcoded to use the runtimepath.
227 function! pathogen#runtime_findfile(file,count) abort "{{{1
228 let rtp = pathogen#join(1,pathogen#split(&rtp))
229 let file = findfile(a:file,rtp,a:count)
230 if file ==# ''
231 return ''
232 else
233 return fnamemodify(file,':p')
234 endif
235 endfunction " }}}1
236
237 " Section: Deprecated
238
239 function! s:warn(msg)
240 echohl WarningMsg
241 echomsg a:msg
242 echohl NONE
243 endfunction
244
245 " Prepend all subdirectories of path to the rtp, and append all 'after'
246 " directories in those subdirectories. Deprecated.
247 function! pathogen#runtime_prepend_subdirectories(path) " {{{1
248 call s:warn('Change pathogen#runtime_prepend_subdirectories('.string(a:path).') to pathogen#infect('.string(a:path.'/{}').')')
249 return pathogen#surround(a:path . pathogen#slash() . '{}')
250 endfunction " }}}1
251
252 function! pathogen#incubate(...) abort " {{{1
253 let name = a:0 ? a:1 : 'bundle/{}'
254 call s:warn('Change pathogen#incubate('.(a:0 ? string(a:1) : '').') to pathogen#infect('.string(name).')')
255 return pathogen#interpose(name)
256 endfunction " }}}1
257
258 " Deprecated alias for pathogen#interpose().
259 function! pathogen#runtime_append_all_bundles(...) abort " {{{1
260 if a:0
261 call s:warn('Change pathogen#runtime_append_all_bundles('.string(a:1).') to pathogen#infect('.string(a:1.'/{}').')')
262 else
263 call s:warn('Change pathogen#runtime_append_all_bundles() to pathogen#infect()')
264 endif
265 return pathogen#interpose(a:0 ? a:1 . '/{}' : 'bundle/{}')
266 endfunction " }}}1
267
268 if exists(':Vedit')
269 finish
270 endif
271
272 let s:vopen_warning = 0
273
274 function! s:find(count,cmd,file,lcd) " {{{1
275 let rtp = pathogen#join(1,pathogen#split(&runtimepath))
276 let file = pathogen#runtime_findfile(a:file,a:count)
277 if file ==# ''
278 return "echoerr 'E345: Can''t find file \"".a:file."\" in runtimepath'"
279 endif
280 if !s:vopen_warning
281 let s:vopen_warning = 1
282 let warning = '|echohl WarningMsg|echo "Install scriptease.vim to continue using :V'.a:cmd.'"|echohl NONE'
283 else
284 let warning = ''
285 endif
286 if a:lcd
287 let path = file[0:-strlen(a:file)-2]
288 execute 'lcd `=path`'
289 return a:cmd.' '.pathogen#fnameescape(a:file) . warning
290 else
291 return a:cmd.' '.pathogen#fnameescape(file) . warning
292 endif
293 endfunction " }}}1
294
295 function! s:Findcomplete(A,L,P) " {{{1
296 let sep = pathogen#slash()
297 let cheats = {
298 \'a': 'autoload',
299 \'d': 'doc',
300 \'f': 'ftplugin',
301 \'i': 'indent',
302 \'p': 'plugin',
303 \'s': 'syntax'}
304 if a:A =~# '^\w[\\/]' && has_key(cheats,a:A[0])
305 let request = cheats[a:A[0]].a:A[1:-1]
306 else
307 let request = a:A
308 endif
309 let pattern = substitute(request,'/\|\'.sep,'*'.sep,'g').'*'
310 let found = {}
311 for path in pathogen#split(&runtimepath)
312 let path = expand(path, ':p')
313 let matches = split(glob(path.sep.pattern),"\n")
314 call map(matches,'isdirectory(v:val) ? v:val.sep : v:val')
315 call map(matches,'expand(v:val, ":p")[strlen(path)+1:-1]')
316 for match in matches
317 let found[match] = 1
318 endfor
319 endfor
320 return sort(keys(found))
321 endfunction " }}}1
322
323 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Ve :execute s:find(<count>,'edit<bang>',<q-args>,0)
324 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vedit :execute s:find(<count>,'edit<bang>',<q-args>,0)
325 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vopen :execute s:find(<count>,'edit<bang>',<q-args>,1)
326 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vsplit :execute s:find(<count>,'split',<q-args>,<bang>1)
327 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vvsplit :execute s:find(<count>,'vsplit',<q-args>,<bang>1)
328 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vtabedit :execute s:find(<count>,'tabedit',<q-args>,<bang>1)
329 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vpedit :execute s:find(<count>,'pedit',<q-args>,<bang>1)
330 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vread :execute s:find(<count>,'read',<q-args>,<bang>1)
331
332 " vim:set et sw=2: