bgneal@6: " pathogen.vim - path option manipulation
bgneal@6: " Maintainer: Tim Pope
bgneal@6: " Version: 2.0
bgneal@6:
bgneal@6: " Install in ~/.vim/autoload (or ~\vimfiles\autoload).
bgneal@6: "
bgneal@6: " For management of individually installed plugins in ~/.vim/bundle (or
bgneal@6: " ~\vimfiles\bundle), adding `call pathogen#infect()` to your .vimrc
bgneal@6: " prior to `filetype plugin indent on` is the only other setup necessary.
bgneal@6: "
bgneal@6: " The API is documented inline below. For maximum ease of reading,
bgneal@6: " :set foldmethod=marker
bgneal@6:
bgneal@6: if exists("g:loaded_pathogen") || &cp
bgneal@6: finish
bgneal@6: endif
bgneal@6: let g:loaded_pathogen = 1
bgneal@6:
bgneal@6: " Point of entry for basic default usage. Give a directory name to invoke
bgneal@6: " pathogen#runtime_append_all_bundles() (defaults to "bundle"), or a full path
bgneal@6: " to invoke pathogen#runtime_prepend_subdirectories(). Afterwards,
bgneal@6: " pathogen#cycle_filetype() is invoked.
bgneal@6: function! pathogen#infect(...) abort " {{{1
bgneal@6: let source_path = a:0 ? a:1 : 'bundle'
bgneal@6: if source_path =~# '[\\/]'
bgneal@6: call pathogen#runtime_prepend_subdirectories(source_path)
bgneal@6: else
bgneal@6: call pathogen#runtime_append_all_bundles(source_path)
bgneal@6: endif
bgneal@6: call pathogen#cycle_filetype()
bgneal@6: endfunction " }}}1
bgneal@6:
bgneal@6: " Split a path into a list.
bgneal@6: function! pathogen#split(path) abort " {{{1
bgneal@6: if type(a:path) == type([]) | return a:path | endif
bgneal@6: let split = split(a:path,'\\\@"),'!isdirectory(v:val)')) && (!filereadable(dir.sep.'doc'.sep.'tags') || filewritable(dir.sep.'doc'.sep.'tags'))
bgneal@6: helptags `=dir.'/doc'`
bgneal@6: endif
bgneal@6: endfor
bgneal@6: endfunction " }}}1
bgneal@6:
bgneal@6: command! -bar Helptags :call pathogen#helptags()
bgneal@6:
bgneal@6: " Like findfile(), but hardcoded to use the runtimepath.
bgneal@6: function! pathogen#runtime_findfile(file,count) "{{{1
bgneal@6: let rtp = pathogen#join(1,pathogen#split(&rtp))
bgneal@6: return fnamemodify(findfile(a:file,rtp,a:count),':p')
bgneal@6: endfunction " }}}1
bgneal@6:
bgneal@6: " Backport of fnameescape().
bgneal@6: function! pathogen#fnameescape(string) " {{{1
bgneal@6: if exists('*fnameescape')
bgneal@6: return fnameescape(a:string)
bgneal@6: elseif a:string ==# '-'
bgneal@6: return '\-'
bgneal@6: else
bgneal@6: return substitute(escape(a:string," \t\n*?[{`$\\%#'\"|!<"),'^[+>]','\\&','')
bgneal@6: endif
bgneal@6: endfunction " }}}1
bgneal@6:
bgneal@6: function! s:find(count,cmd,file,lcd) " {{{1
bgneal@6: let rtp = pathogen#join(1,pathogen#split(&runtimepath))
bgneal@6: let file = pathogen#runtime_findfile(a:file,a:count)
bgneal@6: if file ==# ''
bgneal@6: return "echoerr 'E345: Can''t find file \"".a:file."\" in runtimepath'"
bgneal@6: elseif a:lcd
bgneal@6: let path = file[0:-strlen(a:file)-2]
bgneal@6: execute 'lcd `=path`'
bgneal@6: return a:cmd.' '.pathogen#fnameescape(a:file)
bgneal@6: else
bgneal@6: return a:cmd.' '.pathogen#fnameescape(file)
bgneal@6: endif
bgneal@6: endfunction " }}}1
bgneal@6:
bgneal@6: function! s:Findcomplete(A,L,P) " {{{1
bgneal@6: let sep = pathogen#separator()
bgneal@6: let cheats = {
bgneal@6: \'a': 'autoload',
bgneal@6: \'d': 'doc',
bgneal@6: \'f': 'ftplugin',
bgneal@6: \'i': 'indent',
bgneal@6: \'p': 'plugin',
bgneal@6: \'s': 'syntax'}
bgneal@6: if a:A =~# '^\w[\\/]' && has_key(cheats,a:A[0])
bgneal@6: let request = cheats[a:A[0]].a:A[1:-1]
bgneal@6: else
bgneal@6: let request = a:A
bgneal@6: endif
bgneal@6: let pattern = substitute(request,'\'.sep,'*'.sep,'g').'*'
bgneal@6: let found = {}
bgneal@6: for path in pathogen#split(&runtimepath)
bgneal@6: let path = expand(path, ':p')
bgneal@6: let matches = split(glob(path.sep.pattern),"\n")
bgneal@6: call map(matches,'isdirectory(v:val) ? v:val.sep : v:val')
bgneal@6: call map(matches,'expand(v:val, ":p")[strlen(path)+1:-1]')
bgneal@6: for match in matches
bgneal@6: let found[match] = 1
bgneal@6: endfor
bgneal@6: endfor
bgneal@6: return sort(keys(found))
bgneal@6: endfunction " }}}1
bgneal@6:
bgneal@6: command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Ve :execute s:find(,'edit',,0)
bgneal@6: command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vedit :execute s:find(,'edit',,0)
bgneal@6: command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vopen :execute s:find(,'edit',,1)
bgneal@6: command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vsplit :execute s:find(,'split',,1)
bgneal@6: command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vvsplit :execute s:find(,'vsplit',,1)
bgneal@6: command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vtabedit :execute s:find(,'tabedit',,1)
bgneal@6: command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vpedit :execute s:find(,'pedit',,1)
bgneal@6: command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vread :execute s:find(,'read',,1)
bgneal@6:
bgneal@6: " vim:set ft=vim ts=8 sw=2 sts=2: