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