mauvehed's dotfiles for personal and work environments
1" pathogen.vim - path option manipulation
2" Maintainer: Tim Pope <http://tpo.pe/>
3" Version: 2.4
4
5" Install in ~/.vim/autoload (or ~\vimfiles\autoload).
6"
7" For management of individually installed plugins in ~/.vim/bundle (or
8" ~\vimfiles\bundle), adding `execute pathogen#infect()` to the top of your
9" .vimrc is the only other setup necessary.
10"
11" The API is documented inline below.
12
13if exists("g:loaded_pathogen") || &cp
14 finish
15endif
16let g:loaded_pathogen = 1
17
18" Point of entry for basic default usage. Give a relative path to invoke
19" pathogen#interpose() or an absolute path to invoke pathogen#surround().
20" Curly braces are expanded with pathogen#expand(): "bundle/{}" finds all
21" subdirectories inside "bundle" inside all directories in the runtime path.
22" If no arguments are given, defaults "bundle/{}", and also "pack/{}/start/{}"
23" on versions of Vim without native package support.
24function! pathogen#infect(...) abort
25 if a:0
26 let paths = filter(reverse(copy(a:000)), 'type(v:val) == type("")')
27 else
28 let paths = ['bundle/{}', 'pack/{}/start/{}']
29 endif
30 if has('packages')
31 call filter(paths, 'v:val !~# "^pack/[^/]*/start/[^/]*$"')
32 endif
33 let static = '^\%([$~\\/]\|\w:[\\/]\)[^{}*]*$'
34 for path in filter(copy(paths), 'v:val =~# static')
35 call pathogen#surround(path)
36 endfor
37 for path in filter(copy(paths), 'v:val !~# static')
38 if path =~# '^\%([$~\\/]\|\w:[\\/]\)'
39 call pathogen#surround(path)
40 else
41 call pathogen#interpose(path)
42 endif
43 endfor
44 call pathogen#cycle_filetype()
45 if pathogen#is_disabled($MYVIMRC)
46 return 'finish'
47 endif
48 return ''
49endfunction
50
51" Split a path into a list.
52function! pathogen#split(path) abort
53 if type(a:path) == type([]) | return a:path | endif
54 if empty(a:path) | return [] | endif
55 let split = split(a:path,'\\\@<!\%(\\\\\)*\zs,')
56 return map(split,'substitute(v:val,''\\\([\\,]\)'',''\1'',"g")')
57endfunction
58
59" Convert a list to a path.
60function! pathogen#join(...) abort
61 if type(a:1) == type(1) && a:1
62 let i = 1
63 let space = ' '
64 else
65 let i = 0
66 let space = ''
67 endif
68 let path = ""
69 while i < a:0
70 if type(a:000[i]) == type([])
71 let list = a:000[i]
72 let j = 0
73 while j < len(list)
74 let escaped = substitute(list[j],'[,'.space.']\|\\[\,'.space.']\@=','\\&','g')
75 let path .= ',' . escaped
76 let j += 1
77 endwhile
78 else
79 let path .= "," . a:000[i]
80 endif
81 let i += 1
82 endwhile
83 return substitute(path,'^,','','')
84endfunction
85
86" Convert a list to a path with escaped spaces for 'path', 'tag', etc.
87function! pathogen#legacyjoin(...) abort
88 return call('pathogen#join',[1] + a:000)
89endfunction
90
91" Turn filetype detection off and back on again if it was already enabled.
92function! pathogen#cycle_filetype() abort
93 if exists('g:did_load_filetypes')
94 filetype off
95 filetype on
96 endif
97endfunction
98
99" Check if a bundle is disabled. A bundle is considered disabled if its
100" basename or full name is included in the list g:pathogen_blacklist or the
101" comma delimited environment variable $VIMBLACKLIST.
102function! pathogen#is_disabled(path) abort
103 if a:path =~# '\~$'
104 return 1
105 endif
106 let sep = pathogen#slash()
107 let blacklist = get(g:, 'pathogen_blacklist', get(g:, 'pathogen_disabled', [])) + pathogen#split($VIMBLACKLIST)
108 if !empty(blacklist)
109 call map(blacklist, 'substitute(v:val, "[\\/]$", "", "")')
110 endif
111 return index(blacklist, fnamemodify(a:path, ':t')) != -1 || index(blacklist, a:path) != -1
112endfunction
113
114" Prepend the given directory to the runtime path and append its corresponding
115" after directory. Curly braces are expanded with pathogen#expand().
116function! pathogen#surround(path) abort
117 let sep = pathogen#slash()
118 let rtp = pathogen#split(&rtp)
119 let path = fnamemodify(a:path, ':s?[\\/]\=$??')
120 let before = filter(pathogen#expand(path), '!pathogen#is_disabled(v:val)')
121 let after = filter(reverse(pathogen#expand(path, sep.'after')), '!pathogen#is_disabled(v:val[0 : -7])')
122 call filter(rtp, 'index(before + after, v:val) == -1')
123 let &rtp = pathogen#join(before, rtp, after)
124 return &rtp
125endfunction
126
127" For each directory in the runtime path, add a second entry with the given
128" argument appended. Curly braces are expanded with pathogen#expand().
129function! pathogen#interpose(name) abort
130 let sep = pathogen#slash()
131 let name = a:name
132 if has_key(s:done_bundles, name)
133 return ""
134 endif
135 let s:done_bundles[name] = 1
136 let list = []
137 for dir in pathogen#split(&rtp)
138 if dir =~# '\<after$'
139 let list += reverse(filter(pathogen#expand(dir[0 : -6].name, sep.'after'), '!pathogen#is_disabled(v:val[0 : -7])')) + [dir]
140 else
141 let list += [dir] + filter(pathogen#expand(dir.sep.name), '!pathogen#is_disabled(v:val)')
142 endif
143 endfor
144 let &rtp = pathogen#join(pathogen#uniq(list))
145 return 1
146endfunction
147
148let s:done_bundles = {}
149
150" Invoke :helptags on all non-$VIM doc directories in runtimepath.
151function! pathogen#helptags() abort
152 let sep = pathogen#slash()
153 for glob in pathogen#split(&rtp)
154 for dir in map(split(glob(glob), "\n"), 'v:val.sep."/doc/".sep')
155 if (dir)[0 : strlen($VIMRUNTIME)] !=# $VIMRUNTIME.sep && filewritable(dir) == 2 && !empty(split(glob(dir.'*.txt'))) && (!filereadable(dir.'tags') || filewritable(dir.'tags'))
156 silent! execute 'helptags' pathogen#fnameescape(dir)
157 endif
158 endfor
159 endfor
160endfunction
161
162command! -bar Helptags :call pathogen#helptags()
163
164" Execute the given command. This is basically a backdoor for --remote-expr.
165function! pathogen#execute(...) abort
166 for command in a:000
167 execute command
168 endfor
169 return ''
170endfunction
171
172" Section: Unofficial
173
174function! pathogen#is_absolute(path) abort
175 return a:path =~# (has('win32') ? '^\%([\\/]\|\w:\)[\\/]\|^[~$]' : '^[/~$]')
176endfunction
177
178" Given a string, returns all possible permutations of comma delimited braced
179" alternatives of that string. pathogen#expand('/{a,b}/{c,d}') yields
180" ['/a/c', '/a/d', '/b/c', '/b/d']. Empty braces are treated as a wildcard
181" and globbed. Actual globs are preserved.
182function! pathogen#expand(pattern, ...) abort
183 let after = a:0 ? a:1 : ''
184 let pattern = substitute(a:pattern, '^[~$][^\/]*', '\=expand(submatch(0))', '')
185 if pattern =~# '{[^{}]\+}'
186 let [pre, pat, post] = split(substitute(pattern, '\(.\{-\}\){\([^{}]\+\)}\(.*\)', "\\1\001\\2\001\\3", ''), "\001", 1)
187 let found = map(split(pat, ',', 1), 'pre.v:val.post')
188 let results = []
189 for pattern in found
190 call extend(results, pathogen#expand(pattern))
191 endfor
192 elseif pattern =~# '{}'
193 let pat = matchstr(pattern, '^.*{}[^*]*\%($\|[\\/]\)')
194 let post = pattern[strlen(pat) : -1]
195 let results = map(split(glob(substitute(pat, '{}', '*', 'g')), "\n"), 'v:val.post')
196 else
197 let results = [pattern]
198 endif
199 let vf = pathogen#slash() . 'vimfiles'
200 call map(results, 'v:val =~# "\\*" ? v:val.after : isdirectory(v:val.vf.after) ? v:val.vf.after : isdirectory(v:val.after) ? v:val.after : ""')
201 return filter(results, '!empty(v:val)')
202endfunction
203
204" \ on Windows unless shellslash is set, / everywhere else.
205function! pathogen#slash() abort
206 return !exists("+shellslash") || &shellslash ? '/' : '\'
207endfunction
208
209function! pathogen#separator() abort
210 return pathogen#slash()
211endfunction
212
213" Convenience wrapper around glob() which returns a list.
214function! pathogen#glob(pattern) abort
215 let files = split(glob(a:pattern),"\n")
216 return map(files,'substitute(v:val,"[".pathogen#slash()."/]$","","")')
217endfunction
218
219" Like pathogen#glob(), only limit the results to directories.
220function! pathogen#glob_directories(pattern) abort
221 return filter(pathogen#glob(a:pattern),'isdirectory(v:val)')
222endfunction
223
224" Remove duplicates from a list.
225function! pathogen#uniq(list) abort
226 let i = 0
227 let seen = {}
228 while i < len(a:list)
229 if (a:list[i] ==# '' && exists('empty')) || has_key(seen,a:list[i])
230 call remove(a:list,i)
231 elseif a:list[i] ==# ''
232 let i += 1
233 let empty = 1
234 else
235 let seen[a:list[i]] = 1
236 let i += 1
237 endif
238 endwhile
239 return a:list
240endfunction
241
242" Backport of fnameescape().
243function! pathogen#fnameescape(string) abort
244 if exists('*fnameescape')
245 return fnameescape(a:string)
246 elseif a:string ==# '-'
247 return '\-'
248 else
249 return substitute(escape(a:string," \t\n*?[{`$\\%#'\"|!<"),'^[+>]','\\&','')
250 endif
251endfunction
252
253" Like findfile(), but hardcoded to use the runtimepath.
254function! pathogen#runtime_findfile(file,count) abort
255 let rtp = pathogen#join(1,pathogen#split(&rtp))
256 let file = findfile(a:file,rtp,a:count)
257 if file ==# ''
258 return ''
259 else
260 return fnamemodify(file,':p')
261 endif
262endfunction
263
264" vim:set et sw=2: