comparison rc/vim-autoload-pathogen @ 569:ea4bc5799d71

Update pathogen.
author nanaya <me@myconan.net>
date Wed, 24 Jun 2015 13:31:40 +0900
parents 7394b88bf1c6
children
comparison
equal deleted inserted replaced
568:5fac54648ada 569:ea4bc5799d71
1 " pathogen.vim - path option manipulation 1 " pathogen.vim - path option manipulation
2 " Maintainer: Tim Pope <http://tpo.pe/> 2 " Maintainer: Tim Pope <http://tpo.pe/>
3 " Version: 2.0 3 " Version: 2.3
4 4
5 " Install in ~/.vim/autoload (or ~\vimfiles\autoload). 5 " Install in ~/.vim/autoload (or ~\vimfiles\autoload).
6 " 6 "
7 " For management of individually installed plugins in ~/.vim/bundle (or 7 " For management of individually installed plugins in ~/.vim/bundle (or
8 " ~\vimfiles\bundle), adding `call pathogen#infect()` to the top of your 8 " ~\vimfiles\bundle), adding `execute pathogen#infect()` to the top of your
9 " .vimrc is the only other setup necessary. 9 " .vimrc is the only other setup necessary.
10 " 10 "
11 " The API is documented inline below. For maximum ease of reading, 11 " The API is documented inline below.
12 " :set foldmethod=marker
13 12
14 if exists("g:loaded_pathogen") || &cp 13 if exists("g:loaded_pathogen") || &cp
15 finish 14 finish
16 endif 15 endif
17 let g:loaded_pathogen = 1 16 let g:loaded_pathogen = 1
18 17
19 " Point of entry for basic default usage. Give a directory name to invoke 18 " Point of entry for basic default usage. Give a relative path to invoke
20 " pathogen#runtime_append_all_bundles() (defaults to "bundle"), or a full path 19 " pathogen#interpose() (defaults to "bundle/{}"), or an absolute path to invoke
21 " to invoke pathogen#runtime_prepend_subdirectories(). Afterwards, 20 " pathogen#surround(). Curly braces are expanded with pathogen#expand():
22 " pathogen#cycle_filetype() is invoked. 21 " "bundle/{}" finds all subdirectories inside "bundle" inside all directories
23 function! pathogen#infect(...) abort " {{{1 22 " in the runtime path.
24 let source_path = a:0 ? a:1 : 'bundle' 23 function! pathogen#infect(...) abort
25 if source_path =~# '[\\/]' 24 for path in a:0 ? filter(reverse(copy(a:000)), 'type(v:val) == type("")') : ['bundle/{}']
26 call pathogen#runtime_prepend_subdirectories(source_path) 25 if path =~# '^\%({\=[$~\\/]\|{\=\w:[\\/]\).*[{}*]'
27 else 26 call pathogen#surround(path)
28 call pathogen#runtime_append_all_bundles(source_path) 27 elseif path =~# '^\%([$~\\/]\|\w:[\\/]\)'
29 endif 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
30 call pathogen#cycle_filetype() 37 call pathogen#cycle_filetype()
31 endfunction " }}}1 38 if pathogen#is_disabled($MYVIMRC)
39 return 'finish'
40 endif
41 return ''
42 endfunction
32 43
33 " Split a path into a list. 44 " Split a path into a list.
34 function! pathogen#split(path) abort " {{{1 45 function! pathogen#split(path) abort
35 if type(a:path) == type([]) | return a:path | endif 46 if type(a:path) == type([]) | return a:path | endif
47 if empty(a:path) | return [] | endif
36 let split = split(a:path,'\\\@<!\%(\\\\\)*\zs,') 48 let split = split(a:path,'\\\@<!\%(\\\\\)*\zs,')
37 return map(split,'substitute(v:val,''\\\([\\,]\)'',''\1'',"g")') 49 return map(split,'substitute(v:val,''\\\([\\,]\)'',''\1'',"g")')
38 endfunction " }}}1 50 endfunction
39 51
40 " Convert a list to a path. 52 " Convert a list to a path.
41 function! pathogen#join(...) abort " {{{1 53 function! pathogen#join(...) abort
42 if type(a:1) == type(1) && a:1 54 if type(a:1) == type(1) && a:1
43 let i = 1 55 let i = 1
44 let space = ' ' 56 let space = ' '
45 else 57 else
46 let i = 0 58 let i = 0
60 let path .= "," . a:000[i] 72 let path .= "," . a:000[i]
61 endif 73 endif
62 let i += 1 74 let i += 1
63 endwhile 75 endwhile
64 return substitute(path,'^,','','') 76 return substitute(path,'^,','','')
65 endfunction " }}}1 77 endfunction
66 78
67 " Convert a list to a path with escaped spaces for 'path', 'tag', etc. 79 " Convert a list to a path with escaped spaces for 'path', 'tag', etc.
68 function! pathogen#legacyjoin(...) abort " {{{1 80 function! pathogen#legacyjoin(...) abort
69 return call('pathogen#join',[1] + a:000) 81 return call('pathogen#join',[1] + a:000)
70 endfunction " }}}1 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_disabled.
94 function! pathogen#is_disabled(path) abort
95 if a:path =~# '\~$'
96 return 1
97 endif
98 let sep = pathogen#slash()
99 let blacklist = map(
100 \ get(g:, 'pathogen_blacklist', get(g:, 'pathogen_disabled', [])) +
101 \ pathogen#split($VIMBLACKLIST),
102 \ 'substitute(v:val, "[\\/]$", "", "")')
103 return index(blacklist, fnamemodify(a:path, ':t')) != -1 || index(blacklist, a:path) != -1
104 endfunction "}}}1
105
106 " Prepend the given directory to the runtime path and append its corresponding
107 " after directory. Curly braces are expanded with pathogen#expand().
108 function! pathogen#surround(path) abort
109 let sep = pathogen#slash()
110 let rtp = pathogen#split(&rtp)
111 let path = fnamemodify(a:path, ':p:?[\\/]\=$??')
112 let before = filter(pathogen#expand(path), '!pathogen#is_disabled(v:val)')
113 let after = filter(reverse(pathogen#expand(path.sep.'after')), '!pathogen#is_disabled(v:val[0:-7])')
114 call filter(rtp, 'index(before + after, v:val) == -1')
115 let &rtp = pathogen#join(before, rtp, after)
116 return &rtp
117 endfunction
118
119 " For each directory in the runtime path, add a second entry with the given
120 " argument appended. Curly braces are expanded with pathogen#expand().
121 function! pathogen#interpose(name) abort
122 let sep = pathogen#slash()
123 let name = a:name
124 if has_key(s:done_bundles, name)
125 return ""
126 endif
127 let s:done_bundles[name] = 1
128 let list = []
129 for dir in pathogen#split(&rtp)
130 if dir =~# '\<after$'
131 let list += reverse(filter(pathogen#expand(dir[0:-6].name.sep.'after'), '!pathogen#is_disabled(v:val[0:-7])')) + [dir]
132 else
133 let list += [dir] + filter(pathogen#expand(dir.sep.name), '!pathogen#is_disabled(v:val)')
134 endif
135 endfor
136 let &rtp = pathogen#join(pathogen#uniq(list))
137 return 1
138 endfunction
139
140 let s:done_bundles = {}
141
142 " Invoke :helptags on all non-$VIM doc directories in runtimepath.
143 function! pathogen#helptags() abort
144 let sep = pathogen#slash()
145 for glob in pathogen#split(&rtp)
146 for dir in map(split(glob(glob), "\n"), 'v:val.sep."/doc/".sep')
147 if (dir)[0 : strlen($VIMRUNTIME)] !=# $VIMRUNTIME.sep && filewritable(dir) == 2 && !empty(split(glob(dir.'*.txt'))) && (!filereadable(dir.'tags') || filewritable(dir.'tags'))
148 silent! execute 'helptags' pathogen#fnameescape(dir)
149 endif
150 endfor
151 endfor
152 endfunction
153
154 command! -bar Helptags :call pathogen#helptags()
155
156 " Execute the given command. This is basically a backdoor for --remote-expr.
157 function! pathogen#execute(...) abort
158 for command in a:000
159 execute command
160 endfor
161 return ''
162 endfunction
163
164 " Section: Unofficial
165
166 function! pathogen#is_absolute(path) abort
167 return a:path =~# (has('win32') ? '^\%([\\/]\|\w:\)[\\/]\|^[~$]' : '^[/~$]')
168 endfunction
169
170 " Given a string, returns all possible permutations of comma delimited braced
171 " alternatives of that string. pathogen#expand('/{a,b}/{c,d}') yields
172 " ['/a/c', '/a/d', '/b/c', '/b/d']. Empty braces are treated as a wildcard
173 " and globbed. Actual globs are preserved.
174 function! pathogen#expand(pattern) abort
175 if a:pattern =~# '{[^{}]\+}'
176 let [pre, pat, post] = split(substitute(a:pattern, '\(.\{-\}\){\([^{}]\+\)}\(.*\)', "\\1\001\\2\001\\3", ''), "\001", 1)
177 let found = map(split(pat, ',', 1), 'pre.v:val.post')
178 let results = []
179 for pattern in found
180 call extend(results, pathogen#expand(pattern))
181 endfor
182 return results
183 elseif a:pattern =~# '{}'
184 let pat = matchstr(a:pattern, '^.*{}[^*]*\%($\|[\\/]\)')
185 let post = a:pattern[strlen(pat) : -1]
186 return map(split(glob(substitute(pat, '{}', '*', 'g')), "\n"), 'v:val.post')
187 else
188 return [a:pattern]
189 endif
190 endfunction
191
192 " \ on Windows unless shellslash is set, / everywhere else.
193 function! pathogen#slash() abort
194 return !exists("+shellslash") || &shellslash ? '/' : '\'
195 endfunction
196
197 function! pathogen#separator() abort
198 return pathogen#slash()
199 endfunction
200
201 " Convenience wrapper around glob() which returns a list.
202 function! pathogen#glob(pattern) abort
203 let files = split(glob(a:pattern),"\n")
204 return map(files,'substitute(v:val,"[".pathogen#slash()."/]$","","")')
205 endfunction "}}}1
206
207 " Like pathogen#glob(), only limit the results to directories.
208 function! pathogen#glob_directories(pattern) abort
209 return filter(pathogen#glob(a:pattern),'isdirectory(v:val)')
210 endfunction "}}}1
71 211
72 " Remove duplicates from a list. 212 " Remove duplicates from a list.
73 function! pathogen#uniq(list) abort " {{{1 213 function! pathogen#uniq(list) abort
74 let i = 0 214 let i = 0
75 let seen = {} 215 let seen = {}
76 while i < len(a:list) 216 while i < len(a:list)
77 if (a:list[i] ==# '' && exists('empty')) || has_key(seen,a:list[i]) 217 if (a:list[i] ==# '' && exists('empty')) || has_key(seen,a:list[i])
78 call remove(a:list,i) 218 call remove(a:list,i)
83 let seen[a:list[i]] = 1 223 let seen[a:list[i]] = 1
84 let i += 1 224 let i += 1
85 endif 225 endif
86 endwhile 226 endwhile
87 return a:list 227 return a:list
88 endfunction " }}}1 228 endfunction
89 229
90 " \ on Windows unless shellslash is set, / everywhere else. 230 " Backport of fnameescape().
91 function! pathogen#separator() abort " {{{1 231 function! pathogen#fnameescape(string) abort
92 return !exists("+shellslash") || &shellslash ? '/' : '\' 232 if exists('*fnameescape')
93 endfunction " }}}1 233 return fnameescape(a:string)
94 234 elseif a:string ==# '-'
95 " Convenience wrapper around glob() which returns a list. 235 return '\-'
96 function! pathogen#glob(pattern) abort " {{{1 236 else
97 let files = split(glob(a:pattern),"\n") 237 return substitute(escape(a:string," \t\n*?[{`$\\%#'\"|!<"),'^[+>]','\\&','')
98 return map(files,'substitute(v:val,"[".pathogen#separator()."/]$","","")') 238 endif
99 endfunction "}}}1 239 endfunction
100
101 " Like pathogen#glob(), only limit the results to directories.
102 function! pathogen#glob_directories(pattern) abort " {{{1
103 return filter(pathogen#glob(a:pattern),'isdirectory(v:val)')
104 endfunction "}}}1
105
106 " Turn filetype detection off and back on again if it was already enabled.
107 function! pathogen#cycle_filetype() " {{{1
108 if exists('g:did_load_filetypes')
109 filetype off
110 filetype on
111 endif
112 endfunction " }}}1
113
114 " Checks if a bundle is 'disabled'. A bundle is considered 'disabled' if
115 " its 'basename()' is included in g:pathogen_disabled[]' or ends in a tilde.
116 function! pathogen#is_disabled(path) " {{{1
117 if a:path =~# '\~$'
118 return 1
119 elseif !exists("g:pathogen_disabled")
120 return 0
121 endif
122 let sep = pathogen#separator()
123 return index(g:pathogen_disabled, strpart(a:path, strridx(a:path, sep)+1)) != -1
124 endfunction "}}}1
125
126 " Prepend all subdirectories of path to the rtp, and append all 'after'
127 " directories in those subdirectories.
128 function! pathogen#runtime_prepend_subdirectories(path) " {{{1
129 let sep = pathogen#separator()
130 let before = filter(pathogen#glob_directories(a:path.sep."*"), '!pathogen#is_disabled(v:val)')
131 let after = filter(pathogen#glob_directories(a:path.sep."*".sep."after"), '!pathogen#is_disabled(v:val[0:-7])')
132 let rtp = pathogen#split(&rtp)
133 let path = expand(a:path)
134 call filter(rtp,'v:val[0:strlen(path)-1] !=# path')
135 let &rtp = pathogen#join(pathogen#uniq(before + rtp + after))
136 return &rtp
137 endfunction " }}}1
138
139 " For each directory in rtp, check for a subdirectory named dir. If it
140 " exists, add all subdirectories of that subdirectory to the rtp, immediately
141 " after the original directory. If no argument is given, 'bundle' is used.
142 " Repeated calls with the same arguments are ignored.
143 function! pathogen#runtime_append_all_bundles(...) " {{{1
144 let sep = pathogen#separator()
145 let name = a:0 ? a:1 : 'bundle'
146 if "\n".s:done_bundles =~# "\\M\n".name."\n"
147 return ""
148 endif
149 let s:done_bundles .= name . "\n"
150 let list = []
151 for dir in pathogen#split(&rtp)
152 if dir =~# '\<after$'
153 let list += filter(pathogen#glob_directories(substitute(dir,'after$',name,'').sep.'*[^~]'.sep.'after'), '!pathogen#is_disabled(v:val[0:-7])') + [dir]
154 else
155 let list += [dir] + filter(pathogen#glob_directories(dir.sep.name.sep.'*[^~]'), '!pathogen#is_disabled(v:val)')
156 endif
157 endfor
158 let &rtp = pathogen#join(pathogen#uniq(list))
159 return 1
160 endfunction
161
162 let s:done_bundles = ''
163 " }}}1
164
165 " Invoke :helptags on all non-$VIM doc directories in runtimepath.
166 function! pathogen#helptags() " {{{1
167 let sep = pathogen#separator()
168 for dir in pathogen#split(&rtp)
169 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'))
170 helptags `=dir.'/doc'`
171 endif
172 endfor
173 endfunction " }}}1
174
175 command! -bar Helptags :call pathogen#helptags()
176 240
177 " Like findfile(), but hardcoded to use the runtimepath. 241 " Like findfile(), but hardcoded to use the runtimepath.
178 function! pathogen#runtime_findfile(file,count) "{{{1 242 function! pathogen#runtime_findfile(file,count) abort "{{{1
179 let rtp = pathogen#join(1,pathogen#split(&rtp)) 243 let rtp = pathogen#join(1,pathogen#split(&rtp))
180 let file = findfile(a:file,rtp,a:count) 244 let file = findfile(a:file,rtp,a:count)
181 if file ==# '' 245 if file ==# ''
182 return '' 246 return ''
183 else 247 else
184 return fnamemodify(file,':p') 248 return fnamemodify(file,':p')
185 endif 249 endif
186 endfunction " }}}1 250 endfunction
187 251
188 " Backport of fnameescape(). 252 " Section: Deprecated
189 function! pathogen#fnameescape(string) " {{{1 253
190 if exists('*fnameescape') 254 function! s:warn(msg) abort
191 return fnameescape(a:string) 255 echohl WarningMsg
192 elseif a:string ==# '-' 256 echomsg a:msg
193 return '\-' 257 echohl NONE
194 else 258 endfunction
195 return substitute(escape(a:string," \t\n*?[{`$\\%#'\"|!<"),'^[+>]','\\&','') 259
196 endif 260 " Prepend all subdirectories of path to the rtp, and append all 'after'
197 endfunction " }}}1 261 " directories in those subdirectories. Deprecated.
262 function! pathogen#runtime_prepend_subdirectories(path) abort
263 call s:warn('Change pathogen#runtime_prepend_subdirectories('.string(a:path).') to pathogen#infect('.string(a:path.'/{}').')')
264 return pathogen#surround(a:path . pathogen#slash() . '{}')
265 endfunction
266
267 function! pathogen#incubate(...) abort
268 let name = a:0 ? a:1 : 'bundle/{}'
269 call s:warn('Change pathogen#incubate('.(a:0 ? string(a:1) : '').') to pathogen#infect('.string(name).')')
270 return pathogen#interpose(name)
271 endfunction
272
273 " Deprecated alias for pathogen#interpose().
274 function! pathogen#runtime_append_all_bundles(...) abort
275 if a:0
276 call s:warn('Change pathogen#runtime_append_all_bundles('.string(a:1).') to pathogen#infect('.string(a:1.'/{}').')')
277 else
278 call s:warn('Change pathogen#runtime_append_all_bundles() to pathogen#infect()')
279 endif
280 return pathogen#interpose(a:0 ? a:1 . '/{}' : 'bundle/{}')
281 endfunction
198 282
199 if exists(':Vedit') 283 if exists(':Vedit')
200 finish 284 finish
201 endif 285 endif
202 286
203 function! s:find(count,cmd,file,lcd) " {{{1 287 let s:vopen_warning = 0
288
289 function! s:find(count,cmd,file,lcd)
204 let rtp = pathogen#join(1,pathogen#split(&runtimepath)) 290 let rtp = pathogen#join(1,pathogen#split(&runtimepath))
205 let file = pathogen#runtime_findfile(a:file,a:count) 291 let file = pathogen#runtime_findfile(a:file,a:count)
206 if file ==# '' 292 if file ==# ''
207 return "echoerr 'E345: Can''t find file \"".a:file."\" in runtimepath'" 293 return "echoerr 'E345: Can''t find file \"".a:file."\" in runtimepath'"
208 elseif a:lcd 294 endif
295 if !s:vopen_warning
296 let s:vopen_warning = 1
297 let warning = '|echohl WarningMsg|echo "Install scriptease.vim to continue using :V'.a:cmd.'"|echohl NONE'
298 else
299 let warning = ''
300 endif
301 if a:lcd
209 let path = file[0:-strlen(a:file)-2] 302 let path = file[0:-strlen(a:file)-2]
210 execute 'lcd `=path`' 303 execute 'lcd `=path`'
211 return a:cmd.' '.pathogen#fnameescape(a:file) 304 return a:cmd.' '.pathogen#fnameescape(a:file) . warning
212 else 305 else
213 return a:cmd.' '.pathogen#fnameescape(file) 306 return a:cmd.' '.pathogen#fnameescape(file) . warning
214 endif 307 endif
215 endfunction " }}}1 308 endfunction
216 309
217 function! s:Findcomplete(A,L,P) " {{{1 310 function! s:Findcomplete(A,L,P)
218 let sep = pathogen#separator() 311 let sep = pathogen#slash()
219 let cheats = { 312 let cheats = {
220 \'a': 'autoload', 313 \'a': 'autoload',
221 \'d': 'doc', 314 \'d': 'doc',
222 \'f': 'ftplugin', 315 \'f': 'ftplugin',
223 \'i': 'indent', 316 \'i': 'indent',
238 for match in matches 331 for match in matches
239 let found[match] = 1 332 let found[match] = 1
240 endfor 333 endfor
241 endfor 334 endfor
242 return sort(keys(found)) 335 return sort(keys(found))
243 endfunction " }}}1 336 endfunction
244 337
245 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Ve :execute s:find(<count>,'edit<bang>',<q-args>,0) 338 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Ve :execute s:find(<count>,'edit<bang>',<q-args>,0)
246 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vedit :execute s:find(<count>,'edit<bang>',<q-args>,0) 339 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vedit :execute s:find(<count>,'edit<bang>',<q-args>,0)
247 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vopen :execute s:find(<count>,'edit<bang>',<q-args>,1) 340 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vopen :execute s:find(<count>,'edit<bang>',<q-args>,1)
248 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vsplit :execute s:find(<count>,'split',<q-args>,<bang>1) 341 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vsplit :execute s:find(<count>,'split',<q-args>,<bang>1)
249 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vvsplit :execute s:find(<count>,'vsplit',<q-args>,<bang>1) 342 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vvsplit :execute s:find(<count>,'vsplit',<q-args>,<bang>1)
250 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vtabedit :execute s:find(<count>,'tabedit',<q-args>,<bang>1) 343 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vtabedit :execute s:find(<count>,'tabedit',<q-args>,<bang>1)
251 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vpedit :execute s:find(<count>,'pedit',<q-args>,<bang>1) 344 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vpedit :execute s:find(<count>,'pedit',<q-args>,<bang>1)
252 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vread :execute s:find(<count>,'read',<q-args>,<bang>1) 345 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vread :execute s:find(<count>,'read',<q-args>,<bang>1)
253 346
254 " vim:set et sw=2: 347 " vim:set et sw=2 foldmethod=expr foldexpr=getline(v\:lnum)=~'^\"\ Section\:'?'>1'\:getline(v\:lnum)=~#'^fu'?'a1'\:getline(v\:lnum)=~#'^endf'?'s1'\:'=':