|
1 | 1 | " Pathname manipulation functions. |
2 | 2 | " |
3 | 3 | " Author: Peter Odding <peter@peterodding.com> |
4 | | -" Last Change: July 6, 2014 |
| 4 | +" Last Change: July 7, 2014 |
5 | 5 | " URL: http://peterodding.com/code/vim/misc/ |
6 | 6 |
|
7 | 7 | let s:windows_compatible = xolox#misc#os#is_win() |
@@ -72,8 +72,12 @@ function! xolox#misc#path#split(path) " {{{1 |
72 | 72 | " UNC pathname. |
73 | 73 | return split(a:path, '\%>2c[\/]\+') |
74 | 74 | else |
75 | | - " If it's not a UNC path we can simply split on slashes & backslashes. |
76 | | - return split(a:path, '[\/]\+') |
| 75 | + " If it's not a UNC pathname we can simply split on slashes and |
| 76 | + " backslashes, although we should preserve a leading slash (which |
| 77 | + " denotes a pathname that is 'absolute to the current drive'). |
| 78 | + let absolute = (a:path =~ '^[\/]') |
| 79 | + let segments = split(a:path, '[\/]\+') |
| 80 | + return absolute ? insert(segments, a:path[0]) : segments |
77 | 81 | endif |
78 | 82 | else |
79 | 83 | " Everything else is treated as UNIX. |
@@ -135,6 +139,10 @@ function! xolox#misc#path#absolute(path) " {{{1 |
135 | 139 | " Also normalize the two leading "directory separators" (I'm not |
136 | 140 | " sure what else to call them :-) in Windows UNC pathnames. |
137 | 141 | let parts[0] = repeat(xolox#misc#path#directory_separator(), 2) . parts[0][2:] |
| 142 | + elseif s:windows_compatible && parts[0] =~ '^[\/]$' |
| 143 | + " If a pathname is relative to the current drive we should add |
| 144 | + " the drive letter in order to make the pathname absolute. |
| 145 | + let parts[0] = matchstr(getcwd(), '^\a:') |
138 | 146 | endif |
139 | 147 | return xolox#misc#path#join(parts) |
140 | 148 | endif |
|
0 commit comments