Simple image host.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pathogen.vim 11KB

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