]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - vim/autoload/pathogen.vim
Switch plugins with more than one file to pathogen.
[config/dotfiles.git] / vim / autoload / pathogen.vim
1 " pathogen.vim - path option manipulation
2 " Maintainer:   Tim Pope <vimNOSPAM@tpope.org>
3 " Version:      1.3
4
5 " Install in ~/.vim/autoload (or ~\vimfiles\autoload).
6 "
7 " API is documented below.
8
9 if exists("g:loaded_pathogen") || &cp
10   finish
11 endif
12 let g:loaded_pathogen = 1
13
14 " Split a path into a list.
15 function! pathogen#split(path) abort " {{{1
16   if type(a:path) == type([]) | return a:path | endif
17   let split = split(a:path,'\\\@<!\%(\\\\\)*\zs,')
18   return map(split,'substitute(v:val,''\\\([\\,]\)'',''\1'',"g")')
19 endfunction " }}}1
20
21 " Convert a list to a path.
22 function! pathogen#join(...) abort " {{{1
23   if type(a:1) == type(1) && a:1
24     let i = 1
25     let space = ' '
26   else
27     let i = 0
28     let space = ''
29   endif
30   let path = ""
31   while i < a:0
32     if type(a:000[i]) == type([])
33       let list = a:000[i]
34       let j = 0
35       while j < len(list)
36         let escaped = substitute(list[j],'[,'.space.']\|\\[\,'.space.']\@=','\\&','g')
37         let path .= ',' . escaped
38         let j += 1
39       endwhile
40     else
41       let path .= "," . a:000[i]
42     endif
43     let i += 1
44   endwhile
45   return substitute(path,'^,','','')
46 endfunction " }}}1
47
48 " Convert a list to a path with escaped spaces for 'path', 'tag', etc.
49 function! pathogen#legacyjoin(...) abort " {{{1
50   return call('pathogen#join',[1] + a:000)
51 endfunction " }}}1
52
53 " Remove duplicates from a list.
54 function! pathogen#uniq(list) abort " {{{1
55   let i = 0
56   let seen = {}
57   while i < len(a:list)
58     if has_key(seen,a:list[i])
59       call remove(a:list,i)
60     else
61       let seen[a:list[i]] = 1
62       let i += 1
63     endif
64   endwhile
65   return a:list
66 endfunction " }}}1
67
68 " \ on Windows unless shellslash is set, / everywhere else.
69 function! pathogen#separator() abort " {{{1
70   return !exists("+shellslash") || &shellslash ? '/' : '\'
71 endfunction " }}}1
72
73 " Convenience wrapper around glob() which returns a list.
74 function! pathogen#glob(pattern) abort " {{{1
75   let files = split(glob(a:pattern),"\n")
76   return map(files,'substitute(v:val,"[".pathogen#separator()."/]$","","")')
77 endfunction "}}}1
78
79 " Like pathogen#glob(), only limit the results to directories.
80 function! pathogen#glob_directories(pattern) abort " {{{1
81   return filter(pathogen#glob(a:pattern),'isdirectory(v:val)')
82 endfunction "}}}1
83
84 " Checks if a bundle is 'disabled'. A bundle is considered 'disabled' if
85 " its 'basename()' is included in g:pathogen_disabled[]'.
86 function! pathogen#is_disabled(path) " {{{1
87   if !exists("g:pathogen_disabled")
88     return 0
89   endif
90   let sep = pathogen#separator()
91   return index(g:pathogen_disabled, strpart(a:path, strridx(a:path, sep)+1)) != -1
92 endfunction "}}}1
93
94 " Prepend all subdirectories of path to the rtp, and append all 'after'
95 " directories in those subdirectories.
96 function! pathogen#runtime_prepend_subdirectories(path) " {{{1
97   let sep    = pathogen#separator()
98   let before = filter(pathogen#glob_directories(a:path.sep."*[^~]"), '!pathogen#is_disabled(v:val)')
99   let after  = filter(pathogen#glob_directories(a:path.sep."*[^~]".sep."after"), '!pathogen#is_disabled(v:val[0:-7])')
100   let rtp = pathogen#split(&rtp)
101   let path = expand(a:path)
102   call filter(rtp,'v:val[0:strlen(path)-1] !=# path')
103   let &rtp = pathogen#join(pathogen#uniq(before + rtp + after))
104   return &rtp
105 endfunction " }}}1
106
107 " For each directory in rtp, check for a subdirectory named dir.  If it
108 " exists, add all subdirectories of that subdirectory to the rtp, immediately
109 " after the original directory.  If no argument is given, 'bundle' is used.
110 " Repeated calls with the same arguments are ignored.
111 function! pathogen#runtime_append_all_bundles(...) " {{{1
112   let sep = pathogen#separator()
113   let name = a:0 ? a:1 : 'bundle'
114   if "\n".s:done_bundles =~# "\\M\n".name."\n"
115     return ""
116   endif
117   let s:done_bundles .= name . "\n"
118   let list = []
119   for dir in pathogen#split(&rtp)
120     if dir =~# '\<after$'
121       let list +=  filter(pathogen#glob_directories(substitute(dir,'after$',name,'').sep.'*[^~]'.sep.'after'), '!pathogen#is_disabled(v:val[0:-7])') + [dir]
122     else
123       let list +=  [dir] + filter(pathogen#glob_directories(dir.sep.name.sep.'*[^~]'), '!pathogen#is_disabled(v:val)')
124     endif
125   endfor
126   let &rtp = pathogen#join(pathogen#uniq(list))
127   return 1
128 endfunction
129
130 let s:done_bundles = ''
131 " }}}1
132
133 " Invoke :helptags on all non-$VIM doc directories in runtimepath.
134 function! pathogen#helptags() " {{{1
135   for dir in pathogen#split(&rtp)
136     if dir[0 : strlen($VIM)-1] !=# $VIM && isdirectory(dir.'/doc') && !empty(glob(dir.'/doc/*')) && (!filereadable(dir.'/doc/tags') || filewritable(dir.'/doc/tags'))
137       helptags `=dir.'/doc'`
138     endif
139   endfor
140 endfunction " }}}1
141
142 " vim:set ft=vim ts=8 sw=2 sts=2: