1
1
" Vim auto-load script
2
2
" Author: Peter Odding <peter@peterodding.com>
3
- " Last Change: April 18 , 2013
3
+ " Last Change: April 22 , 2013
4
4
" URL: http://peterodding.com/code/vim/misc/
5
5
6
6
let s: windows_compatible = has (' win32' ) || has (' win64' )
7
7
let s: mac_os_x_compatible = has (' macunix' )
8
8
9
- function ! xolox#misc#path#which (... )
9
+ function ! xolox#misc#path#which (... ) " {{{1
10
+ " Scan the executable search path for programs.
10
11
let extensions = s: windows_compatible ? split ($PATHEXT , ' ;' ) : [' ' ]
11
12
let matches = []
12
13
let checked = {}
@@ -29,9 +30,8 @@ function! xolox#misc#path#which(...)
29
30
return matches
30
31
endfunction
31
32
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.
35
35
if type (a: path ) == type (' ' )
36
36
if s: windows_compatible
37
37
return split (a: path , ' [\/]\+' )
@@ -44,9 +44,8 @@ function! xolox#misc#path#split(path)
44
44
return []
45
45
endfunction
46
46
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.
50
49
if type (a: parts ) == type ([])
51
50
if ! s: windows_compatible && a: parts [0 ] == ' /'
52
51
return join (a: parts , ' /' )[1 : -1 ]
@@ -57,9 +56,10 @@ function! xolox#misc#path#join(parts)
57
56
return ' '
58
57
endfunction
59
58
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.
63
63
if type (a: path ) == type (' ' )
64
64
let path = fnamemodify (a: path , ' :p' )
65
65
" resolve() doesn't work when there's a trailing path separator.
@@ -77,9 +77,8 @@ function! xolox#misc#path#absolute(path)
77
77
return ' '
78
78
endfunction
79
79
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.
83
82
let path = xolox#misc#path#split (a: path )
84
83
let base = xolox#misc#path#split (a: base )
85
84
while path != [] && base != [] && path [0 ] == base[0 ]
@@ -90,9 +89,9 @@ function! xolox#misc#path#relative(path, base)
90
89
return xolox#misc#path#join (distance + path )
91
90
endfunction
92
91
93
- " Join a directory and filename into a single pathname.
94
92
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.
96
95
" TODO Use isabs()!
97
96
if type (a: parent ) == type (' ' ) && type (a: child ) == type (' ' )
98
97
if s: windows_compatible
@@ -108,9 +107,8 @@ function! xolox#misc#path#merge(parent, child, ...)
108
107
return ' '
109
108
endfunction
110
109
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.
114
112
let common = xolox#misc#path#split (a: paths [0 ])
115
113
for path in a: paths
116
114
let index = 0
@@ -127,9 +125,8 @@ function! xolox#misc#path#commonprefix(paths)
127
125
return xolox#misc#path#join (common)
128
126
endfunction
129
127
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.
133
130
if s: windows_compatible
134
131
let mask = ' [*|\\/:"<>?%]'
135
132
elseif s: mac_os_x_compatible
@@ -140,12 +137,13 @@ function! xolox#misc#path#encode(path)
140
137
return substitute (a: path , mask, ' \=printf("%%%x", char2nr(submatch(0)))' , ' g' )
141
138
endfunction
142
139
143
- " Decode a pathname previously encoded with xolox#misc#path#encode().
144
140
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().
146
143
return substitute (a: encoded_path , ' %\(\x\x\?\)' , ' \=nr2char("0x" . submatch(1))' , ' g' )
147
144
endfunction
148
145
146
+ " xolox#misc#path#equals(a, b) {{{1
149
147
" Check whether two pathnames point to the same file.
150
148
151
149
if s: windows_compatible
158
156
endfunction
159
157
endif
160
158
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.
164
161
if a: path = ~ ' ^\w\+://'
165
162
return 0
166
163
elseif s: windows_compatible
@@ -170,9 +167,8 @@ function! xolox#misc#path#is_relative(path)
170
167
endif
171
168
endfunction
172
169
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.
176
172
if ! exists (' s:tempdir_counter' )
177
173
let s: tempdir_counter = 1
178
174
endif
0 commit comments