11" Vim auto-load script
22" Author: Peter Odding <peter@peterodding.com>
3- " Last Change: April 18 , 2013
3+ " Last Change: April 22 , 2013
44" URL: http://peterodding.com/code/vim/misc/
55
66let s: windows_compatible = has (' win32' ) || has (' win64' )
77let s: mac_os_x_compatible = has (' macunix' )
88
9- function ! xolox#misc#path#which (... )
9+ function ! xolox#misc#path#which (... ) " {{{1
10+ " Scan the executable search path for programs.
1011 let extensions = s: windows_compatible ? split ($PATHEXT , ' ;' ) : [' ' ]
1112 let matches = []
1213 let checked = {}
@@ -29,9 +30,8 @@ function! xolox#misc#path#which(...)
2930 return matches
3031endfunction
3132
32- " Split a pathname into a list of path components.
33-
34- function ! xolox#misc#path#split (path )
33+ function ! xolox#misc#path#split (path ) " {{{1
34+ " Split a pathname into a list of path components.
3535 if type (a: path ) == type (' ' )
3636 if s: windows_compatible
3737 return split (a: path , ' [\/]\+' )
@@ -44,9 +44,8 @@ function! xolox#misc#path#split(path)
4444 return []
4545endfunction
4646
47- " Join a list of path components into a pathname.
48-
49- function ! xolox#misc#path#join (parts)
47+ function ! xolox#misc#path#join (parts) " {{{1
48+ " Join a list of path components into a pathname.
5049 if type (a: parts ) == type ([])
5150 if ! s: windows_compatible && a: parts [0 ] == ' /'
5251 return join (a: parts , ' /' )[1 : -1 ]
@@ -57,9 +56,10 @@ function! xolox#misc#path#join(parts)
5756 return ' '
5857endfunction
5958
60- " Canonicalize and resolve a pathname.
61-
62- function ! xolox#misc#path#absolute (path )
59+ function ! xolox#misc#path#absolute (path ) " {{{1
60+ " Canonicalize and resolve a pathname, regardless of whether it exists. This
61+ " is intended to support string comparison to determine whether two pathnames
62+ " point to the same directory or file.
6363 if type (a: path ) == type (' ' )
6464 let path = fnamemodify (a: path , ' :p' )
6565 " resolve() doesn't work when there's a trailing path separator.
@@ -77,9 +77,8 @@ function! xolox#misc#path#absolute(path)
7777 return ' '
7878endfunction
7979
80- " Make an absolute pathname relative.
81-
82- function ! xolox#misc#path#relative (path , base)
80+ function ! xolox#misc#path#relative (path , base) " {{{1
81+ " Make an absolute pathname relative.
8382 let path = xolox#misc#path#split (a: path )
8483 let base = xolox#misc#path#split (a: base )
8584 while path != [] && base != [] && path [0 ] == base[0 ]
@@ -90,9 +89,9 @@ function! xolox#misc#path#relative(path, base)
9089 return xolox#misc#path#join (distance + path )
9190endfunction
9291
93- " Join a directory and filename into a single pathname.
9492
95- function ! xolox#misc#path#merge (parent, child, ... )
93+ function ! xolox#misc#path#merge (parent, child, ... ) " {{{1
94+ " Join a directory and filename into a single pathname.
9695 " TODO Use isabs()!
9796 if type (a: parent ) == type (' ' ) && type (a: child ) == type (' ' )
9897 if s: windows_compatible
@@ -108,9 +107,8 @@ function! xolox#misc#path#merge(parent, child, ...)
108107 return ' '
109108endfunction
110109
111- " Find the common prefix of path components in a list of pathnames.
112-
113- function ! xolox#misc#path#commonprefix (paths)
110+ function ! xolox#misc#path#commonprefix (paths) " {{{1
111+ " Find the common prefix of path components in a list of pathnames.
114112 let common = xolox#misc#path#split (a: paths [0 ])
115113 for path in a: paths
116114 let index = 0
@@ -127,9 +125,8 @@ function! xolox#misc#path#commonprefix(paths)
127125 return xolox#misc#path#join (common)
128126endfunction
129127
130- " Encode a pathname so it can be used as a filename.
131-
132- function ! xolox#misc#path#encode (path )
128+ function ! xolox#misc#path#encode (path ) " {{{1
129+ " Encode a pathname so it can be used as a filename.
133130 if s: windows_compatible
134131 let mask = ' [*|\\/:"<>?%]'
135132 elseif s: mac_os_x_compatible
@@ -140,12 +137,13 @@ function! xolox#misc#path#encode(path)
140137 return substitute (a: path , mask, ' \=printf("%%%x", char2nr(submatch(0)))' , ' g' )
141138endfunction
142139
143- " Decode a pathname previously encoded with xolox#misc#path#encode().
144140
145- function ! xolox#misc#path#decode (encoded_path)
141+ function ! xolox#misc#path#decode (encoded_path) " {{{1
142+ " Decode a pathname previously encoded with xolox#misc#path#encode().
146143 return substitute (a: encoded_path , ' %\(\x\x\?\)' , ' \=nr2char("0x" . submatch(1))' , ' g' )
147144endfunction
148145
146+ " xolox#misc#path#equals(a, b) {{{1
149147" Check whether two pathnames point to the same file.
150148
151149if s: windows_compatible
158156 endfunction
159157endif
160158
161- " Check whether a path is relative.
162-
163- function ! xolox#misc#path#is_relative (path )
159+ function ! xolox#misc#path#is_relative (path ) " {{{1
160+ " Check whether a path is relative.
164161 if a: path = ~ ' ^\w\+://'
165162 return 0
166163 elseif s: windows_compatible
@@ -170,9 +167,8 @@ function! xolox#misc#path#is_relative(path)
170167 endif
171168endfunction
172169
173- " Create a temporary directory and return the path.
174-
175- function ! xolox#misc#path#tempdir ()
170+ function ! xolox#misc#path#tempdir () " {{{1
171+ " Create a temporary directory and return the path.
176172 if ! exists (' s:tempdir_counter' )
177173 let s: tempdir_counter = 1
178174 endif
0 commit comments