1 " pathogen.vim - path option manipulation
2 " Maintainer: Tim Pope <http://tpo.pe/>
5 " Install in ~/.vim/autoload (or ~\vimfiles\autoload).
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.
11 " The API is documented inline below. For maximum ease of reading,
12 " :set foldmethod=marker
14 if exists("g:loaded_pathogen") || &cp
17 let g:loaded_pathogen = 1
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()
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)
42 call s:warn('Change pathogen#infect('.string(path).') to pathogen#infect('.string(path.'/{}').')')
43 call pathogen#surround(path . '/{}')
46 call pathogen#cycle_filetype()
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")')
57 " Convert a list to a path.
58 function! pathogen#join(...) abort " {{{1
59 if type(a:1) == type(1) && a:1
68 if type(a:000[i]) == type([])
72 let escaped = substitute(list[j],'[,'.space.']\|\\[\,'.space.']\@=','\\&','g')
73 let path .= ',' . escaped
77 let path .= "," . a:000[i]
81 return substitute(path,'^,','','')
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)
89 " Remove duplicates from a list.
90 function! pathogen#uniq(list) abort " {{{1
94 if (a:list[i] ==# '' && exists('empty')) || has_key(seen,a:list[i])
96 elseif a:list[i] ==# ''
100 let seen[a:list[i]] = 1
107 " \ on Windows unless shellslash is set, / everywhere else.
108 function! pathogen#separator() abort " {{{1
109 return !exists("+shellslash") || &shellslash ? '/' : '\'
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()."/]$","","")')
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)')
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')
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
137 elseif !exists("g:pathogen_disabled")
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
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')
158 let path = fnamemodify(a:path, ':p:s?[\\/]\=$??')
160 let after = [path . sep . 'after']
161 call filter(rtp, 'index(before + after, v:val) == -1')
163 let &rtp = pathogen#join(before, rtp, after)
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() . '{}')
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
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"
186 let s:done_bundles .= name . "\n"
188 for dir in pathogen#split(&rtp)
189 if dir =~# '\<after$'
191 let list += filter(pathogen#glob_directories(substitute(dir,'after$',name[0:-3],'').'*[^~]'.sep.'after'), '!pathogen#is_disabled(v:val[0:-7])') + [dir]
193 let list += [dir, substitute(dir, 'after$', '', '') . name . sep . 'after']
197 let list += [dir] + filter(pathogen#glob_directories(dir.sep.name[0:-3].'*[^~]'), '!pathogen#is_disabled(v:val)')
199 let list += [dir . sep . name, dir]
203 let &rtp = pathogen#join(pathogen#uniq(list))
207 " Deprecated alias for pathogen#incubate().
208 function! pathogen#runtime_append_all_bundles(...) abort " {{{1
210 call s:warn('Change pathogen#runtime_append_all_bundles('.string(a:1).') to pathogen#incubate('.string(a:1.'/{}').')')
212 call s:warn('Change pathogen#runtime_append_all_bundles() to pathogen#incubate()')
214 return call('pathogen#incubate', map(copy(a:000),'v:val . "/{}"'))
217 let s:done_bundles = ''
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'`
232 command! -bar Helptags :call pathogen#helptags()
234 " Execute the given command. This is basically a backdoor for --remote-expr.
235 function! pathogen#execute(...) abort " {{{1
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)
249 return fnamemodify(file,':p')
253 " Backport of fnameescape().
254 function! pathogen#fnameescape(string) abort " {{{1
255 if exists('*fnameescape')
256 return fnameescape(a:string)
257 elseif a:string ==# '-'
260 return substitute(escape(a:string," \t\n*?[{`$\\%#'\"|!<"),'^[+>]','\\&','')
268 let s:vopen_warning = 0
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)
274 return "echoerr 'E345: Can''t find file \"".a:file."\" in runtimepath'"
277 let s:vopen_warning = 1
278 let warning = '|echohl WarningMsg|echo "Install scriptease.vim to continue using :V'.a:cmd.'"|echohl NONE'
283 let path = file[0:-strlen(a:file)-2]
284 execute 'lcd `=path`'
285 return a:cmd.' '.pathogen#fnameescape(a:file) . warning
287 return a:cmd.' '.pathogen#fnameescape(file) . warning
291 function! s:Findcomplete(A,L,P) " {{{1
292 let sep = pathogen#separator()
300 if a:A =~# '^\w[\\/]' && has_key(cheats,a:A[0])
301 let request = cheats[a:A[0]].a:A[1:-1]
305 let pattern = substitute(request,'/\|\'.sep,'*'.sep,'g').'*'
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]')
316 return sort(keys(found))
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)