@@ -17,21 +17,21 @@ let g:loaded_pathogen = 1
1717
1818" Point of entry for basic default usage. Give a relative path to invoke
1919" pathogen#interpose() (defaults to "bundle/{}"), or an absolute path to invoke
20- " pathogen#surround(). For backwards compatibility purposes, a full path that
21- " does not end in {} or * is given to pathogen#runtime_prepend_subdirectories()
22- " instead .
20+ " pathogen#surround(). Curly braces are expanded with pathogen#expand():
21+ " "bundle/{}" finds all subdirectories inside "bundle" inside all directories
22+ " in the runtime path .
2323function ! pathogen#infect (... ) abort
2424 for path in a: 0 ? filter (reverse (copy (a: 000 )), ' type(v:val) == type("")' ) : [' bundle/{}' ]
25- if path = ~# ' ^[^\\/]\+$'
25+ if path = ~# ' ^\%({\=[$~\\/]\|{\=\w:[\\/]\).*[{}*]'
26+ call pathogen#surround (path )
27+ elseif path = ~# ' ^\%([$~\\/]\|\w:[\\/]\)'
2628 call s: warn (' Change pathogen#infect(' .string (path ).' ) to pathogen#infect(' .string (path .' /{}' ).' )' )
27- call pathogen#interpose (path . ' /{}' )
28- elseif path = ~# ' ^[^\\/]\+[\\/]\%({}\|\*\)$ '
29+ call pathogen#surround (path . ' /{}' )
30+ elseif path = ~# ' [{}*] '
2931 call pathogen#interpose (path )
30- elseif path = ~# ' [\\/]\%({}\|\*\)$'
31- call pathogen#surround (path )
3232 else
3333 call s: warn (' Change pathogen#infect(' .string (path ).' ) to pathogen#infect(' .string (path .' /{}' ).' )' )
34- call pathogen#surround (path . ' /{}' )
34+ call pathogen#interpose (path . ' /{}' )
3535 endif
3636 endfor
3737 call pathogen#cycle_filetype ()
@@ -100,30 +100,20 @@ function! pathogen#is_disabled(path) abort
100100endfunction " }}}1
101101
102102" Prepend the given directory to the runtime path and append its corresponding
103- " after directory. If the directory is already included, move it to the
104- " outermost position. Wildcards are added as is. Ending a path in /{} causes
105- " all subdirectories to be added (except those in g:pathogen_disabled).
103+ " after directory. Curly braces are expanded with pathogen#expand().
106104function ! pathogen#surround (path ) abort
107105 let sep = pathogen#slash ()
108106 let rtp = pathogen#split (&rtp )
109- if a: path = ~# ' [\\/]{}$'
110- let path = fnamemodify (a: path [0 :-4 ], ' :p:s?[\\/]\=$??' )
111- let before = filter (pathogen#glob_directories (path .sep.' *' ), ' !pathogen#is_disabled(v:val)' )
112- let after = filter (reverse (pathogen#glob_directories (path .sep." *" .sep." after" )), ' !pathogen#is_disabled(v:val[0:-7])' )
113- call filter (rtp ,' v:val[0:strlen(path)-1] !=# path' )
114- else
115- let path = fnamemodify (a: path , ' :p:s?[\\/]\=$??' )
116- let before = [path ]
117- let after = [path . sep . ' after' ]
118- call filter (rtp , ' index(before + after, v:val) == -1' )
119- endif
107+ let path = fnamemodify (a: path , ' :p:?[\\/]\=$??' )
108+ let before = filter (pathogen#expand (path ), ' !pathogen#is_disabled(v:val)' )
109+ let after = filter (reverse (pathogen#expand (path .sep.' after' )), ' !pathogen#is_disabled(v:val[0:-7])' )
110+ call filter (rtp , ' index(before + after, v:val) == -1' )
120111 let &rtp = pathogen#join (before, rtp , after)
121112 return &rtp
122113endfunction
123114
124115" For each directory in the runtime path, add a second entry with the given
125- " argument appended. If the argument ends in '/{}', add a separate entry for
126- " each subdirectory.
116+ " argument appended. Curly braces are expanded with pathogen#expand().
127117function ! pathogen#interpose (name) abort
128118 let sep = pathogen#slash ()
129119 let name = a: name
@@ -134,17 +124,9 @@ function! pathogen#interpose(name) abort
134124 let list = []
135125 for dir in pathogen#split (&rtp )
136126 if dir = ~# ' \<after$'
137- if name = ~# ' {}$'
138- let list += filter (pathogen#glob_directories (substitute (dir ,' after$' ,name[0 :-3 ],' ' ).' *' .sep.' after' ), ' !pathogen#is_disabled(v:val[0:-7])' ) + [dir ]
139- else
140- let list += [dir , substitute (dir , ' after$' , ' ' , ' ' ) . name . sep . ' after' ]
141- endif
127+ let list += reverse (filter (pathogen#expand (dir [0 :-6 ].name.sep.' after' ), ' !pathogen#is_disabled(v:val[0:-7])' )) + [dir ]
142128 else
143- if name = ~# ' {}$'
144- let list += [dir ] + filter (pathogen#glob_directories (dir .sep.name[0 :-3 ].' *' ), ' !pathogen#is_disabled(v:val)' )
145- else
146- let list += [dir . sep . name, dir ]
147- endif
129+ let list += [dir ] + filter (pathogen#expand (dir .sep.name), ' !pathogen#is_disabled(v:val)' )
148130 endif
149131 endfor
150132 let &rtp = pathogen#join (pathogen#uniq (list ))
@@ -177,6 +159,32 @@ endfunction
177159
178160" Section: Unofficial
179161
162+ function ! pathogen#is_absolute (path ) abort
163+ return a: path = ~# (has (' win32' ) ? ' ^\%([\\/]\|\w:\)[\\/]\|^[~$]' : ' ^[/~$]' )
164+ endfunction
165+
166+ " Given a string, returns all possible permutations of comma delimited braced
167+ " alternatives of that string. pathogen#expand('/{a,b}/{c,d}') yields
168+ " ['/a/c', '/a/d', '/b/c', '/b/d']. Empty braces are treated as a wildcard
169+ " and globbed. Actual globs are preserved.
170+ function ! pathogen#expand (pattern) abort
171+ if a: pattern = ~# ' {[^{}]\+}'
172+ let [pre , pat, post] = split (substitute (a: pattern , ' \(.\{-\}\){\([^{}]\+\)}\(.*\)' , " \\ 1\001 \\ 2\001 \\ 3" , ' ' ), " \001 " , 1 )
173+ let found = map (split (pat, ' ,' , 1 ), ' pre.v:val.post' )
174+ let results = []
175+ for pattern in found
176+ call extend (results, pathogen#expand (pattern))
177+ endfor
178+ return results
179+ elseif a: pattern = ~# ' {}'
180+ let pat = matchstr (a: pattern , ' ^.*{}[^*]*\%($\|[\\/]\)' )
181+ let post = a: pattern [strlen (pat) : -1 ]
182+ return map (split (glob (substitute (pat, ' {}' , ' *' , ' g' )), " \n " ), ' v:val.post' )
183+ else
184+ return [a: pattern ]
185+ endif
186+ endfunction
187+
180188" \ on Windows unless shellslash is set, / everywhere else.
181189function ! pathogen#slash () abort
182190 return ! exists (" +shellslash" ) || &shellslash ? ' /' : ' \'
0 commit comments