Rewrite the "Path._strForEdit()" method

This method used the brittle "Path._escChars()" method to do its
work.  This created problems when 'shellslash' was in use on Windows
because excessive escape characters (i.e., backslashes!) are
interpreted by Vim as additional path separators.

The above problem made it impossible to edit files with weird names
using the NERDTree on Windows with 'shellslash' set.  For example,
'+' should be escaped with ":edit", but '(' should not.  So, when
escaping '(', Vim on Windows correctly sees the start of a new
directory in the path.

This was reported in five issues which may be read for further
details and commentary.

Fixes #398, fixes #474, fixes #653, fixes #674, and fixes #733.
This commit is contained in:
Jason Franklin
2017-08-11 10:09:18 -04:00
parent 7a2fc6b6b9
commit a32a55e8d9

View File

@@ -726,22 +726,23 @@ endfunction
" Return a string representation of this Path that is suitable for use as an " Return a string representation of this Path that is suitable for use as an
" argument to Vim's internal ":edit" command. " argument to Vim's internal ":edit" command.
function! s:Path._strForEdit() function! s:Path._strForEdit()
let p = escape(self.str(), self._escChars())
"make it relative " Make the path relative to the current working directory, if possible.
let p = fnamemodify(p, ':.') let l:result = fnamemodify(self.str(), ':.')
"handle the edge case where the file begins with a + (vim interprets " On Windows, the drive letter may be removed by "fnamemodify()". Add it
"the +foo in `:e +foo` as an option to :edit) " back, if necessary.
if p[0] == "+" if nerdtree#runningWindows() && l:result[0] == s:Path.Slash()
let p = '\' . p let l:result = self.drive . l:result
endif endif
if p ==# '' let l:result = fnameescape(l:result)
let p = '.'
if empty(l:result)
let l:result = '.'
endif endif
return p return l:result
endfunction endfunction
" FUNCTION: Path._strForGlob() {{{1 " FUNCTION: Path._strForGlob() {{{1