|
| 1 | +" pathogen.vim - path option manipulation |
| 2 | +" Maintainer: Tim Pope <http://tpo.pe/> |
| 3 | +" Version: 2.4 |
| 4 | + |
| 5 | +" Install in ~/.vim/autoload (or ~\vimfiles\autoload). |
| 6 | +" |
| 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. |
| 10 | +" |
| 11 | +" The API is documented inline below. |
| 12 | + |
| 13 | +if exists("g:loaded_pathogen") || &cp |
| 14 | + finish |
| 15 | +endif |
| 16 | +let g:loaded_pathogen = 1 |
| 17 | + |
| 18 | +" Point of entry for basic default usage. Give a relative path to invoke |
| 19 | +" pathogen#interpose() (defaults to "bundle/{}"), or an absolute path to invoke |
| 20 | +" pathogen#surround(). Curly braces are expanded with pathogen#expand(): |
| 21 | +" "bundle/{}" finds all subdirectories inside "bundle" inside all directories |
| 22 | +" in the runtime path. |
| 23 | +function! pathogen#infect(...) abort |
| 24 | + for path in a:0 ? filter(reverse(copy(a:000)), 'type(v:val) == type("")') : ['bundle/{}'] |
| 25 | + if path =~# '^\%({\=[$~\\/]\|{\=\w:[\\/]\).*[{}*]' |
| 26 | + call pathogen#surround(path) |
| 27 | + elseif path =~# '^\%([$~\\/]\|\w:[\\/]\)' |
| 28 | + call s:warn('Change pathogen#infect('.string(path).') to pathogen#infect('.string(path.'/{}').')') |
| 29 | + call pathogen#surround(path . '/{}') |
| 30 | + elseif path =~# '[{}*]' |
| 31 | + call pathogen#interpose(path) |
| 32 | + else |
| 33 | + call s:warn('Change pathogen#infect('.string(path).') to pathogen#infect('.string(path.'/{}').')') |
| 34 | + call pathogen#interpose(path . '/{}') |
| 35 | + endif |
| 36 | + endfor |
| 37 | + call pathogen#cycle_filetype() |
| 38 | + if pathogen#is_disabled($MYVIMRC) |
| 39 | + return 'finish' |
| 40 | + endif |
| 41 | + return '' |
| 42 | +endfunction |
| 43 | + |
| 44 | +" Split a path into a list. |
| 45 | +function! pathogen#split(path) abort |
| 46 | + if type(a:path) == type([]) | return a:path | endif |
| 47 | + if empty(a:path) | return [] | endif |
| 48 | + let split = split(a:path,'\\\@<!\%(\\\\\)*\zs,') |
| 49 | + return map(split,'substitute(v:val,''\\\([\\,]\)'',''\1'',"g")') |
| 50 | +endfunction |
| 51 | + |
| 52 | +" Convert a list to a path. |
| 53 | +function! pathogen#join(...) abort |
| 54 | + if type(a:1) == type(1) && a:1 |
| 55 | + let i = 1 |
| 56 | + let space = ' ' |
| 57 | + else |
| 58 | + let i = 0 |
| 59 | + let space = '' |
| 60 | + endif |
| 61 | + let path = "" |
| 62 | + while i < a:0 |
| 63 | + if type(a:000[i]) == type([]) |
| 64 | + let list = a:000[i] |
| 65 | + let j = 0 |
| 66 | + while j < len(list) |
| 67 | + let escaped = substitute(list[j],'[,'.space.']\|\\[\,'.space.']\@=','\\&','g') |
| 68 | + let path .= ',' . escaped |
| 69 | + let j += 1 |
| 70 | + endwhile |
| 71 | + else |
| 72 | + let path .= "," . a:000[i] |
| 73 | + endif |
| 74 | + let i += 1 |
| 75 | + endwhile |
| 76 | + return substitute(path,'^,','','') |
| 77 | +endfunction |
| 78 | + |
| 79 | +" Convert a list to a path with escaped spaces for 'path', 'tag', etc. |
| 80 | +function! pathogen#legacyjoin(...) abort |
| 81 | + return call('pathogen#join',[1] + a:000) |
| 82 | +endfunction |
| 83 | + |
| 84 | +" Turn filetype detection off and back on again if it was already enabled. |
| 85 | +function! pathogen#cycle_filetype() abort |
| 86 | + if exists('g:did_load_filetypes') |
| 87 | + filetype off |
| 88 | + filetype on |
| 89 | + endif |
| 90 | +endfunction |
| 91 | + |
| 92 | +" Check if a bundle is disabled. A bundle is considered disabled if its |
| 93 | +" basename or full name is included in the list g:pathogen_blacklist or the |
| 94 | +" comma delimited environment variable $VIMBLACKLIST. |
| 95 | +function! pathogen#is_disabled(path) abort |
| 96 | + if a:path =~# '\~$' |
| 97 | + return 1 |
| 98 | + endif |
| 99 | + let sep = pathogen#slash() |
| 100 | + let blacklist = |
| 101 | + \ get(g:, 'pathogen_blacklist', get(g:, 'pathogen_disabled', [])) + |
| 102 | + \ pathogen#split($VIMBLACKLIST) |
| 103 | + if !empty(blacklist) |
| 104 | + call map(blacklist, 'substitute(v:val, "[\\/]$", "", "")') |
| 105 | + endif |
| 106 | + return index(blacklist, fnamemodify(a:path, ':t')) != -1 || index(blacklist, a:path) != -1 |
| 107 | +endfunction |
| 108 | + |
| 109 | +" Prepend the given directory to the runtime path and append its corresponding |
| 110 | +" after directory. Curly braces are expanded with pathogen#expand(). |
| 111 | +function! pathogen#surround(path) abort |
| 112 | + let sep = pathogen#slash() |
| 113 | + let rtp = pathogen#split(&rtp) |
| 114 | + let path = fnamemodify(a:path, ':s?[\\/]\=$??') |
| 115 | + let before = filter(pathogen#expand(path), '!pathogen#is_disabled(v:val)') |
| 116 | + let after = filter(reverse(pathogen#expand(path, sep.'after')), '!pathogen#is_disabled(v:val[0:-7])') |
| 117 | + call filter(rtp, 'index(before + after, v:val) == -1') |
| 118 | + let &rtp = pathogen#join(before, rtp, after) |
| 119 | + return &rtp |
| 120 | +endfunction |
| 121 | + |
| 122 | +" For each directory in the runtime path, add a second entry with the given |
| 123 | +" argument appended. Curly braces are expanded with pathogen#expand(). |
| 124 | +function! pathogen#interpose(name) abort |
| 125 | + let sep = pathogen#slash() |
| 126 | + let name = a:name |
| 127 | + if has_key(s:done_bundles, name) |
| 128 | + return "" |
| 129 | + endif |
| 130 | + let s:done_bundles[name] = 1 |
| 131 | + let list = [] |
| 132 | + for dir in pathogen#split(&rtp) |
| 133 | + if dir =~# '\<after$' |
| 134 | + let list += reverse(filter(pathogen#expand(dir[0:-6].name, sep.'after'), '!pathogen#is_disabled(v:val[0:-7])')) + [dir] |
| 135 | + else |
| 136 | + let list += [dir] + filter(pathogen#expand(dir.sep.name), '!pathogen#is_disabled(v:val)') |
| 137 | + endif |
| 138 | + endfor |
| 139 | + let &rtp = pathogen#join(pathogen#uniq(list)) |
| 140 | + return 1 |
| 141 | +endfunction |
| 142 | + |
| 143 | +let s:done_bundles = {} |
| 144 | + |
| 145 | +" Invoke :helptags on all non-$VIM doc directories in runtimepath. |
| 146 | +function! pathogen#helptags() abort |
| 147 | + let sep = pathogen#slash() |
| 148 | + for glob in pathogen#split(&rtp) |
| 149 | + for dir in map(split(glob(glob), "\n"), 'v:val.sep."/doc/".sep') |
| 150 | + if (dir)[0 : strlen($VIMRUNTIME)] !=# $VIMRUNTIME.sep && filewritable(dir) == 2 && !empty(split(glob(dir.'*.txt'))) && (!filereadable(dir.'tags') || filewritable(dir.'tags')) |
| 151 | + silent! execute 'helptags' pathogen#fnameescape(dir) |
| 152 | + endif |
| 153 | + endfor |
| 154 | + endfor |
| 155 | +endfunction |
| 156 | + |
| 157 | +command! -bar Helptags :call pathogen#helptags() |
| 158 | + |
| 159 | +" Execute the given command. This is basically a backdoor for --remote-expr. |
| 160 | +function! pathogen#execute(...) abort |
| 161 | + for command in a:000 |
| 162 | + execute command |
| 163 | + endfor |
| 164 | + return '' |
| 165 | +endfunction |
| 166 | + |
| 167 | +" Section: Unofficial |
| 168 | + |
| 169 | +function! pathogen#is_absolute(path) abort |
| 170 | + return a:path =~# (has('win32') ? '^\%([\\/]\|\w:\)[\\/]\|^[~$]' : '^[/~$]') |
| 171 | +endfunction |
| 172 | + |
| 173 | +" Given a string, returns all possible permutations of comma delimited braced |
| 174 | +" alternatives of that string. pathogen#expand('/{a,b}/{c,d}') yields |
| 175 | +" ['/a/c', '/a/d', '/b/c', '/b/d']. Empty braces are treated as a wildcard |
| 176 | +" and globbed. Actual globs are preserved. |
| 177 | +function! pathogen#expand(pattern, ...) abort |
| 178 | + let after = a:0 ? a:1 : '' |
| 179 | + if a:pattern =~# '{[^{}]\+}' |
| 180 | + let [pre, pat, post] = split(substitute(a:pattern, '\(.\{-\}\){\([^{}]\+\)}\(.*\)', "\\1\001\\2\001\\3", ''), "\001", 1) |
| 181 | + let found = map(split(pat, ',', 1), 'pre.v:val.post') |
| 182 | + let results = [] |
| 183 | + for pattern in found |
| 184 | + call extend(results, pathogen#expand(pattern)) |
| 185 | + endfor |
| 186 | + elseif a:pattern =~# '{}' |
| 187 | + let pat = matchstr(a:pattern, '^.*{}[^*]*\%($\|[\\/]\)') |
| 188 | + let post = a:pattern[strlen(pat) : -1] |
| 189 | + let results = map(split(glob(substitute(pat, '{}', '*', 'g')), "\n"), 'v:val.post') |
| 190 | + else |
| 191 | + let results = [a:pattern] |
| 192 | + endif |
| 193 | + let vf = pathogen#slash() . 'vimfiles' |
| 194 | + call map(results, 'v:val =~# "\\*" ? v:val.after : isdirectory(v:val.vf.after) ? v:val.vf.after : isdirectory(v:val.after) ? v:val.after : ""') |
| 195 | + return filter(results, '!empty(v:val)') |
| 196 | +endfunction |
| 197 | + |
| 198 | +" \ on Windows unless shellslash is set, / everywhere else. |
| 199 | +function! pathogen#slash() abort |
| 200 | + return !exists("+shellslash") || &shellslash ? '/' : '\' |
| 201 | +endfunction |
| 202 | + |
| 203 | +function! pathogen#separator() abort |
| 204 | + return pathogen#slash() |
| 205 | +endfunction |
| 206 | + |
| 207 | +" Convenience wrapper around glob() which returns a list. |
| 208 | +function! pathogen#glob(pattern) abort |
| 209 | + let files = split(glob(a:pattern),"\n") |
| 210 | + return map(files,'substitute(v:val,"[".pathogen#slash()."/]$","","")') |
| 211 | +endfunction |
| 212 | + |
| 213 | +" Like pathogen#glob(), only limit the results to directories. |
| 214 | +function! pathogen#glob_directories(pattern) abort |
| 215 | + return filter(pathogen#glob(a:pattern),'isdirectory(v:val)') |
| 216 | +endfunction |
| 217 | + |
| 218 | +" Remove duplicates from a list. |
| 219 | +function! pathogen#uniq(list) abort |
| 220 | + let i = 0 |
| 221 | + let seen = {} |
| 222 | + while i < len(a:list) |
| 223 | + if (a:list[i] ==# '' && exists('empty')) || has_key(seen,a:list[i]) |
| 224 | + call remove(a:list,i) |
| 225 | + elseif a:list[i] ==# '' |
| 226 | + let i += 1 |
| 227 | + let empty = 1 |
| 228 | + else |
| 229 | + let seen[a:list[i]] = 1 |
| 230 | + let i += 1 |
| 231 | + endif |
| 232 | + endwhile |
| 233 | + return a:list |
| 234 | +endfunction |
| 235 | + |
| 236 | +" Backport of fnameescape(). |
| 237 | +function! pathogen#fnameescape(string) abort |
| 238 | + if exists('*fnameescape') |
| 239 | + return fnameescape(a:string) |
| 240 | + elseif a:string ==# '-' |
| 241 | + return '\-' |
| 242 | + else |
| 243 | + return substitute(escape(a:string," \t\n*?[{`$\\%#'\"|!<"),'^[+>]','\\&','') |
| 244 | + endif |
| 245 | +endfunction |
| 246 | + |
| 247 | +" Like findfile(), but hardcoded to use the runtimepath. |
| 248 | +function! pathogen#runtime_findfile(file,count) abort |
| 249 | + let rtp = pathogen#join(1,pathogen#split(&rtp)) |
| 250 | + let file = findfile(a:file,rtp,a:count) |
| 251 | + if file ==# '' |
| 252 | + return '' |
| 253 | + else |
| 254 | + return fnamemodify(file,':p') |
| 255 | + endif |
| 256 | +endfunction |
| 257 | + |
| 258 | +" Section: Deprecated |
| 259 | + |
| 260 | +function! s:warn(msg) abort |
| 261 | + echohl WarningMsg |
| 262 | + echomsg a:msg |
| 263 | + echohl NONE |
| 264 | +endfunction |
| 265 | + |
| 266 | +" Prepend all subdirectories of path to the rtp, and append all 'after' |
| 267 | +" directories in those subdirectories. Deprecated. |
| 268 | +function! pathogen#runtime_prepend_subdirectories(path) abort |
| 269 | + call s:warn('Change pathogen#runtime_prepend_subdirectories('.string(a:path).') to pathogen#infect('.string(a:path.'/{}').')') |
| 270 | + return pathogen#surround(a:path . pathogen#slash() . '{}') |
| 271 | +endfunction |
| 272 | + |
| 273 | +function! pathogen#incubate(...) abort |
| 274 | + let name = a:0 ? a:1 : 'bundle/{}' |
| 275 | + call s:warn('Change pathogen#incubate('.(a:0 ? string(a:1) : '').') to pathogen#infect('.string(name).')') |
| 276 | + return pathogen#interpose(name) |
| 277 | +endfunction |
| 278 | + |
| 279 | +" Deprecated alias for pathogen#interpose(). |
| 280 | +function! pathogen#runtime_append_all_bundles(...) abort |
| 281 | + if a:0 |
| 282 | + call s:warn('Change pathogen#runtime_append_all_bundles('.string(a:1).') to pathogen#infect('.string(a:1.'/{}').')') |
| 283 | + else |
| 284 | + call s:warn('Change pathogen#runtime_append_all_bundles() to pathogen#infect()') |
| 285 | + endif |
| 286 | + return pathogen#interpose(a:0 ? a:1 . '/{}' : 'bundle/{}') |
| 287 | +endfunction |
| 288 | + |
| 289 | +if exists(':Vedit') |
| 290 | + finish |
| 291 | +endif |
| 292 | + |
| 293 | +let s:vopen_warning = 0 |
| 294 | + |
| 295 | +function! s:find(count,cmd,file,lcd) |
| 296 | + let rtp = pathogen#join(1,pathogen#split(&runtimepath)) |
| 297 | + let file = pathogen#runtime_findfile(a:file,a:count) |
| 298 | + if file ==# '' |
| 299 | + return "echoerr 'E345: Can''t find file \"".a:file."\" in runtimepath'" |
| 300 | + endif |
| 301 | + if !s:vopen_warning |
| 302 | + let s:vopen_warning = 1 |
| 303 | + let warning = '|echohl WarningMsg|echo "Install scriptease.vim to continue using :V'.a:cmd.'"|echohl NONE' |
| 304 | + else |
| 305 | + let warning = '' |
| 306 | + endif |
| 307 | + if a:lcd |
| 308 | + let path = file[0:-strlen(a:file)-2] |
| 309 | + execute 'lcd `=path`' |
| 310 | + return a:cmd.' '.pathogen#fnameescape(a:file) . warning |
| 311 | + else |
| 312 | + return a:cmd.' '.pathogen#fnameescape(file) . warning |
| 313 | + endif |
| 314 | +endfunction |
| 315 | + |
| 316 | +function! s:Findcomplete(A,L,P) |
| 317 | + let sep = pathogen#slash() |
| 318 | + let cheats = { |
| 319 | + \'a': 'autoload', |
| 320 | + \'d': 'doc', |
| 321 | + \'f': 'ftplugin', |
| 322 | + \'i': 'indent', |
| 323 | + \'p': 'plugin', |
| 324 | + \'s': 'syntax'} |
| 325 | + if a:A =~# '^\w[\\/]' && has_key(cheats,a:A[0]) |
| 326 | + let request = cheats[a:A[0]].a:A[1:-1] |
| 327 | + else |
| 328 | + let request = a:A |
| 329 | + endif |
| 330 | + let pattern = substitute(request,'/\|\'.sep,'*'.sep,'g').'*' |
| 331 | + let found = {} |
| 332 | + for path in pathogen#split(&runtimepath) |
| 333 | + let path = expand(path, ':p') |
| 334 | + let matches = split(glob(path.sep.pattern),"\n") |
| 335 | + call map(matches,'isdirectory(v:val) ? v:val.sep : v:val') |
| 336 | + call map(matches,'expand(v:val, ":p")[strlen(path)+1:-1]') |
| 337 | + for match in matches |
| 338 | + let found[match] = 1 |
| 339 | + endfor |
| 340 | + endfor |
| 341 | + return sort(keys(found)) |
| 342 | +endfunction |
| 343 | + |
| 344 | +command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Ve :execute s:find(<count>,'edit<bang>',<q-args>,0) |
| 345 | +command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vedit :execute s:find(<count>,'edit<bang>',<q-args>,0) |
| 346 | +command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vopen :execute s:find(<count>,'edit<bang>',<q-args>,1) |
| 347 | +command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vsplit :execute s:find(<count>,'split',<q-args>,<bang>1) |
| 348 | +command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vvsplit :execute s:find(<count>,'vsplit',<q-args>,<bang>1) |
| 349 | +command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vtabedit :execute s:find(<count>,'tabedit',<q-args>,<bang>1) |
| 350 | +command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vpedit :execute s:find(<count>,'pedit',<q-args>,<bang>1) |
| 351 | +command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vread :execute s:find(<count>,'read',<q-args>,<bang>1) |
| 352 | + |
| 353 | +" vim:set et sw=2 foldmethod=expr foldexpr=getline(v\:lnum)=~'^\"\ Section\:'?'>1'\:getline(v\:lnum)=~#'^fu'?'a1'\:getline(v\:lnum)=~#'^endf'?'s1'\:'=': |
0 commit comments