annotate vim/vimfiles/autoload/pathogen.vim @ 18:2cc96559ecac

Ignore .pyc files.
author Brian Neal <bgneal@gmail.com>
date Sun, 19 Jan 2014 11:32:42 -0600
parents ff60fbc930de
children
rev   line source
bgneal@6 1 " pathogen.vim - path option manipulation
bgneal@6 2 " Maintainer: Tim Pope <http://tpo.pe/>
bgneal@6 3 " Version: 2.0
bgneal@6 4
bgneal@6 5 " Install in ~/.vim/autoload (or ~\vimfiles\autoload).
bgneal@6 6 "
bgneal@6 7 " For management of individually installed plugins in ~/.vim/bundle (or
bgneal@6 8 " ~\vimfiles\bundle), adding `call pathogen#infect()` to your .vimrc
bgneal@6 9 " prior to `filetype plugin indent on` is the only other setup necessary.
bgneal@6 10 "
bgneal@6 11 " The API is documented inline below. For maximum ease of reading,
bgneal@6 12 " :set foldmethod=marker
bgneal@6 13
bgneal@6 14 if exists("g:loaded_pathogen") || &cp
bgneal@6 15 finish
bgneal@6 16 endif
bgneal@6 17 let g:loaded_pathogen = 1
bgneal@6 18
bgneal@6 19 " Point of entry for basic default usage. Give a directory name to invoke
bgneal@6 20 " pathogen#runtime_append_all_bundles() (defaults to "bundle"), or a full path
bgneal@6 21 " to invoke pathogen#runtime_prepend_subdirectories(). Afterwards,
bgneal@6 22 " pathogen#cycle_filetype() is invoked.
bgneal@6 23 function! pathogen#infect(...) abort " {{{1
bgneal@6 24 let source_path = a:0 ? a:1 : 'bundle'
bgneal@6 25 if source_path =~# '[\\/]'
bgneal@6 26 call pathogen#runtime_prepend_subdirectories(source_path)
bgneal@6 27 else
bgneal@6 28 call pathogen#runtime_append_all_bundles(source_path)
bgneal@6 29 endif
bgneal@6 30 call pathogen#cycle_filetype()
bgneal@6 31 endfunction " }}}1
bgneal@6 32
bgneal@6 33 " Split a path into a list.
bgneal@6 34 function! pathogen#split(path) abort " {{{1
bgneal@6 35 if type(a:path) == type([]) | return a:path | endif
bgneal@6 36 let split = split(a:path,'\\\@<!\%(\\\\\)*\zs,')
bgneal@6 37 return map(split,'substitute(v:val,''\\\([\\,]\)'',''\1'',"g")')
bgneal@6 38 endfunction " }}}1
bgneal@6 39
bgneal@6 40 " Convert a list to a path.
bgneal@6 41 function! pathogen#join(...) abort " {{{1
bgneal@6 42 if type(a:1) == type(1) && a:1
bgneal@6 43 let i = 1
bgneal@6 44 let space = ' '
bgneal@6 45 else
bgneal@6 46 let i = 0
bgneal@6 47 let space = ''
bgneal@6 48 endif
bgneal@6 49 let path = ""
bgneal@6 50 while i < a:0
bgneal@6 51 if type(a:000[i]) == type([])
bgneal@6 52 let list = a:000[i]
bgneal@6 53 let j = 0
bgneal@6 54 while j < len(list)
bgneal@6 55 let escaped = substitute(list[j],'[,'.space.']\|\\[\,'.space.']\@=','\\&','g')
bgneal@6 56 let path .= ',' . escaped
bgneal@6 57 let j += 1
bgneal@6 58 endwhile
bgneal@6 59 else
bgneal@6 60 let path .= "," . a:000[i]
bgneal@6 61 endif
bgneal@6 62 let i += 1
bgneal@6 63 endwhile
bgneal@6 64 return substitute(path,'^,','','')
bgneal@6 65 endfunction " }}}1
bgneal@6 66
bgneal@6 67 " Convert a list to a path with escaped spaces for 'path', 'tag', etc.
bgneal@6 68 function! pathogen#legacyjoin(...) abort " {{{1
bgneal@6 69 return call('pathogen#join',[1] + a:000)
bgneal@6 70 endfunction " }}}1
bgneal@6 71
bgneal@6 72 " Remove duplicates from a list.
bgneal@6 73 function! pathogen#uniq(list) abort " {{{1
bgneal@6 74 let i = 0
bgneal@6 75 let seen = {}
bgneal@6 76 while i < len(a:list)
bgneal@6 77 if (a:list[i] ==# '' && exists('empty')) || has_key(seen,a:list[i])
bgneal@6 78 call remove(a:list,i)
bgneal@6 79 elseif a:list[i] ==# ''
bgneal@6 80 let i += 1
bgneal@6 81 let empty = 1
bgneal@6 82 else
bgneal@6 83 let seen[a:list[i]] = 1
bgneal@6 84 let i += 1
bgneal@6 85 endif
bgneal@6 86 endwhile
bgneal@6 87 return a:list
bgneal@6 88 endfunction " }}}1
bgneal@6 89
bgneal@6 90 " \ on Windows unless shellslash is set, / everywhere else.
bgneal@6 91 function! pathogen#separator() abort " {{{1
bgneal@6 92 return !exists("+shellslash") || &shellslash ? '/' : '\'
bgneal@6 93 endfunction " }}}1
bgneal@6 94
bgneal@6 95 " Convenience wrapper around glob() which returns a list.
bgneal@6 96 function! pathogen#glob(pattern) abort " {{{1
bgneal@6 97 let files = split(glob(a:pattern),"\n")
bgneal@6 98 return map(files,'substitute(v:val,"[".pathogen#separator()."/]$","","")')
bgneal@6 99 endfunction "}}}1
bgneal@6 100
bgneal@6 101 " Like pathogen#glob(), only limit the results to directories.
bgneal@6 102 function! pathogen#glob_directories(pattern) abort " {{{1
bgneal@6 103 return filter(pathogen#glob(a:pattern),'isdirectory(v:val)')
bgneal@6 104 endfunction "}}}1
bgneal@6 105
bgneal@6 106 " Turn filetype detection off and back on again if it was already enabled.
bgneal@6 107 function! pathogen#cycle_filetype() " {{{1
bgneal@6 108 if exists('g:did_load_filetypes')
bgneal@6 109 filetype off
bgneal@6 110 filetype on
bgneal@6 111 endif
bgneal@6 112 endfunction " }}}1
bgneal@6 113
bgneal@6 114 " Checks if a bundle is 'disabled'. A bundle is considered 'disabled' if
bgneal@6 115 " its 'basename()' is included in g:pathogen_disabled[]' or ends in a tilde.
bgneal@6 116 function! pathogen#is_disabled(path) " {{{1
bgneal@6 117 if a:path =~# '\~$'
bgneal@6 118 return 1
bgneal@6 119 elseif !exists("g:pathogen_disabled")
bgneal@6 120 return 0
bgneal@6 121 endif
bgneal@6 122 let sep = pathogen#separator()
bgneal@6 123 return index(g:pathogen_disabled, strpart(a:path, strridx(a:path, sep)+1)) != -1
bgneal@6 124 endfunction "}}}1
bgneal@6 125
bgneal@6 126 " Prepend all subdirectories of path to the rtp, and append all 'after'
bgneal@6 127 " directories in those subdirectories.
bgneal@6 128 function! pathogen#runtime_prepend_subdirectories(path) " {{{1
bgneal@6 129 let sep = pathogen#separator()
bgneal@6 130 let before = filter(pathogen#glob_directories(a:path.sep."*"), '!pathogen#is_disabled(v:val)')
bgneal@6 131 let after = filter(pathogen#glob_directories(a:path.sep."*".sep."after"), '!pathogen#is_disabled(v:val[0:-7])')
bgneal@6 132 let rtp = pathogen#split(&rtp)
bgneal@6 133 let path = expand(a:path)
bgneal@6 134 call filter(rtp,'v:val[0:strlen(path)-1] !=# path')
bgneal@6 135 let &rtp = pathogen#join(pathogen#uniq(before + rtp + after))
bgneal@6 136 return &rtp
bgneal@6 137 endfunction " }}}1
bgneal@6 138
bgneal@6 139 " For each directory in rtp, check for a subdirectory named dir. If it
bgneal@6 140 " exists, add all subdirectories of that subdirectory to the rtp, immediately
bgneal@6 141 " after the original directory. If no argument is given, 'bundle' is used.
bgneal@6 142 " Repeated calls with the same arguments are ignored.
bgneal@6 143 function! pathogen#runtime_append_all_bundles(...) " {{{1
bgneal@6 144 let sep = pathogen#separator()
bgneal@6 145 let name = a:0 ? a:1 : 'bundle'
bgneal@6 146 if "\n".s:done_bundles =~# "\\M\n".name."\n"
bgneal@6 147 return ""
bgneal@6 148 endif
bgneal@6 149 let s:done_bundles .= name . "\n"
bgneal@6 150 let list = []
bgneal@6 151 for dir in pathogen#split(&rtp)
bgneal@6 152 if dir =~# '\<after$'
bgneal@6 153 let list += filter(pathogen#glob_directories(substitute(dir,'after$',name,'').sep.'*[^~]'.sep.'after'), '!pathogen#is_disabled(v:val[0:-7])') + [dir]
bgneal@6 154 else
bgneal@6 155 let list += [dir] + filter(pathogen#glob_directories(dir.sep.name.sep.'*[^~]'), '!pathogen#is_disabled(v:val)')
bgneal@6 156 endif
bgneal@6 157 endfor
bgneal@6 158 let &rtp = pathogen#join(pathogen#uniq(list))
bgneal@6 159 return 1
bgneal@6 160 endfunction
bgneal@6 161
bgneal@6 162 let s:done_bundles = ''
bgneal@6 163 " }}}1
bgneal@6 164
bgneal@6 165 " Invoke :helptags on all non-$VIM doc directories in runtimepath.
bgneal@6 166 function! pathogen#helptags() " {{{1
bgneal@6 167 let sep = pathogen#separator()
bgneal@6 168 for dir in pathogen#split(&rtp)
bgneal@6 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'))
bgneal@6 170 helptags `=dir.'/doc'`
bgneal@6 171 endif
bgneal@6 172 endfor
bgneal@6 173 endfunction " }}}1
bgneal@6 174
bgneal@6 175 command! -bar Helptags :call pathogen#helptags()
bgneal@6 176
bgneal@6 177 " Like findfile(), but hardcoded to use the runtimepath.
bgneal@6 178 function! pathogen#runtime_findfile(file,count) "{{{1
bgneal@6 179 let rtp = pathogen#join(1,pathogen#split(&rtp))
bgneal@6 180 return fnamemodify(findfile(a:file,rtp,a:count),':p')
bgneal@6 181 endfunction " }}}1
bgneal@6 182
bgneal@6 183 " Backport of fnameescape().
bgneal@6 184 function! pathogen#fnameescape(string) " {{{1
bgneal@6 185 if exists('*fnameescape')
bgneal@6 186 return fnameescape(a:string)
bgneal@6 187 elseif a:string ==# '-'
bgneal@6 188 return '\-'
bgneal@6 189 else
bgneal@6 190 return substitute(escape(a:string," \t\n*?[{`$\\%#'\"|!<"),'^[+>]','\\&','')
bgneal@6 191 endif
bgneal@6 192 endfunction " }}}1
bgneal@6 193
bgneal@6 194 function! s:find(count,cmd,file,lcd) " {{{1
bgneal@6 195 let rtp = pathogen#join(1,pathogen#split(&runtimepath))
bgneal@6 196 let file = pathogen#runtime_findfile(a:file,a:count)
bgneal@6 197 if file ==# ''
bgneal@6 198 return "echoerr 'E345: Can''t find file \"".a:file."\" in runtimepath'"
bgneal@6 199 elseif a:lcd
bgneal@6 200 let path = file[0:-strlen(a:file)-2]
bgneal@6 201 execute 'lcd `=path`'
bgneal@6 202 return a:cmd.' '.pathogen#fnameescape(a:file)
bgneal@6 203 else
bgneal@6 204 return a:cmd.' '.pathogen#fnameescape(file)
bgneal@6 205 endif
bgneal@6 206 endfunction " }}}1
bgneal@6 207
bgneal@6 208 function! s:Findcomplete(A,L,P) " {{{1
bgneal@6 209 let sep = pathogen#separator()
bgneal@6 210 let cheats = {
bgneal@6 211 \'a': 'autoload',
bgneal@6 212 \'d': 'doc',
bgneal@6 213 \'f': 'ftplugin',
bgneal@6 214 \'i': 'indent',
bgneal@6 215 \'p': 'plugin',
bgneal@6 216 \'s': 'syntax'}
bgneal@6 217 if a:A =~# '^\w[\\/]' && has_key(cheats,a:A[0])
bgneal@6 218 let request = cheats[a:A[0]].a:A[1:-1]
bgneal@6 219 else
bgneal@6 220 let request = a:A
bgneal@6 221 endif
bgneal@6 222 let pattern = substitute(request,'\'.sep,'*'.sep,'g').'*'
bgneal@6 223 let found = {}
bgneal@6 224 for path in pathogen#split(&runtimepath)
bgneal@6 225 let path = expand(path, ':p')
bgneal@6 226 let matches = split(glob(path.sep.pattern),"\n")
bgneal@6 227 call map(matches,'isdirectory(v:val) ? v:val.sep : v:val')
bgneal@6 228 call map(matches,'expand(v:val, ":p")[strlen(path)+1:-1]')
bgneal@6 229 for match in matches
bgneal@6 230 let found[match] = 1
bgneal@6 231 endfor
bgneal@6 232 endfor
bgneal@6 233 return sort(keys(found))
bgneal@6 234 endfunction " }}}1
bgneal@6 235
bgneal@6 236 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Ve :execute s:find(<count>,'edit<bang>',<q-args>,0)
bgneal@6 237 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vedit :execute s:find(<count>,'edit<bang>',<q-args>,0)
bgneal@6 238 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vopen :execute s:find(<count>,'edit<bang>',<q-args>,1)
bgneal@6 239 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vsplit :execute s:find(<count>,'split',<q-args>,<bang>1)
bgneal@6 240 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vvsplit :execute s:find(<count>,'vsplit',<q-args>,<bang>1)
bgneal@6 241 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vtabedit :execute s:find(<count>,'tabedit',<q-args>,<bang>1)
bgneal@6 242 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vpedit :execute s:find(<count>,'pedit',<q-args>,<bang>1)
bgneal@6 243 command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vread :execute s:find(<count>,'read',<q-args>,<bang>1)
bgneal@6 244
bgneal@6 245 " vim:set ft=vim ts=8 sw=2 sts=2: