My dotfiles. Period.

pathogen.vim 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. " pathogen.vim - path option manipulation
  2. " Maintainer: Tim Pope <http://tpo.pe/>
  3. " Version: 2.2
  4. " Install in ~/.vim/autoload (or ~\vimfiles\autoload).
  5. "
  6. " For management of individually installed plugins in ~/.vim/bundle (or
  7. " ~\vimfiles\bundle), adding `call pathogen#infect()` to the top of your
  8. " .vimrc is the only other setup necessary.
  9. "
  10. " The API is documented inline below. For maximum ease of reading,
  11. " :set foldmethod=marker
  12. if exists("g:loaded_pathogen") || &cp
  13. finish
  14. endif
  15. let g:loaded_pathogen = 1
  16. function! s:warn(msg)
  17. if &verbose
  18. echohl WarningMsg
  19. echomsg a:msg
  20. echohl NONE
  21. endif
  22. endfunction
  23. " Point of entry for basic default usage. Give a relative path to invoke
  24. " pathogen#incubate() (defaults to "bundle/{}"), or an absolute path to invoke
  25. " pathogen#surround(). For backwards compatibility purposes, a full path that
  26. " does not end in {} or * is given to pathogen#runtime_prepend_subdirectories()
  27. " instead.
  28. function! pathogen#infect(...) abort " {{{1
  29. for path in a:0 ? reverse(copy(a:000)) : ['bundle/{}']
  30. if path =~# '^[^\\/]\+$'
  31. call s:warn('Change pathogen#infect('.string(path).') to pathogen#infect('.string(path.'/{}').')')
  32. call pathogen#incubate(path . '/{}')
  33. elseif path =~# '^[^\\/]\+[\\/]\%({}\|\*\)$'
  34. call pathogen#incubate(path)
  35. elseif path =~# '[\\/]\%({}\|\*\)$'
  36. call pathogen#surround(path)
  37. else
  38. call s:warn('Change pathogen#infect('.string(path).') to pathogen#infect('.string(path.'/{}').')')
  39. call pathogen#surround(path . '/{}')
  40. endif
  41. endfor
  42. call pathogen#cycle_filetype()
  43. return ''
  44. endfunction " }}}1
  45. " Split a path into a list.
  46. function! pathogen#split(path) abort " {{{1
  47. if type(a:path) == type([]) | return a:path | endif
  48. let split = split(a:path,'\\\@<!\%(\\\\\)*\zs,')
  49. return map(split,'substitute(v:val,''\\\([\\,]\)'',''\1'',"g")')
  50. endfunction " }}}1
  51. " Convert a list to a path.
  52. function! pathogen#join(...) abort " {{{1
  53. if type(a:1) == type(1) && a:1
  54. let i = 1
  55. let space = ' '
  56. else
  57. let i = 0
  58. let space = ''
  59. endif
  60. let path = ""
  61. while i < a:0
  62. if type(a:000[i]) == type([])
  63. let list = a:000[i]
  64. let j = 0
  65. while j < len(list)
  66. let escaped = substitute(list[j],'[,'.space.']\|\\[\,'.space.']\@=','\\&','g')
  67. let path .= ',' . escaped
  68. let j += 1
  69. endwhile
  70. else
  71. let path .= "," . a:000[i]
  72. endif
  73. let i += 1
  74. endwhile
  75. return substitute(path,'^,','','')
  76. endfunction " }}}1
  77. " Convert a list to a path with escaped spaces for 'path', 'tag', etc.
  78. function! pathogen#legacyjoin(...) abort " {{{1
  79. return call('pathogen#join',[1] + a:000)
  80. endfunction " }}}1
  81. " Remove duplicates from a list.
  82. function! pathogen#uniq(list) abort " {{{1
  83. let i = 0
  84. let seen = {}
  85. while i < len(a:list)
  86. if (a:list[i] ==# '' && exists('empty')) || has_key(seen,a:list[i])
  87. call remove(a:list,i)
  88. elseif a:list[i] ==# ''
  89. let i += 1
  90. let empty = 1
  91. else
  92. let seen[a:list[i]] = 1
  93. let i += 1
  94. endif
  95. endwhile
  96. return a:list
  97. endfunction " }}}1
  98. " \ on Windows unless shellslash is set, / everywhere else.
  99. function! pathogen#separator() abort " {{{1
  100. return !exists("+shellslash") || &shellslash ? '/' : '\'
  101. endfunction " }}}1
  102. " Convenience wrapper around glob() which returns a list.
  103. function! pathogen#glob(pattern) abort " {{{1
  104. let files = split(glob(a:pattern),"\n")
  105. return map(files,'substitute(v:val,"[".pathogen#separator()."/]$","","")')
  106. endfunction "}}}1
  107. " Like pathogen#glob(), only limit the results to directories.
  108. function! pathogen#glob_directories(pattern) abort " {{{1
  109. return filter(pathogen#glob(a:pattern),'isdirectory(v:val)')
  110. endfunction "}}}1
  111. " Turn filetype detection off and back on again if it was already enabled.
  112. function! pathogen#cycle_filetype() " {{{1
  113. if exists('g:did_load_filetypes')
  114. filetype off
  115. filetype on
  116. endif
  117. endfunction " }}}1
  118. " Check if a bundle is disabled. A bundle is considered disabled if it ends
  119. " in a tilde or its basename or full name is included in the list
  120. " g:pathogen_disabled.
  121. function! pathogen#is_disabled(path) " {{{1
  122. if a:path =~# '\~$'
  123. return 1
  124. elseif !exists("g:pathogen_disabled")
  125. return 0
  126. endif
  127. let sep = pathogen#separator()
  128. let blacklist = g:pathogen_disabled
  129. return index(blacklist, strpart(a:path, strridx(a:path, sep)+1)) != -1 && index(blacklist, a:path) != 1
  130. endfunction "}}}1
  131. " Prepend the given directory to the runtime path and append its corresponding
  132. " after directory. If the directory is already included, move it to the
  133. " outermost position. Wildcards are added as is. Ending a path in /{} causes
  134. " all subdirectories to be added (except those in g:pathogen_disabled).
  135. function! pathogen#surround(path) abort " {{{1
  136. let sep = pathogen#separator()
  137. let rtp = pathogen#split(&rtp)
  138. if a:path =~# '[\\/]{}$'
  139. let path = fnamemodify(a:path[0:-4], ':p:s?[\\/]\=$??')
  140. let before = filter(pathogen#glob_directories(path.sep.'*'), '!pathogen#is_disabled(v:val)')
  141. let after = filter(reverse(pathogen#glob_directories(path.sep."*".sep."after")), '!pathogen#is_disabled(v:val[0:-7])')
  142. call filter(rtp,'v:val[0:strlen(path)-1] !=# path')
  143. else
  144. let path = fnamemodify(a:path, ':p:s?[\\/]\=$??')
  145. let before = [path]
  146. let after = [path . sep . 'after']
  147. call filter(rtp, 'index(before + after, v:val) == -1')
  148. endif
  149. let &rtp = pathogen#join(before, rtp, after)
  150. return &rtp
  151. endfunction " }}}1
  152. " Prepend all subdirectories of path to the rtp, and append all 'after'
  153. " directories in those subdirectories. Deprecated.
  154. function! pathogen#runtime_prepend_subdirectories(path) " {{{1
  155. call s:warn('Change pathogen#runtime_prepend_subdirectories('.string(a:path).') to pathogen#surround('.string(a:path.'/{}').')')
  156. return pathogen#surround(a:path . pathogen#separator() . '{}')
  157. endfunction " }}}1
  158. " For each directory in the runtime path, add a second entry with the given
  159. " argument appended. If the argument ends in '/{}', add a separate entry for
  160. " each subdirectory. The default argument is 'bundle/{}', which means that
  161. " .vim/bundle/*, $VIM/vimfiles/bundle/*, $VIMRUNTIME/bundle/*,
  162. " $VIM/vim/files/bundle/*/after, and .vim/bundle/*/after will be added (on
  163. " UNIX).
  164. function! pathogen#incubate(...) abort " {{{1
  165. let sep = pathogen#separator()
  166. let name = a:0 ? a:1 : 'bundle/{}'
  167. if "\n".s:done_bundles =~# "\\M\n".name."\n"
  168. return ""
  169. endif
  170. let s:done_bundles .= name . "\n"
  171. let list = []
  172. for dir in pathogen#split(&rtp)
  173. if dir =~# '\<after$'
  174. if name =~# '{}$'
  175. let list += filter(pathogen#glob_directories(substitute(dir,'after$',name[0:-3],'').'*[^~]'.sep.'after'), '!pathogen#is_disabled(v:val[0:-7])') + [dir]
  176. else
  177. let list += [dir, substitute(dir, 'after$', '', '') . name . sep . 'after']
  178. endif
  179. else
  180. if name =~# '{}$'
  181. let list += [dir] + filter(pathogen#glob_directories(dir.sep.name[0:-3].'*[^~]'), '!pathogen#is_disabled(v:val)')
  182. else
  183. let list += [dir . sep . name, dir]
  184. endif
  185. endif
  186. endfor
  187. let &rtp = pathogen#join(pathogen#uniq(list))
  188. return 1
  189. endfunction " }}}1
  190. " Deprecated alias for pathogen#incubate().
  191. function! pathogen#runtime_append_all_bundles(...) abort " {{{1
  192. if a:0
  193. call s:warn('Change pathogen#runtime_append_all_bundles('.string(a:1).') to pathogen#incubate('.string(a:1.'/{}').')')
  194. else
  195. call s:warn('Change pathogen#runtime_append_all_bundles() to pathogen#incubate()')
  196. endif
  197. return call('pathogen#incubate', map(copy(a:000),'v:val . "/{}"'))
  198. endfunction
  199. let s:done_bundles = ''
  200. " }}}1
  201. " Invoke :helptags on all non-$VIM doc directories in runtimepath.
  202. function! pathogen#helptags() abort " {{{1
  203. let sep = pathogen#separator()
  204. for glob in pathogen#split(&rtp)
  205. for dir in split(glob(glob), "\n")
  206. 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'))
  207. helptags `=dir.'/doc'`
  208. endif
  209. endfor
  210. endfor
  211. endfunction " }}}1
  212. command! -bar Helptags :call pathogen#helptags()
  213. " Execute the given command. This is basically a backdoor for --remote-expr.
  214. function! pathogen#execute(...) abort " {{{1
  215. for command in a:000
  216. execute command
  217. endfor
  218. return ''
  219. endfunction " }}}1
  220. " Like findfile(), but hardcoded to use the runtimepath.
  221. function! pathogen#runtime_findfile(file,count) abort "{{{1
  222. let rtp = pathogen#join(1,pathogen#split(&rtp))
  223. let file = findfile(a:file,rtp,a:count)
  224. if file ==# ''
  225. return ''
  226. else
  227. return fnamemodify(file,':p')
  228. endif
  229. endfunction " }}}1
  230. " Backport of fnameescape().
  231. function! pathogen#fnameescape(string) abort " {{{1
  232. if exists('*fnameescape')
  233. return fnameescape(a:string)
  234. elseif a:string ==# '-'
  235. return '\-'
  236. else
  237. return substitute(escape(a:string," \t\n*?[{`$\\%#'\"|!<"),'^[+>]','\\&','')
  238. endif
  239. endfunction " }}}1
  240. if exists(':Vedit')
  241. finish
  242. endif
  243. let s:vopen_warning = 0
  244. function! s:find(count,cmd,file,lcd) " {{{1
  245. let rtp = pathogen#join(1,pathogen#split(&runtimepath))
  246. let file = pathogen#runtime_findfile(a:file,a:count)
  247. if file ==# ''
  248. return "echoerr 'E345: Can''t find file \"".a:file."\" in runtimepath'"
  249. endif
  250. if !s:vopen_warning
  251. let s:vopen_warning = 1
  252. let warning = '|echohl WarningMsg|echo "Install scriptease.vim to continue using :V'.a:cmd.'"|echohl NONE'
  253. else
  254. let warning = ''
  255. endif
  256. if a:lcd
  257. let path = file[0:-strlen(a:file)-2]
  258. execute 'lcd `=path`'
  259. return a:cmd.' '.pathogen#fnameescape(a:file) . warning
  260. else
  261. return a:cmd.' '.pathogen#fnameescape(file) . warning
  262. endif
  263. endfunction " }}}1
  264. function! s:Findcomplete(A,L,P) " {{{1
  265. let sep = pathogen#separator()
  266. let cheats = {
  267. \'a': 'autoload',
  268. \'d': 'doc',
  269. \'f': 'ftplugin',
  270. \'i': 'indent',
  271. \'p': 'plugin',
  272. \'s': 'syntax'}
  273. if a:A =~# '^\w[\\/]' && has_key(cheats,a:A[0])
  274. let request = cheats[a:A[0]].a:A[1:-1]
  275. else
  276. let request = a:A
  277. endif
  278. let pattern = substitute(request,'/\|\'.sep,'*'.sep,'g').'*'
  279. let found = {}
  280. for path in pathogen#split(&runtimepath)
  281. let path = expand(path, ':p')
  282. let matches = split(glob(path.sep.pattern),"\n")
  283. call map(matches,'isdirectory(v:val) ? v:val.sep : v:val')
  284. call map(matches,'expand(v:val, ":p")[strlen(path)+1:-1]')
  285. for match in matches
  286. let found[match] = 1
  287. endfor
  288. endfor
  289. return sort(keys(found))
  290. endfunction " }}}1
  291. command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Ve :execute s:find(<count>,'edit<bang>',<q-args>,0)
  292. command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vedit :execute s:find(<count>,'edit<bang>',<q-args>,0)
  293. command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vopen :execute s:find(<count>,'edit<bang>',<q-args>,1)
  294. command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vsplit :execute s:find(<count>,'split',<q-args>,<bang>1)
  295. command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vvsplit :execute s:find(<count>,'vsplit',<q-args>,<bang>1)
  296. command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vtabedit :execute s:find(<count>,'tabedit',<q-args>,<bang>1)
  297. command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vpedit :execute s:find(<count>,'pedit',<q-args>,<bang>1)
  298. command! -bar -bang -range=1 -nargs=1 -complete=customlist,s:Findcomplete Vread :execute s:find(<count>,'read',<q-args>,<bang>1)
  299. " vim:set et sw=2: