commit 96e247ba7488af1e71d0facfc68aba37e750298c
parent 2af10e3589307fea749012a2d757feda0f4e108a
Author: Phil Runninger <PhilRunninger@users.noreply.github.com>
Date: Tue, 14 Jul 2020 08:53:00 -0400
Respect user's &shellslash setting in CopyNode and RemoveNode functions (#1150)
* Replace s:Path.Slash() with nerdtree#slash().
* Check the value of &shell when determining the slash under Windows.
* Leave &shellslash unchanged when forming copy/delete commands.
* Fix fold marker.
* Update version number in change log.
* Add abort attribute to nerdtree#slash() to satisfy Vim style guide.
Co-authored-by: Phil Runninger <prunninger@vhtcx.com>
Diffstat:
6 files changed, 15 insertions(+), 35 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -7,6 +7,7 @@
#### 6.9
- **.3**: Fix new NERDTrees' width when previous one was in the only window. (PhilRunninger) [#1153](https://github.com/preservim/nerdtree/pull/1153)
- **.2**: Fix the scope of several key mappings (lifecrisis, PhilRunninger) [#1151](https://github.com/preservim/nerdtree/pull/1151)
+- **.1**: Respect user's `&shellslash` setting in CopyNode and RemoveNode functions (PhilRunninger) [#1150](https://github.com/preservim/nerdtree/pull/1150)
- **.0**: Enable opening bookmarks in split windows. (PhilRunninger) [#1144](https://github.com/preservim/nerdtree/pull/1144)
#### 6.8
- **.0**: Allow concealed characters to show another character. (PhilRunninger) [#1138](https://github.com/preservim/nerdtree/pull/1138)
diff --git a/autoload/nerdtree.vim b/autoload/nerdtree.vim
@@ -30,9 +30,11 @@ endfunction
" SECTION: General Functions {{{1
"============================================================
-"FUNCTION: nerdtree#slash() {{{2
+" FUNCTION: nerdtree#slash() {{{2
+" Return the path separator used by the underlying file system. Special
+" consideration is taken for the use of the 'shellslash' option on Windows
+" systems.
function! nerdtree#slash() abort
-
if nerdtree#runningWindows()
if exists('+shellslash') && &shellslash
return '/'
diff --git a/lib/nerdtree/creator.vim b/lib/nerdtree/creator.vim
@@ -247,7 +247,7 @@ function! s:Creator._pathForString(str)
"hack to get an absolute path if a relative path is given
if dir =~# '^\.'
- let dir = getcwd() . g:NERDTreePath.Slash() . dir
+ let dir = getcwd() . nerdtree#slash() . dir
endif
"hack to prevent removing slash if dir is the root of the file system.
diff --git a/lib/nerdtree/path.vim b/lib/nerdtree/path.vim
@@ -25,10 +25,10 @@ function! s:Path.AbsolutePathFor(pathStr)
if l:prependWorkingDir
let l:result = getcwd()
- if l:result[-1:] ==# s:Path.Slash()
+ if l:result[-1:] == nerdtree#slash()
let l:result = l:result . a:pathStr
else
- let l:result = l:result . s:Path.Slash() . a:pathStr
+ let l:result = l:result . nerdtree#slash() . a:pathStr
endif
endif
@@ -614,23 +614,6 @@ function! s:Path.New(pathStr)
return l:newPath
endfunction
-" FUNCTION: Path.Slash() {{{1
-" Return the path separator used by the underlying file system. Special
-" consideration is taken for the use of the 'shellslash' option on Windows
-" systems.
-function! s:Path.Slash()
-
- if nerdtree#runningWindows()
- if exists('+shellslash') && &shellslash
- return '/'
- endif
-
- return '\'
- endif
-
- return '/'
-endfunction
-
" FUNCTION: Path.Resolve() {{{1
" Invoke the vim resolve() function and return the result
" This is necessary because in some versions of vim resolve() removes trailing
@@ -815,7 +798,7 @@ function! s:Path._strForEdit()
" On Windows, the drive letter may be removed by "fnamemodify()". Add it
" back, if necessary.
- if nerdtree#runningWindows() && l:result[0] ==# s:Path.Slash()
+ if nerdtree#runningWindows() && l:result[0] == nerdtree#slash()
let l:result = self.drive . l:result
endif
@@ -830,14 +813,14 @@ endfunction
" FUNCTION: Path._strForGlob() {{{1
function! s:Path._strForGlob()
- let lead = s:Path.Slash()
+ let lead = nerdtree#slash()
"if we are running windows then slap a drive letter on the front
if nerdtree#runningWindows()
let lead = self.drive . '\'
endif
- let toReturn = lead . join(self.pathSegments, s:Path.Slash())
+ let toReturn = lead . join(self.pathSegments, nerdtree#slash())
if !nerdtree#runningWindows()
let toReturn = escape(toReturn, self._escChars())
@@ -849,7 +832,7 @@ endfunction
" Return the absolute pathname associated with this Path object. The pathname
" returned is appropriate for the underlying file system.
function! s:Path._str()
- let l:separator = s:Path.Slash()
+ let l:separator = nerdtree#slash()
let l:leader = l:separator
if nerdtree#runningWindows()
diff --git a/lib/nerdtree/tree_dir_node.vim b/lib/nerdtree/tree_dir_node.vim
@@ -278,8 +278,8 @@ function! s:TreeDirNode._glob(pattern, all)
else
let l:pathSpec = escape(fnamemodify(self.path.str({'format': 'Glob'}), ':.'), ',')
- " On Windows, the drive letter may be removed by fnamemodify().
- if nerdtree#runningWindows() && l:pathSpec[0] ==# g:NERDTreePath.Slash()
+ " On Windows, the drive letter may be removed by "fnamemodify()".
+ if nerdtree#runningWindows() && l:pathSpec[0] == nerdtree#slash()
let l:pathSpec = self.path.drive . l:pathSpec
endif
endif
diff --git a/nerdtree_plugin/fs_menu.vim b/nerdtree_plugin/fs_menu.vim
@@ -165,7 +165,7 @@ endfunction
function! NERDTreeAddNode()
let curDirNode = g:NERDTreeDirNode.GetSelected()
let prompt = s:inputPrompt('add')
- let newNodeName = input(prompt, curDirNode.path.str() . g:NERDTreePath.Slash(), 'file')
+ let newNodeName = input(prompt, curDirNode.path.str() . nerdtree#slash(), 'file')
if newNodeName ==# ''
call nerdtree#echo('Node Creation Aborted.')
@@ -252,8 +252,6 @@ endfunction
" FUNCTION: NERDTreeDeleteNode() {{{1
function! NERDTreeDeleteNode()
- let l:shellslash = &shellslash
- let &shellslash = 0
let currentNode = g:NERDTreeFileNode.GetSelected()
let confirmed = 0
@@ -289,7 +287,6 @@ function! NERDTreeDeleteNode()
else
call nerdtree#echo('delete aborted')
endif
- let &shellslash = l:shellslash
endfunction
" FUNCTION: NERDTreeListNode() {{{1
@@ -334,8 +331,6 @@ endfunction
" FUNCTION: NERDTreeCopyNode() {{{1
function! NERDTreeCopyNode()
- let l:shellslash = &shellslash
- let &shellslash = 0
let currentNode = g:NERDTreeFileNode.GetSelected()
let prompt = s:inputPrompt('copy')
let newNodePath = input(prompt, currentNode.path.str(), 'file')
@@ -371,7 +366,6 @@ function! NERDTreeCopyNode()
else
call nerdtree#echo('Copy aborted.')
endif
- let &shellslash = l:shellslash
redraw!
endfunction