Features by Gerhard
[shutils.git] / dotfiles / vim / .vim / autoload / pathogen.vim
1 " pathogen.vim - path option manipulation
2 " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
3 " Version: 1.2
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 " Returns a hash indicating which filetype features are enabled.
69 function! pathogen#filetype() abort " {{{1
70 redir => output
71 silent filetype
72 redir END
73 let result = {}
74 let result.detection = match(output,'detection:ON') >= 0
75 let result.indent = match(output,'indent:ON') >= 0
76 let result.plugin = match(output,'plugin:ON') >= 0
77 return result
78 endfunction " }}}1
79
80 " \ on Windows unless shellslash is set, / everywhere else.
81 function! pathogen#separator() abort " {{{1
82 return !exists("+shellslash") || &shellslash ? '/' : '\'
83 endfunction " }}}1
84
85 " Convenience wrapper around glob() which returns a list.
86 function! pathogen#glob(pattern) abort " {{{1
87 let files = split(glob(a:pattern),"\n")
88 return map(files,'substitute(v:val,"[".pathogen#separator()."/]$","","")')
89 endfunction "}}}1
90
91 " Like pathogen#glob(), only limit the results to directories.
92 function! pathogen#glob_directories(pattern) abort " {{{1
93 return filter(pathogen#glob(a:pattern),'isdirectory(v:val)')
94 endfunction "}}}1
95
96 " Prepend all subdirectories of path to the rtp, and append all after
97 " directories in those subdirectories.
98 function! pathogen#runtime_prepend_subdirectories(path) " {{{1
99 let sep = pathogen#separator()
100 let before = pathogen#glob_directories(a:path.sep."*[^~]")
101 let after = pathogen#glob_directories(a:path.sep."*[^~]".sep."after")
102 let rtp = pathogen#split(&rtp)
103 let path = expand(a:path)
104 call filter(rtp,'v:val[0:strlen(path)-1] !=# path')
105 let &rtp = pathogen#join(pathogen#uniq(before + rtp + after))
106 return &rtp
107 endfunction " }}}1
108
109 " For each directory in rtp, check for a subdirectory named dir. If it
110 " exists, add all subdirectories of that subdirectory to the rtp, immediately
111 " after the original directory. If no argument is given, 'bundle' is used.
112 " Repeated calls with the same arguments are ignored.
113 function! pathogen#runtime_append_all_bundles(...) " {{{1
114 let sep = pathogen#separator()
115 let name = a:0 ? a:1 : 'bundle'
116 let list = []
117 for dir in pathogen#split(&rtp)
118 if dir =~# '\<after$'
119 let list += pathogen#glob_directories(substitute(dir,'after$',name.sep.'*[^~]'.sep.'after','')) + [dir]
120 else
121 let list += [dir] + pathogen#glob_directories(dir.sep.name.sep.'*[^~]')
122 endif
123 endfor
124 let &rtp = pathogen#join(pathogen#uniq(list))
125 return 1
126 endfunction
127
128 " }}}1
129
130 " Invoke :helptags on all non-$VIM doc directories in runtimepath.
131 function! pathogen#helptags() " {{{1
132 for dir in pathogen#split(&rtp)
133 if dir[0 : strlen($VIM)-1] !=# $VIM && isdirectory(dir.'/doc') && (!filereadable(dir.'/doc/tags') || filewritable(dir.'/doc/tags'))
134 helptags `=dir.'/doc'`
135 endif
136 endfor
137 endfunction " }}}1
138
139 " vim:set ft=vim ts=8 sw=2 sts=2: