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