]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/vim-pathogen/autoload/pathogen.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit '294584081929424aec883f90c7d6515b3743358d' as '.vim/bundle/vim-lsp-ale'
[etc/vim.git] / .vim / bundle / vim-pathogen / autoload / pathogen.vim
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
13 if exists("g:loaded_pathogen") || &cp
14   finish
15 endif
16 let 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.
24 function! 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 ''
49 endfunction
50
51 " Split a path into a list.
52 function! 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")')
57 endfunction
58
59 " Convert a list to a path.
60 function! 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,'^,','','')
84 endfunction
85
86 " Convert a list to a path with escaped spaces for 'path', 'tag', etc.
87 function! pathogen#legacyjoin(...) abort
88   return call('pathogen#join',[1] + a:000)
89 endfunction
90
91 " Turn filetype detection off and back on again if it was already enabled.
92 function! pathogen#cycle_filetype() abort
93   if exists('g:did_load_filetypes')
94     filetype off
95     filetype on
96   endif
97 endfunction
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.
102 function! 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
112 endfunction
113
114 " Prepend the given directory to the runtime path and append its corresponding
115 " after directory.  Curly braces are expanded with pathogen#expand().
116 function! 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
125 endfunction
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().
129 function! 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
146 endfunction
147
148 let s:done_bundles = {}
149
150 " Invoke :helptags on all non-$VIM doc directories in runtimepath.
151 function! 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
160 endfunction
161
162 command! -bar Helptags :call pathogen#helptags()
163
164 " Execute the given command.  This is basically a backdoor for --remote-expr.
165 function! pathogen#execute(...) abort
166   for command in a:000
167     execute command
168   endfor
169   return ''
170 endfunction
171
172 " Section: Unofficial
173
174 function! pathogen#is_absolute(path) abort
175   return a:path =~# (has('win32') ? '^\%([\\/]\|\w:\)[\\/]\|^[~$]' : '^[/~$]')
176 endfunction
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.
182 function! 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)')
202 endfunction
203
204 " \ on Windows unless shellslash is set, / everywhere else.
205 function! pathogen#slash() abort
206   return !exists("+shellslash") || &shellslash ? '/' : '\'
207 endfunction
208
209 function! pathogen#separator() abort
210   return pathogen#slash()
211 endfunction
212
213 " Convenience wrapper around glob() which returns a list.
214 function! pathogen#glob(pattern) abort
215   let files = split(glob(a:pattern),"\n")
216   return map(files,'substitute(v:val,"[".pathogen#slash()."/]$","","")')
217 endfunction
218
219 " Like pathogen#glob(), only limit the results to directories.
220 function! pathogen#glob_directories(pattern) abort
221   return filter(pathogen#glob(a:pattern),'isdirectory(v:val)')
222 endfunction
223
224 " Remove duplicates from a list.
225 function! 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
240 endfunction
241
242 " Backport of fnameescape().
243 function! 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
251 endfunction
252
253 " Like findfile(), but hardcoded to use the runtimepath.
254 function! 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
262 endfunction
263
264 " vim:set et sw=2: