All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
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.
13 if exists("g:loaded_pathogen") || &cp
16 let g:loaded_pathogen = 1
18 " Point of entry for basic default usage. Give a relative path to invoke
19 " pathogen#interpose() or an absolute path to invoke pathogen#surround().
20 " Curly braces are expanded with pathogen#expand(): "bundle/{}" finds all
21 " subdirectories inside "bundle" inside all directories in the runtime path.
22 " If no arguments are given, defaults "bundle/{}", and also "pack/{}/start/{}"
23 " on versions of Vim without native package support.
24 function! pathogen#infect(...) abort
26 let paths = filter(reverse(copy(a:000)), 'type(v:val) == type("")')
28 let paths = ['bundle/{}', 'pack/{}/start/{}']
31 call filter(paths, 'v:val !~# "^pack/[^/]*/start/[^/]*$"')
33 let static = '^\%([$~\\/]\|\w:[\\/]\)[^{}*]*$'
34 for path in filter(copy(paths), 'v:val =~# static')
35 call pathogen#surround(path)
37 for path in filter(copy(paths), 'v:val !~# static')
38 if path =~# '^\%([$~\\/]\|\w:[\\/]\)'
39 call pathogen#surround(path)
41 call pathogen#interpose(path)
44 call pathogen#cycle_filetype()
45 if pathogen#is_disabled($MYVIMRC)
51 " Split a path into a list.
52 function! pathogen#split(path) abort
53 if type(a:path) == type([]) | return a:path | endif
54 if empty(a:path) | return [] | endif
55 let split = split(a:path,'\\\@<!\%(\\\\\)*\zs,')
56 return map(split,'substitute(v:val,''\\\([\\,]\)'',''\1'',"g")')
59 " Convert a list to a path.
60 function! pathogen#join(...) abort
61 if type(a:1) == type(1) && a:1
70 if type(a:000[i]) == type([])
74 let escaped = substitute(list[j],'[,'.space.']\|\\[\,'.space.']\@=','\\&','g')
75 let path .= ',' . escaped
79 let path .= "," . a:000[i]
83 return substitute(path,'^,','','')
86 " Convert a list to a path with escaped spaces for 'path', 'tag', etc.
87 function! pathogen#legacyjoin(...) abort
88 return call('pathogen#join',[1] + a:000)
91 " Turn filetype detection off and back on again if it was already enabled.
92 function! pathogen#cycle_filetype() abort
93 if exists('g:did_load_filetypes')
99 " Check if a bundle is disabled. A bundle is considered disabled if its
100 " basename or full name is included in the list g:pathogen_blacklist or the
101 " comma delimited environment variable $VIMBLACKLIST.
102 function! pathogen#is_disabled(path) abort
106 let sep = pathogen#slash()
107 let blacklist = get(g:, 'pathogen_blacklist', get(g:, 'pathogen_disabled', [])) + pathogen#split($VIMBLACKLIST)
109 call map(blacklist, 'substitute(v:val, "[\\/]$", "", "")')
111 return index(blacklist, fnamemodify(a:path, ':t')) != -1 || index(blacklist, a:path) != -1
114 " Prepend the given directory to the runtime path and append its corresponding
115 " after directory. Curly braces are expanded with pathogen#expand().
116 function! pathogen#surround(path) abort
117 let sep = pathogen#slash()
118 let rtp = pathogen#split(&rtp)
119 let path = fnamemodify(a:path, ':s?[\\/]\=$??')
120 let before = filter(pathogen#expand(path), '!pathogen#is_disabled(v:val)')
121 let after = filter(reverse(pathogen#expand(path, sep.'after')), '!pathogen#is_disabled(v:val[0 : -7])')
122 call filter(rtp, 'index(before + after, v:val) == -1')
123 let &rtp = pathogen#join(before, rtp, after)
127 " For each directory in the runtime path, add a second entry with the given
128 " argument appended. Curly braces are expanded with pathogen#expand().
129 function! pathogen#interpose(name) abort
130 let sep = pathogen#slash()
132 if has_key(s:done_bundles, name)
135 let s:done_bundles[name] = 1
137 for dir in pathogen#split(&rtp)
138 if dir =~# '\<after$'
139 let list += reverse(filter(pathogen#expand(dir[0 : -6].name, sep.'after'), '!pathogen#is_disabled(v:val[0 : -7])')) + [dir]
141 let list += [dir] + filter(pathogen#expand(dir.sep.name), '!pathogen#is_disabled(v:val)')
144 let &rtp = pathogen#join(pathogen#uniq(list))
148 let s:done_bundles = {}
150 " Invoke :helptags on all non-$VIM doc directories in runtimepath.
151 function! pathogen#helptags() abort
152 let sep = pathogen#slash()
153 for glob in pathogen#split(&rtp)
154 for dir in map(split(glob(glob), "\n"), 'v:val.sep."/doc/".sep')
155 if (dir)[0 : strlen($VIMRUNTIME)] !=# $VIMRUNTIME.sep && filewritable(dir) == 2 && !empty(split(glob(dir.'*.txt'))) && (!filereadable(dir.'tags') || filewritable(dir.'tags'))
156 silent! execute 'helptags' pathogen#fnameescape(dir)
162 command! -bar Helptags :call pathogen#helptags()
164 " Execute the given command. This is basically a backdoor for --remote-expr.
165 function! pathogen#execute(...) abort
172 " Section: Unofficial
174 function! pathogen#is_absolute(path) abort
175 return a:path =~# (has('win32') ? '^\%([\\/]\|\w:\)[\\/]\|^[~$]' : '^[/~$]')
178 " Given a string, returns all possible permutations of comma delimited braced
179 " alternatives of that string. pathogen#expand('/{a,b}/{c,d}') yields
180 " ['/a/c', '/a/d', '/b/c', '/b/d']. Empty braces are treated as a wildcard
181 " and globbed. Actual globs are preserved.
182 function! pathogen#expand(pattern, ...) abort
183 let after = a:0 ? a:1 : ''
184 let pattern = substitute(a:pattern, '^[~$][^\/]*', '\=expand(submatch(0))', '')
185 if pattern =~# '{[^{}]\+}'
186 let [pre, pat, post] = split(substitute(pattern, '\(.\{-\}\){\([^{}]\+\)}\(.*\)', "\\1\001\\2\001\\3", ''), "\001", 1)
187 let found = map(split(pat, ',', 1), 'pre.v:val.post')
190 call extend(results, pathogen#expand(pattern))
192 elseif pattern =~# '{}'
193 let pat = matchstr(pattern, '^.*{}[^*]*\%($\|[\\/]\)')
194 let post = pattern[strlen(pat) : -1]
195 let results = map(split(glob(substitute(pat, '{}', '*', 'g')), "\n"), 'v:val.post')
197 let results = [pattern]
199 let vf = pathogen#slash() . 'vimfiles'
200 call map(results, 'v:val =~# "\\*" ? v:val.after : isdirectory(v:val.vf.after) ? v:val.vf.after : isdirectory(v:val.after) ? v:val.after : ""')
201 return filter(results, '!empty(v:val)')
204 " \ on Windows unless shellslash is set, / everywhere else.
205 function! pathogen#slash() abort
206 return !exists("+shellslash") || &shellslash ? '/' : '\'
209 function! pathogen#separator() abort
210 return pathogen#slash()
213 " Convenience wrapper around glob() which returns a list.
214 function! pathogen#glob(pattern) abort
215 let files = split(glob(a:pattern),"\n")
216 return map(files,'substitute(v:val,"[".pathogen#slash()."/]$","","")')
219 " Like pathogen#glob(), only limit the results to directories.
220 function! pathogen#glob_directories(pattern) abort
221 return filter(pathogen#glob(a:pattern),'isdirectory(v:val)')
224 " Remove duplicates from a list.
225 function! pathogen#uniq(list) abort
228 while i < len(a:list)
229 if (a:list[i] ==# '' && exists('empty')) || has_key(seen,a:list[i])
230 call remove(a:list,i)
231 elseif a:list[i] ==# ''
235 let seen[a:list[i]] = 1
242 " Backport of fnameescape().
243 function! pathogen#fnameescape(string) abort
244 if exists('*fnameescape')
245 return fnameescape(a:string)
246 elseif a:string ==# '-'
249 return substitute(escape(a:string," \t\n*?[{`$\\%#'\"|!<"),'^[+>]','\\&','')
253 " Like findfile(), but hardcoded to use the runtimepath.
254 function! pathogen#runtime_findfile(file,count) abort
255 let rtp = pathogen#join(1,pathogen#split(&rtp))
256 let file = findfile(a:file,rtp,a:count)
260 return fnamemodify(file,':p')