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 your .vimrc
9 " prior to `filetype plugin indent on` 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 directory name to invoke
20 " pathogen#runtime_append_all_bundles() (defaults to "bundle"), or a full path
21 " to invoke pathogen#runtime_prepend_subdirectories(). Afterwards,
22 " pathogen#cycle_filetype() is invoked.
23 function! pathogen#infect(...) abort " {{{1
24 let source_path = a:0 ? a:1 : 'bundle'
25 if source_path =~# '[\\/]'
26 call pathogen#runtime_prepend_subdirectories(source_path)
28 call pathogen#runtime_append_all_bundles(source_path)
30 call pathogen#cycle_filetype()
33 " Split a path into a list.
34 function! pathogen#split(path) abort " {{{1
35 if type(a:path) == type([]) | return a:path | endif
36 let split = split(a:path,'\\\@<!\%(\\\\\)*\zs,')
37 return map(split,'substitute(v:val,''\\\([\\,]\)'',''\1'',"g")')
40 " Convert a list to a path.
41 function! pathogen#join(...) abort " {{{1
42 if type(a:1) == type(1) && a:1
51 if type(a:000[i]) == type([])
55 let escaped = substitute(list[j],'[,'.space.']\|\\[\,'.space.']\@=','\\&','g')
56 let path .= ',' . escaped
60 let path .= "," . a:000[i]
64 return substitute(path,'^,','','')
67 " Convert a list to a path with escaped spaces for 'path', 'tag', etc.
68 function! pathogen#legacyjoin(...) abort " {{{1
69 return call('pathogen#join',[1] + a:000)
72 " Remove duplicates from a list.
73 function! pathogen#uniq(list) abort " {{{1
77 if (a:list[i] ==# '' && exists('empty')) || has_key(seen,a:list[i])
79 elseif a:list[i] ==# ''
83 let seen[a:list[i]] = 1
90 " \ on Windows unless shellslash is set, / everywhere else.
91 function! pathogen#separator() abort " {{{1
92 return !exists("+shellslash") || &shellslash ? '/' : '\'
95 " Convenience wrapper around glob() which returns a list.
96 function! pathogen#glob(pattern) abort " {{{1
97 let files = split(glob(a:pattern),"\n")
98 return map(files,'substitute(v:val,"[".pathogen#separator()."/]$","","")')
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)')
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')
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
119 elseif !exists("g:pathogen_disabled")
122 let sep = pathogen#separator()
123 return index(g:pathogen_disabled, strpart(a:path, strridx(a:path, sep)+1)) != -1
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))
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"
149 let s:done_bundles .= name . "\n"
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]
155 let list += [dir] + filter(pathogen#glob_directories(dir.sep.name.sep.'*[^~]'), '!pathogen#is_disabled(v:val)')
158 let &rtp = pathogen#join(pathogen#uniq(list))
162 let s:done_bundles = ''
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'`
175 command! -bar Helptags :call pathogen#helptags()
177 " Like findfile(), but hardcoded to use the runtimepath.
178 function! pathogen#runtime_findfile(file,count) "{{{1
179 let rtp = pathogen#join(1,pathogen#split(&rtp))
180 let file = findfile(a:file,rtp,a:count)
184 return fnamemodify(file,':p')
188 " Backport of fnameescape().
189 function! pathogen#fnameescape(string) " {{{1
190 if exists('*fnameescape')
191 return fnameescape(a:string)
192 elseif a:string ==# '-'
195 return substitute(escape(a:string," \t\n*?[{`$\\%#'\"|!<"),'^[+>]','\\&','')
199 function! s:find(count,cmd,file,lcd) " {{{1
200 let rtp = pathogen#join(1,pathogen#split(&runtimepath))
201 let file = pathogen#runtime_findfile(a:file,a:count)
203 return "echoerr 'E345: Can''t find file \"".a:file."\" in runtimepath'"
205 let path = file[0:-strlen(a:file)-2]
206 execute 'lcd `=path`'
207 return a:cmd.' '.pathogen#fnameescape(a:file)
209 return a:cmd.' '.pathogen#fnameescape(file)
213 function! s:Findcomplete(A,L,P) " {{{1
214 let sep = pathogen#separator()
222 if a:A =~# '^\w[\\/]' && has_key(cheats,a:A[0])
223 let request = cheats[a:A[0]].a:A[1:-1]
227 let pattern = substitute(request,'/\|\'.sep,'*'.sep,'g').'*'
229 for path in pathogen#split(&runtimepath)
230 let path = expand(path, ':p')
231 let matches = split(glob(path.sep.pattern),"\n")
232 call map(matches,'isdirectory(v:val) ? v:val.sep : v:val')
233 call map(matches,'expand(v:val, ":p")[strlen(path)+1:-1]')
238 return sort(keys(found))
241 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Ve :execute s:find(<count>,'edit<bang>',<q-args>,0)
242 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vedit :execute s:find(<count>,'edit<bang>',<q-args>,0)
243 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vopen :execute s:find(<count>,'edit<bang>',<q-args>,1)
244 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vsplit :execute s:find(<count>,'split',<q-args>,<bang>1)
245 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vvsplit :execute s:find(<count>,'vsplit',<q-args>,<bang>1)
246 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vtabedit :execute s:find(<count>,'tabedit',<q-args>,<bang>1)
247 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vpedit :execute s:find(<count>,'pedit',<q-args>,<bang>1)
248 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vread :execute s:find(<count>,'read',<q-args>,<bang>1)
250 " vim:set ft=vim ts=8 sw=2 sts=2: