Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

tlib#file#Relative(): Wrong results for filenames that don't exist

  • Loading branch information...
commit 8d003efcd06471d8320ae4fc6422aa348cf8ee64 1 parent c98db8c
@tomtom authored
Showing with 21 additions and 6 deletions.
  1. +21 −6 autoload/tlib/file.vim
View
27 autoload/tlib/file.vim
@@ -4,7 +4,7 @@
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-06-30.
" @Last Change: 2012-03-23.
-" @Revision: 0.0.106
+" @Revision: 0.0.128
if &cp || exists("loaded_tlib_file_autoload")
finish
@@ -60,14 +60,14 @@ function! tlib#file#Relative(filename, basedir) "{{{3
" TLogVAR a:filename, a:basedir
" TLogDBG getcwd()
" TLogDBG expand('%:p')
- let f0 = fnamemodify(a:filename, ':p')
+ let b0 = tlib#file#Absolute(a:basedir)
+ let b = tlib#file#Split(b0)
+ " TLogVAR b
+ let f0 = tlib#file#Absolute(a:filename)
let fn = fnamemodify(f0, ':t')
let fd = fnamemodify(f0, ':h')
let f = tlib#file#Split(fd)
- " TLogVAR f
- let b0 = fnamemodify(a:basedir, ':p')
- let b = tlib#file#Split(b0)
- " TLogVAR b
+ " TLogVAR f0, fn, fd, f
if f[0] != b[0]
let rv = f0
else
@@ -78,6 +78,7 @@ function! tlib#file#Relative(filename, basedir) "{{{3
call remove(f, 0)
call remove(b, 0)
endwh
+ " TLogVAR f, b
let rv = tlib#file#Join(repeat(['..'], len(b)) + f + [fn])
endif
" TLogVAR rv
@@ -85,6 +86,20 @@ function! tlib#file#Relative(filename, basedir) "{{{3
endf
+function! tlib#file#Absolute(filename, ...) "{{{3
+ if filereadable(a:filename)
+ let filename = fnamemodify(a:filename, ':p')
+ elseif a:filename =~ '^\(/\|[^\/]\+:\)'
+ let filename = a:filename
+ else
+ let cwd = a:0 >= 1 ? a:1 : getcwd()
+ let filename = tlib#file#Join([cwd, a:filename])
+ endif
+ let filename = substitute(filename, '[\/]\zs[^\/]\+[\/]\.\.[\/]', '', 'g')
+ return filename
+endf
+
+
function! s:SetScrollBind(world) "{{{3
let sb = get(a:world, 'scrollbind', &scrollbind)
if sb != &scrollbind
Please sign in to comment.
Something went wrong with that request. Please try again.