aboutsummaryrefslogtreecommitdiffstats
path: root/autoload/xolox/misc/path.vim
diff options
context:
space:
mode:
Diffstat (limited to 'autoload/xolox/misc/path.vim')
-rw-r--r--autoload/xolox/misc/path.vim56
1 files changed, 26 insertions, 30 deletions
diff --git a/autoload/xolox/misc/path.vim b/autoload/xolox/misc/path.vim
index 6f8fe44..67ef8d8 100644
--- a/autoload/xolox/misc/path.vim
+++ b/autoload/xolox/misc/path.vim
@@ -1,12 +1,13 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: April 18, 2013
+" Last Change: April 22, 2013
" URL: http://peterodding.com/code/vim/misc/
let s:windows_compatible = has('win32') || has('win64')
let s:mac_os_x_compatible = has('macunix')
-function! xolox#misc#path#which(...)
+function! xolox#misc#path#which(...) " {{{1
+ " Scan the executable search path for programs.
let extensions = s:windows_compatible ? split($PATHEXT, ';') : ['']
let matches = []
let checked = {}
@@ -29,9 +30,8 @@ function! xolox#misc#path#which(...)
return matches
endfunction
-" Split a pathname into a list of path components.
-
-function! xolox#misc#path#split(path)
+function! xolox#misc#path#split(path) " {{{1
+ " Split a pathname into a list of path components.
if type(a:path) == type('')
if s:windows_compatible
return split(a:path, '[\/]\+')
@@ -44,9 +44,8 @@ function! xolox#misc#path#split(path)
return []
endfunction
-" Join a list of path components into a pathname.
-
-function! xolox#misc#path#join(parts)
+function! xolox#misc#path#join(parts) " {{{1
+ " Join a list of path components into a pathname.
if type(a:parts) == type([])
if !s:windows_compatible && a:parts[0] == '/'
return join(a:parts, '/')[1 : -1]
@@ -57,9 +56,10 @@ function! xolox#misc#path#join(parts)
return ''
endfunction
-" Canonicalize and resolve a pathname.
-
-function! xolox#misc#path#absolute(path)
+function! xolox#misc#path#absolute(path) " {{{1
+ " Canonicalize and resolve a pathname, regardless of whether it exists. This
+ " is intended to support string comparison to determine whether two pathnames
+ " point to the same directory or file.
if type(a:path) == type('')
let path = fnamemodify(a:path, ':p')
" resolve() doesn't work when there's a trailing path separator.
@@ -77,9 +77,8 @@ function! xolox#misc#path#absolute(path)
return ''
endfunction
-" Make an absolute pathname relative.
-
-function! xolox#misc#path#relative(path, base)
+function! xolox#misc#path#relative(path, base) " {{{1
+ " Make an absolute pathname relative.
let path = xolox#misc#path#split(a:path)
let base = xolox#misc#path#split(a:base)
while path != [] && base != [] && path[0] == base[0]
@@ -90,9 +89,9 @@ function! xolox#misc#path#relative(path, base)
return xolox#misc#path#join(distance + path)
endfunction
-" Join a directory and filename into a single pathname.
-function! xolox#misc#path#merge(parent, child, ...)
+function! xolox#misc#path#merge(parent, child, ...) " {{{1
+ " Join a directory and filename into a single pathname.
" TODO Use isabs()!
if type(a:parent) == type('') && type(a:child) == type('')
if s:windows_compatible
@@ -108,9 +107,8 @@ function! xolox#misc#path#merge(parent, child, ...)
return ''
endfunction
-" Find the common prefix of path components in a list of pathnames.
-
-function! xolox#misc#path#commonprefix(paths)
+function! xolox#misc#path#commonprefix(paths) " {{{1
+ " Find the common prefix of path components in a list of pathnames.
let common = xolox#misc#path#split(a:paths[0])
for path in a:paths
let index = 0
@@ -127,9 +125,8 @@ function! xolox#misc#path#commonprefix(paths)
return xolox#misc#path#join(common)
endfunction
-" Encode a pathname so it can be used as a filename.
-
-function! xolox#misc#path#encode(path)
+function! xolox#misc#path#encode(path) " {{{1
+ " Encode a pathname so it can be used as a filename.
if s:windows_compatible
let mask = '[*|\\/:"<>?%]'
elseif s:mac_os_x_compatible
@@ -140,12 +137,13 @@ function! xolox#misc#path#encode(path)
return substitute(a:path, mask, '\=printf("%%%x", char2nr(submatch(0)))', 'g')
endfunction
-" Decode a pathname previously encoded with xolox#misc#path#encode().
-function! xolox#misc#path#decode(encoded_path)
+function! xolox#misc#path#decode(encoded_path) " {{{1
+ " Decode a pathname previously encoded with xolox#misc#path#encode().
return substitute(a:encoded_path, '%\(\x\x\?\)', '\=nr2char("0x" . submatch(1))', 'g')
endfunction
+" xolox#misc#path#equals(a, b) {{{1
" Check whether two pathnames point to the same file.
if s:windows_compatible
@@ -158,9 +156,8 @@ else
endfunction
endif
-" Check whether a path is relative.
-
-function! xolox#misc#path#is_relative(path)
+function! xolox#misc#path#is_relative(path) " {{{1
+ " Check whether a path is relative.
if a:path =~ '^\w\+://'
return 0
elseif s:windows_compatible
@@ -170,9 +167,8 @@ function! xolox#misc#path#is_relative(path)
endif
endfunction
-" Create a temporary directory and return the path.
-
-function! xolox#misc#path#tempdir()
+function! xolox#misc#path#tempdir() " {{{1
+ " Create a temporary directory and return the path.
if !exists('s:tempdir_counter')
let s:tempdir_counter = 1
endif