1 " pathogen.vim - path option manipulation
2 " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
5 " Install in ~/.vim/autoload (or ~\vimfiles\autoload).
7 " API is documented below.
9 if exists("g:loaded_pathogen") || &cp
12 let g:loaded_pathogen = 1
14 " Split a path into a list.
15 function! pathogen#split(path) abort " {{{1
16 if type(a:path) == type([]) | return a:path | endif
17 let split = split(a:path,'\\\@<!\%(\\\\\)*\zs,')
18 return map(split,'substitute(v:val,''\\\([\\,]\)'',''\1'',"g")')
21 " Convert a list to a path.
22 function! pathogen#join(...) abort " {{{1
23 if type(a:1) == type(1) && a:1
32 if type(a:000[i]) == type([])
36 let escaped = substitute(list[j],'[,'.space.']\|\\[\,'.space.']\@=','\\&','g')
37 let path .= ',' . escaped
41 let path .= "," . a:000[i]
45 return substitute(path,'^,','','')
48 " Convert a list to a path with escaped spaces for 'path', 'tag', etc.
49 function! pathogen#legacyjoin(...) abort " {{{1
50 return call('pathogen#join',[1] + a:000)
53 " Remove duplicates from a list.
54 function! pathogen#uniq(list) abort " {{{1
58 if has_key(seen,a:list[i])
61 let seen[a:list[i]] = 1
68 " \ on Windows unless shellslash is set, / everywhere else.
69 function! pathogen#separator() abort " {{{1
70 return !exists("+shellslash") || &shellslash ? '/' : '\'
73 " Convenience wrapper around glob() which returns a list.
74 function! pathogen#glob(pattern) abort " {{{1
75 let files = split(glob(a:pattern),"\n")
76 return map(files,'substitute(v:val,"[".pathogen#separator()."/]$","","")')
79 " Like pathogen#glob(), only limit the results to directories.
80 function! pathogen#glob_directories(pattern) abort " {{{1
81 return filter(pathogen#glob(a:pattern),'isdirectory(v:val)')
84 " Checks if a bundle is 'disabled'. A bundle is considered 'disabled' if
85 " its 'basename()' is included in g:pathogen_disabled[]'.
86 function! pathogen#is_disabled(path) " {{{1
87 if !exists("g:pathogen_disabled")
90 let sep = pathogen#separator()
91 return index(g:pathogen_disabled, strpart(a:path, strridx(a:path, sep)+1)) != -1
94 " Prepend all subdirectories of path to the rtp, and append all 'after'
95 " directories in those subdirectories.
96 function! pathogen#runtime_prepend_subdirectories(path) " {{{1
97 let sep = pathogen#separator()
98 let before = filter(pathogen#glob_directories(a:path.sep."*[^~]"), '!pathogen#is_disabled(v:val)')
99 let after = filter(pathogen#glob_directories(a:path.sep."*[^~]".sep."after"), '!pathogen#is_disabled(v:val[0:-7])')
100 let rtp = pathogen#split(&rtp)
101 let path = expand(a:path)
102 call filter(rtp,'v:val[0:strlen(path)-1] !=# path')
103 let &rtp = pathogen#join(pathogen#uniq(before + rtp + after))
107 " For each directory in rtp, check for a subdirectory named dir. If it
108 " exists, add all subdirectories of that subdirectory to the rtp, immediately
109 " after the original directory. If no argument is given, 'bundle' is used.
110 " Repeated calls with the same arguments are ignored.
111 function! pathogen#runtime_append_all_bundles(...) " {{{1
112 let sep = pathogen#separator()
113 let name = a:0 ? a:1 : 'bundle'
114 if "\n".s:done_bundles =~# "\\M\n".name."\n"
117 let s:done_bundles .= name . "\n"
119 for dir in pathogen#split(&rtp)
120 if dir =~# '\<after$'
121 let list += filter(pathogen#glob_directories(substitute(dir,'after$',name,'').sep.'*[^~]'.sep.'after'), '!pathogen#is_disabled(v:val[0:-7])') + [dir]
123 let list += [dir] + filter(pathogen#glob_directories(dir.sep.name.sep.'*[^~]'), '!pathogen#is_disabled(v:val)')
126 let &rtp = pathogen#join(pathogen#uniq(list))
130 let s:done_bundles = ''
133 " Invoke :helptags on all non-$VIM doc directories in runtimepath.
134 function! pathogen#helptags() " {{{1
135 for dir in pathogen#split(&rtp)
136 if dir[0 : strlen($VIM)-1] !=# $VIM && isdirectory(dir.'/doc') && !empty(glob(dir.'/doc/*')) && (!filereadable(dir.'/doc/tags') || filewritable(dir.'/doc/tags'))
137 helptags `=dir.'/doc'`
142 " vim:set ft=vim ts=8 sw=2 sts=2: