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
19 " Point of entry for basic default usage. Give a relative path to invoke
20 " pathogen#interpose() (defaults to "bundle/{}"), or an absolute path to invoke
21 " pathogen#surround(). For backwards compatibility purposes, a full path that
22 " does not end in {} or * is given to pathogen#runtime_prepend_subdirectories()
24 function! pathogen#infect(...) abort " {{{1
25 for path in a:0 ? filter(reverse(copy(a:000)), 'type(v:val) == type("")') : ['bundle/{}']
26 if path =~# '^[^\\/]\+$'
27 call s:warn('Change pathogen#infect('.string(path).') to pathogen#infect('.string(path.'/{}').')')
28 call pathogen#interpose(path . '/{}')
29 elseif path =~# '^[^\\/]\+[\\/]\%({}\|\*\)$'
30 call pathogen#interpose(path)
31 elseif path =~# '[\\/]\%({}\|\*\)$'
32 call pathogen#surround(path)
34 call s:warn('Change pathogen#infect('.string(path).') to pathogen#infect('.string(path.'/{}').')')
35 call pathogen#surround(path . '/{}')
38 call pathogen#cycle_filetype()
42 " Split a path into a list.
43 function! pathogen#split(path) abort " {{{1
44 if type(a:path) == type([]) | return a:path | endif
45 let split = split(a:path,'\\\@<!\%(\\\\\)*\zs,')
46 return map(split,'substitute(v:val,''\\\([\\,]\)'',''\1'',"g")')
49 " Convert a list to a path.
50 function! pathogen#join(...) abort " {{{1
51 if type(a:1) == type(1) && a:1
60 if type(a:000[i]) == type([])
64 let escaped = substitute(list[j],'[,'.space.']\|\\[\,'.space.']\@=','\\&','g')
65 let path .= ',' . escaped
69 let path .= "," . a:000[i]
73 return substitute(path,'^,','','')
76 " Convert a list to a path with escaped spaces for 'path', 'tag', etc.
77 function! pathogen#legacyjoin(...) abort " {{{1
78 return call('pathogen#join',[1] + a:000)
81 " Turn filetype detection off and back on again if it was already enabled.
82 function! pathogen#cycle_filetype() " {{{1
83 if exists('g:did_load_filetypes')
89 " Check if a bundle is disabled. A bundle is considered disabled if its
90 " basename or full name is included in the list g:pathogen_disabled.
91 function! pathogen#is_disabled(path) abort " {{{1
92 let sep = pathogen#slash()
93 let blacklist = get(g:, 'pathogen_blacklist', get(g:, 'pathogen_disabled', []))
94 return index(blacklist, fnamemodify(a:path, ':t')) != -1 || index(blacklist, a:path) != -1
97 " Prepend the given directory to the runtime path and append its corresponding
98 " after directory. If the directory is already included, move it to the
99 " outermost position. Wildcards are added as is. Ending a path in /{} causes
100 " all subdirectories to be added (except those in g:pathogen_disabled).
101 function! pathogen#surround(path) abort " {{{1
102 let sep = pathogen#slash()
103 let rtp = pathogen#split(&rtp)
104 if a:path =~# '[\\/]{}$'
105 let path = fnamemodify(a:path[0:-4], ':p:s?[\\/]\=$??')
106 let before = filter(pathogen#glob_directories(path.sep.'*'), '!pathogen#is_disabled(v:val)')
107 let after = filter(reverse(pathogen#glob_directories(path.sep."*".sep."after")), '!pathogen#is_disabled(v:val[0:-7])')
108 call filter(rtp,'v:val[0:strlen(path)-1] !=# path')
110 let path = fnamemodify(a:path, ':p:s?[\\/]\=$??')
112 let after = [path . sep . 'after']
113 call filter(rtp, 'index(before + after, v:val) == -1')
115 let &rtp = pathogen#join(before, rtp, after)
119 " For each directory in the runtime path, add a second entry with the given
120 " argument appended. If the argument ends in '/{}', add a separate entry for
122 function! pathogen#interpose(name) abort " {{{1
123 let sep = pathogen#slash()
125 if has_key(s:done_bundles, name)
128 let s:done_bundles[name] = 1
130 for dir in pathogen#split(&rtp)
131 if dir =~# '\<after$'
133 let list += filter(pathogen#glob_directories(substitute(dir,'after$',name[0:-3],'').'*'.sep.'after'), '!pathogen#is_disabled(v:val[0:-7])') + [dir]
135 let list += [dir, substitute(dir, 'after$', '', '') . name . sep . 'after']
139 let list += [dir] + filter(pathogen#glob_directories(dir.sep.name[0:-3].'*'), '!pathogen#is_disabled(v:val)')
141 let list += [dir . sep . name, dir]
145 let &rtp = pathogen#join(pathogen#uniq(list))
149 let s:done_bundles = {}
153 " Invoke :helptags on all non-$VIM doc directories in runtimepath.
154 function! pathogen#helptags() abort " {{{1
155 let sep = pathogen#slash()
156 for glob in pathogen#split(&rtp)
157 for dir in map(split(glob(glob), "\n"), 'v:val.sep."/doc/".sep')
158 if (dir)[0 : strlen($VIMRUNTIME)] !=# $VIMRUNTIME.sep && filewritable(dir) == 2 && !empty(split(glob(dir.'*.txt'))) && (!filereadable(dir.'tags') || filewritable(dir.'tags'))
159 silent! execute 'helptags' pathogen#fnameescape(dir)
165 command! -bar Helptags :call pathogen#helptags()
167 " Execute the given command. This is basically a backdoor for --remote-expr.
168 function! pathogen#execute(...) abort " {{{1
175 " Section: Unofficial
177 " \ on Windows unless shellslash is set, / everywhere else.
178 function! pathogen#slash() abort " {{{1
179 return !exists("+shellslash") || &shellslash ? '/' : '\'
182 function! pathogen#separator() abort " {{{1
183 return pathogen#slash()
186 " Convenience wrapper around glob() which returns a list.
187 function! pathogen#glob(pattern) abort " {{{1
188 let files = split(glob(a:pattern),"\n")
189 return map(files,'substitute(v:val,"[".pathogen#slash()."/]$","","")')
192 " Like pathogen#glob(), only limit the results to directories.
193 function! pathogen#glob_directories(pattern) abort " {{{1
194 return filter(pathogen#glob(a:pattern),'isdirectory(v:val)')
197 " Remove duplicates from a list.
198 function! pathogen#uniq(list) abort " {{{1
201 while i < len(a:list)
202 if (a:list[i] ==# '' && exists('empty')) || has_key(seen,a:list[i])
203 call remove(a:list,i)
204 elseif a:list[i] ==# ''
208 let seen[a:list[i]] = 1
215 " Backport of fnameescape().
216 function! pathogen#fnameescape(string) abort " {{{1
217 if exists('*fnameescape')
218 return fnameescape(a:string)
219 elseif a:string ==# '-'
222 return substitute(escape(a:string," \t\n*?[{`$\\%#'\"|!<"),'^[+>]','\\&','')
226 " Like findfile(), but hardcoded to use the runtimepath.
227 function! pathogen#runtime_findfile(file,count) abort "{{{1
228 let rtp = pathogen#join(1,pathogen#split(&rtp))
229 let file = findfile(a:file,rtp,a:count)
233 return fnamemodify(file,':p')
237 " Section: Deprecated
239 function! s:warn(msg)
245 " Prepend all subdirectories of path to the rtp, and append all 'after'
246 " directories in those subdirectories. Deprecated.
247 function! pathogen#runtime_prepend_subdirectories(path) " {{{1
248 call s:warn('Change pathogen#runtime_prepend_subdirectories('.string(a:path).') to pathogen#infect('.string(a:path.'/{}').')')
249 return pathogen#surround(a:path . pathogen#slash() . '{}')
252 function! pathogen#incubate(...) abort " {{{1
253 let name = a:0 ? a:1 : 'bundle/{}'
254 call s:warn('Change pathogen#incubate('.(a:0 ? string(a:1) : '').') to pathogen#infect('.string(name).')')
255 return pathogen#interpose(name)
258 " Deprecated alias for pathogen#interpose().
259 function! pathogen#runtime_append_all_bundles(...) abort " {{{1
261 call s:warn('Change pathogen#runtime_append_all_bundles('.string(a:1).') to pathogen#infect('.string(a:1.'/{}').')')
263 call s:warn('Change pathogen#runtime_append_all_bundles() to pathogen#infect()')
265 return pathogen#interpose(a:0 ? a:1 . '/{}' : 'bundle/{}')
272 let s:vopen_warning = 0
274 function! s:find(count,cmd,file,lcd) " {{{1
275 let rtp = pathogen#join(1,pathogen#split(&runtimepath))
276 let file = pathogen#runtime_findfile(a:file,a:count)
278 return "echoerr 'E345: Can''t find file \"".a:file."\" in runtimepath'"
281 let s:vopen_warning = 1
282 let warning = '|echohl WarningMsg|echo "Install scriptease.vim to continue using :V'.a:cmd.'"|echohl NONE'
287 let path = file[0:-strlen(a:file)-2]
288 execute 'lcd `=path`'
289 return a:cmd.' '.pathogen#fnameescape(a:file) . warning
291 return a:cmd.' '.pathogen#fnameescape(file) . warning
295 function! s:Findcomplete(A,L,P) " {{{1
296 let sep = pathogen#slash()
304 if a:A =~# '^\w[\\/]' && has_key(cheats,a:A[0])
305 let request = cheats[a:A[0]].a:A[1:-1]
309 let pattern = substitute(request,'/\|\'.sep,'*'.sep,'g').'*'
311 for path in pathogen#split(&runtimepath)
312 let path = expand(path, ':p')
313 let matches = split(glob(path.sep.pattern),"\n")
314 call map(matches,'isdirectory(v:val) ? v:val.sep : v:val')
315 call map(matches,'expand(v:val, ":p")[strlen(path)+1:-1]')
320 return sort(keys(found))
323 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Ve :execute s:find(<count>,'edit<bang>',<q-args>,0)
324 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vedit :execute s:find(<count>,'edit<bang>',<q-args>,0)
325 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vopen :execute s:find(<count>,'edit<bang>',<q-args>,1)
326 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vsplit :execute s:find(<count>,'split',<q-args>,<bang>1)
327 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vvsplit :execute s:find(<count>,'vsplit',<q-args>,<bang>1)
328 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vtabedit :execute s:find(<count>,'tabedit',<q-args>,<bang>1)
329 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vpedit :execute s:find(<count>,'pedit',<q-args>,<bang>1)
330 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vread :execute s:find(<count>,'read',<q-args>,<bang>1)