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 `execute 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
25 " Point of entry for basic default usage. Give a relative path to invoke
26 " pathogen#incubate() (defaults to "bundle/{}"), or an absolute path to invoke
27 " pathogen#surround(). For backwards compatibility purposes, a full path that
28 " does not end in {} or * is given to pathogen#runtime_prepend_subdirectories()
30 function! pathogen#infect(...) abort " {{{1
31 for path in a:0 ? reverse(copy(a:000)) : ['bundle/{}']
32 if path =~# '^[^\\/]\+$'
33 call s:warn('Change pathogen#infect('.string(path).') to pathogen#infect('.string(path.'/{}').')')
34 call pathogen#incubate(path . '/{}')
35 elseif path =~# '^[^\\/]\+[\\/]\%({}\|\*\)$'
36 call pathogen#incubate(path)
37 elseif path =~# '[\\/]\%({}\|\*\)$'
38 call pathogen#surround(path)
40 call s:warn('Change pathogen#infect('.string(path).') to pathogen#infect('.string(path.'/{}').')')
41 call pathogen#surround(path . '/{}')
44 call pathogen#cycle_filetype()
48 " Split a path into a list.
49 function! pathogen#split(path) abort " {{{1
50 if type(a:path) == type([]) | return a:path | endif
51 let split = split(a:path,'\\\@<!\%(\\\\\)*\zs,')
52 return map(split,'substitute(v:val,''\\\([\\,]\)'',''\1'',"g")')
55 " Convert a list to a path.
56 function! pathogen#join(...) abort " {{{1
57 if type(a:1) == type(1) && a:1
66 if type(a:000[i]) == type([])
70 let escaped = substitute(list[j],'[,'.space.']\|\\[\,'.space.']\@=','\\&','g')
71 let path .= ',' . escaped
75 let path .= "," . a:000[i]
79 return substitute(path,'^,','','')
82 " Convert a list to a path with escaped spaces for 'path', 'tag', etc.
83 function! pathogen#legacyjoin(...) abort " {{{1
84 return call('pathogen#join',[1] + a:000)
87 " Remove duplicates from a list.
88 function! pathogen#uniq(list) abort " {{{1
92 if (a:list[i] ==# '' && exists('empty')) || has_key(seen,a:list[i])
94 elseif a:list[i] ==# ''
98 let seen[a:list[i]] = 1
105 " \ on Windows unless shellslash is set, / everywhere else.
106 function! pathogen#separator() abort " {{{1
107 return !exists("+shellslash") || &shellslash ? '/' : '\'
110 " Convenience wrapper around glob() which returns a list.
111 function! pathogen#glob(pattern) abort " {{{1
112 let files = split(glob(a:pattern),"\n")
113 return map(files,'substitute(v:val,"[".pathogen#separator()."/]$","","")')
116 " Like pathogen#glob(), only limit the results to directories.
117 function! pathogen#glob_directories(pattern) abort " {{{1
118 return filter(pathogen#glob(a:pattern),'isdirectory(v:val)')
121 " Turn filetype detection off and back on again if it was already enabled.
122 function! pathogen#cycle_filetype() " {{{1
123 if exists('g:did_load_filetypes')
129 " Check if a bundle is disabled. A bundle is considered disabled if it ends
130 " in a tilde or its basename or full name is included in the list
131 " g:pathogen_disabled.
132 function! pathogen#is_disabled(path) " {{{1
135 elseif !exists("g:pathogen_disabled")
138 let sep = pathogen#separator()
139 let blacklist = g:pathogen_disabled
140 return index(blacklist, strpart(a:path, strridx(a:path, sep)+1)) != -1 && index(blacklist, a:path) != 1
143 " Prepend the given directory to the runtime path and append its corresponding
144 " after directory. If the directory is already included, move it to the
145 " outermost position. Wildcards are added as is. Ending a path in /{} causes
146 " all subdirectories to be added (except those in g:pathogen_disabled).
147 function! pathogen#surround(path) abort " {{{1
148 let sep = pathogen#separator()
149 let rtp = pathogen#split(&rtp)
150 if a:path =~# '[\\/]{}$'
151 let path = fnamemodify(a:path[0:-4], ':p:s?[\\/]\=$??')
152 let before = filter(pathogen#glob_directories(path.sep.'*'), '!pathogen#is_disabled(v:val)')
153 let after = filter(reverse(pathogen#glob_directories(path.sep."*".sep."after")), '!pathogen#is_disabled(v:val[0:-7])')
154 call filter(rtp,'v:val[0:strlen(path)-1] !=# path')
156 let path = fnamemodify(a:path, ':p:s?[\\/]\=$??')
158 let after = [path . sep . 'after']
159 call filter(rtp, 'index(before + after, v:val) == -1')
161 let &rtp = pathogen#join(before, rtp, after)
165 " Prepend all subdirectories of path to the rtp, and append all 'after'
166 " directories in those subdirectories. Deprecated.
167 function! pathogen#runtime_prepend_subdirectories(path) " {{{1
168 call s:warn('Change pathogen#runtime_prepend_subdirectories('.string(a:path).') to pathogen#surround('.string(a:path.'/{}').')')
169 return pathogen#surround(a:path . pathogen#separator() . '{}')
172 " For each directory in the runtime path, add a second entry with the given
173 " argument appended. If the argument ends in '/{}', add a separate entry for
174 " each subdirectory. The default argument is 'bundle/{}', which means that
175 " .vim/bundle/*, $VIM/vimfiles/bundle/*, $VIMRUNTIME/bundle/*,
176 " $VIM/vim/files/bundle/*/after, and .vim/bundle/*/after will be added (on
178 function! pathogen#incubate(...) abort " {{{1
179 let sep = pathogen#separator()
180 let name = a:0 ? a:1 : 'bundle/{}'
181 if "\n".s:done_bundles =~# "\\M\n".name."\n"
184 let s:done_bundles .= name . "\n"
186 for dir in pathogen#split(&rtp)
187 if dir =~# '\<after$'
189 let list += filter(pathogen#glob_directories(substitute(dir,'after$',name[0:-3],'').'*'.sep.'after'), '!pathogen#is_disabled(v:val[0:-7])') + [dir]
191 let list += [dir, substitute(dir, 'after$', '', '') . name . sep . 'after']
195 let list += [dir] + filter(pathogen#glob_directories(dir.sep.name[0:-3].'*'), '!pathogen#is_disabled(v:val)')
197 let list += [dir . sep . name, dir]
201 let &rtp = pathogen#join(pathogen#uniq(list))
205 " Deprecated alias for pathogen#incubate().
206 function! pathogen#runtime_append_all_bundles(...) abort " {{{1
208 call s:warn('Change pathogen#runtime_append_all_bundles('.string(a:1).') to pathogen#incubate('.string(a:1.'/{}').')')
210 call s:warn('Change pathogen#runtime_append_all_bundles() to pathogen#incubate()')
212 return call('pathogen#incubate', map(copy(a:000),'v:val . "/{}"'))
215 let s:done_bundles = ''
218 " Invoke :helptags on all non-$VIM doc directories in runtimepath.
219 function! pathogen#helptags() abort " {{{1
220 let sep = pathogen#separator()
221 for glob in pathogen#split(&rtp)
222 for dir in split(glob(glob), "\n")
223 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'))
224 silent! execute 'helptags' pathogen#fnameescape(dir.'/doc')
230 command! -bar Helptags :call pathogen#helptags()
232 " Execute the given command. This is basically a backdoor for --remote-expr.
233 function! pathogen#execute(...) abort " {{{1
240 " Like findfile(), but hardcoded to use the runtimepath.
241 function! pathogen#runtime_findfile(file,count) abort "{{{1
242 let rtp = pathogen#join(1,pathogen#split(&rtp))
243 let file = findfile(a:file,rtp,a:count)
247 return fnamemodify(file,':p')
251 " Backport of fnameescape().
252 function! pathogen#fnameescape(string) abort " {{{1
253 if exists('*fnameescape')
254 return fnameescape(a:string)
255 elseif a:string ==# '-'
258 return substitute(escape(a:string," \t\n*?[{`$\\%#'\"|!<"),'^[+>]','\\&','')
266 let s:vopen_warning = 0
268 function! s:find(count,cmd,file,lcd) " {{{1
269 let rtp = pathogen#join(1,pathogen#split(&runtimepath))
270 let file = pathogen#runtime_findfile(a:file,a:count)
272 return "echoerr 'E345: Can''t find file \"".a:file."\" in runtimepath'"
275 let s:vopen_warning = 1
276 let warning = '|echohl WarningMsg|echo "Install scriptease.vim to continue using :V'.a:cmd.'"|echohl NONE'
281 let path = file[0:-strlen(a:file)-2]
282 execute 'lcd `=path`'
283 return a:cmd.' '.pathogen#fnameescape(a:file) . warning
285 return a:cmd.' '.pathogen#fnameescape(file) . warning
289 function! s:Findcomplete(A,L,P) " {{{1
290 let sep = pathogen#separator()
298 if a:A =~# '^\w[\\/]' && has_key(cheats,a:A[0])
299 let request = cheats[a:A[0]].a:A[1:-1]
303 let pattern = substitute(request,'/\|\'.sep,'*'.sep,'g').'*'
305 for path in pathogen#split(&runtimepath)
306 let path = expand(path, ':p')
307 let matches = split(glob(path.sep.pattern),"\n")
308 call map(matches,'isdirectory(v:val) ? v:val.sep : v:val')
309 call map(matches,'expand(v:val, ":p")[strlen(path)+1:-1]')
314 return sort(keys(found))
317 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Ve :execute s:find(<count>,'edit<bang>',<q-args>,0)
318 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vedit :execute s:find(<count>,'edit<bang>',<q-args>,0)
319 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vopen :execute s:find(<count>,'edit<bang>',<q-args>,1)
320 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vsplit :execute s:find(<count>,'split',<q-args>,<bang>1)
321 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vvsplit :execute s:find(<count>,'vsplit',<q-args>,<bang>1)
322 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vtabedit :execute s:find(<count>,'tabedit',<q-args>,<bang>1)
323 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vpedit :execute s:find(<count>,'pedit',<q-args>,<bang>1)
324 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vread :execute s:find(<count>,'read',<q-args>,<bang>1)