Compare commits

..

15 Commits
6.6.0 ... 6.7.8

Author SHA1 Message Date
Phil Runninger
5e77fb2fef Fix example code for the NERDTreeAddKeyMap function. (#1116)
* Fix example code for the NERDTreeAddKeyMap function.

The quickhelpText didn't match what the statement in the callback
function actually did.

* Update version number in change log.
2020-05-03 01:21:34 -04:00
Phil Runninger
29a321d061 Put '%' argument in bufname() for backwards compatibility. (#1105)
* Put '%' argument in bufname() for backwards compatibility.

* Update version number in change log.
2020-04-15 08:58:07 -04:00
Phil Runninger
0257d64248 If a file's already open in the window, don't edit it again. (#1103)
* If a file's already open in the window, don't edit it again.

* Update version number in change log.

* Make only one call to self.str().
2020-04-15 00:55:13 -04:00
Phil Runninger
2d7cb043d4 Prevent unneeded tree creation in :NERDTreeToggle[VCS] <path> (#1101)
* Don't recreate the NERDTree if its root is the same as being requested.

* Use single quotes per Vint's style recommendation.

* Update version number in changelog.

* Use a simpler method of getting the NERDTree root path.

* Remove variable. Just compare agains the function call's result.
2020-04-13 17:05:27 -04:00
lifecrisis
f767dd34a0 Add missing calls to the shellescape() function (#1099)
* Improve "g:NERDTreeQuickLook()"

The following improvements were made...

  - Use variable sigils
  - Shorten a local variable name
  - Prefer an early return over testing for a negative
  - Switch to single quotes
  - Call "shellescape()" to pass a command argument [IMPORTANT!]

The final change is a critical fix for the security and reliability
of this function (see ":h system()").

Similar fixes for the other functions in this script will follow.

* Improve "g:NERDTreeRevealInFinder()"

This commit makes several style improvements and adds a missing call
to the "shellescape()" function.

See also: 56cfbcff1e

* Improve "g:NERDTreeExecuteFile()"

Refer to: 56cfbcff1e

* Improve "g:NERDTreeRevealFileLinux()"

Refer to: 56cfbcff1e

* Improve "g:NERDTreeExecuteFileLinux()"

Refer to: 56cfbcff1e

* Properly reveal "/" on Linux

This commit handles the edge case where a user invokes the "reveal"
function on "/" on a Linux box.  There is nothing to do but open the
root directory itself since "/" has no parent.

* Update the "CHANGELOG.md" file

* Add final missing "shellescape()" calls

I initially thought that there were several more locations where
a call to "shellescape()" was required but omitted.  However, there
are only two.  I suppose I should have taken the time to look.

Fixing these was easy.  I would be surprised if this change breaks
anything on the user side.

* Update the "CHANGELOG.md" file (again)

Use a more fitting description of the change...
2020-04-09 21:37:55 -04:00
Rolando
832bbaa729 Fix vsplit to not open empty buffer (#1098)
* Fix vsplit to not open empty buffer

* Add changelog entry
2020-04-01 01:21:37 -04:00
Eugenij
343508e9fd Fix infinity loop in FindParentVCSRoot (#1095)
* Fix infinity loop in FindParentVCSRoot (on windows os with 'set shellslash' in vimrc and no VCS in path)

* update CHANGELOG.md

* Update CHANGELOG.md

Co-Authored-By: Phil Runninger <PhilRunninger@users.noreply.github.com>

Co-authored-by: evgenij.vidershpan <evgenij.vidershpan@yandex.ru>
Co-authored-by: Phil Runninger <PhilRunninger@users.noreply.github.com>
2020-03-26 16:33:11 -04:00
Phil Runninger
495b4e781a File Move: Escape existing directory name when looking for open files. (#1094)
* File Move: Escape existing directory name when looking for open files.

* Update version number in change log.

Co-authored-by: Phil Runninger <prunninger@vhtcx.com>
2020-03-24 15:08:06 -04:00
Phil Runninger
e67324fdea Merge pull request #1090 from bouk/open-on-find-unsaved-file
Open the parent directory when revealing a non-existent file
2020-02-20 09:10:19 -05:00
Bouke van der Bijl
5249b30fbf Use single-quoted string to comply with styleguide 2020-02-20 10:50:15 +01:00
Bouke van der Bijl
09b165cfac Add changelog entry 2020-02-20 10:49:03 +01:00
Bouke van der Bijl
6224d20698 Open the parent directory when revealing a non-existent file
Right now it just reveals the directory but leaves it closed.

Related to #1043
2020-02-20 10:45:09 +01:00
Phil Runninger
07612557eb Give kazukazuinaina proper credit. 2020-02-07 14:11:00 -05:00
Phil Runninger
7a0312f492 Merge pull request #1087 from kazukazuinaina/add_dein_in_README
[add] How to install using dein.vim
2020-02-07 14:00:12 -05:00
kazukazuinaina
41a44be8d5 [add] How to install using dein.vim
update changelog
2020-02-08 03:45:28 +09:00
9 changed files with 75 additions and 28 deletions

View File

@@ -4,7 +4,18 @@
version in an unordered list. The format is: version in an unordered list. The format is:
- **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR) - **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR)
--> -->
#### 6.7
- **.8**: Fix example code for the NERDTreeAddKeyMap function. (PhilRunninger) [#1116](https://github.com/preservim/nerdtree/pull/1116)
- **.7**: Put '%' argument in bufname() for backwards compatibility. (PhilRunninger) [#1105](https://github.com/preservim/nerdtree/pull/1105)
- **.6**: If a file's already open in the window, don't edit it again. (PhilRunninger) [#1103](https://github.com/preservim/nerdtree/pull/1103)
- **.5**: Prevent unneeded tree creation in `:NERDTreeToggle[VCS] <path>` (PhilRunninger) [#1101](https://github.com/preservim/nerdtree/pull/1101)
- **.4**: Add missing calls to the `shellescape()` function (lifecrisis) [#1099](https://github.com/preservim/nerdtree/pull/1099)
- **.3**: Fix vsplit to not open empty buffers when opening previously closed file (AwkwardKore) [#1098](https://github.com/preservim/nerdtree/pull/1098)
- **.2**: Fix infinity loop (on winvim) in FindParentVCSRoot (Eugenij-W) [#1095](https://github.com/preservim/nerdtree/pull/1095)
- **.1**: File Move: Escape existing directory name when looking for open files. (PhilRunninger) [#1094](https://github.com/preservim/nerdtree/pull/1094)
- **.0**: Open the parent directory when revealing a non-existent file with :NERDTreeFind (bouk) [#1090](https://github.com/preservim/nerdtree/pull/1090)
#### 6.6 #### 6.6
- **.1**: [add] How to install using dein.vim (kazukazuinaina) [#1087](https://github.com/preservim/nerdtree/pull/1087)
- **.0**: Add the ability to turn off directory arrows (PhilRunninger) [#1085](https://github.com/preservim/nerdtree/pull/1085) - **.0**: Add the ability to turn off directory arrows (PhilRunninger) [#1085](https://github.com/preservim/nerdtree/pull/1085)
#### 6.5 #### 6.5
- **.0**: `NERDTreeToggle <start-directory>` always sets NERDTree root. (PhilRunninger) [#1083](https://github.com/preservim/nerdtree/pull/1083) - **.0**: `NERDTreeToggle <start-directory>` always sets NERDTree root. (PhilRunninger) [#1083](https://github.com/preservim/nerdtree/pull/1083)

View File

@@ -59,6 +59,13 @@ Plug 'preservim/nerdtree'
call plug#end() call plug#end()
``` ```
#### [dein.vim](https://github.com/Shougo/dein.vim)
```vim
call dein#begin()
call dein#add('preservim/nerdtree')
call dein#end()
```
#### [apt-vim](https://github.com/egalpin/apt-vim) #### [apt-vim](https://github.com/egalpin/apt-vim)
```bash ```bash
apt-vim install -y https://github.com/preservim/nerdtree.git apt-vim install -y https://github.com/preservim/nerdtree.git

View File

@@ -284,6 +284,7 @@ endfunction
" FUNCTION: s:findAndRevealPath(pathStr) {{{1 " FUNCTION: s:findAndRevealPath(pathStr) {{{1
function! s:findAndRevealPath(pathStr) abort function! s:findAndRevealPath(pathStr) abort
let l:pathStr = !empty(a:pathStr) ? a:pathStr : expand('%:p') let l:pathStr = !empty(a:pathStr) ? a:pathStr : expand('%:p')
let l:revealOpts = {}
if empty(l:pathStr) if empty(l:pathStr)
call nerdtree#echoWarning('no file for the current buffer') call nerdtree#echoWarning('no file for the current buffer')
@@ -292,6 +293,7 @@ function! s:findAndRevealPath(pathStr) abort
if !filereadable(l:pathStr) if !filereadable(l:pathStr)
let l:pathStr = fnamemodify(l:pathStr, ':h') let l:pathStr = fnamemodify(l:pathStr, ':h')
let l:revealOpts['open'] = 1
endif endif
try try
@@ -327,7 +329,7 @@ function! s:findAndRevealPath(pathStr) abort
call b:NERDTree.ui.setShowHidden(1) call b:NERDTree.ui.setShowHidden(1)
endif endif
let l:node = b:NERDTree.root.reveal(l:pathObj) let l:node = b:NERDTree.root.reveal(l:pathObj, l:revealOpts)
call b:NERDTree.render() call b:NERDTree.render()
call l:node.putCursorHere(1, 0) call l:node.putCursorHere(1, 0)
endfunction endfunction

View File

@@ -1353,12 +1353,12 @@ NERDTreeAddKeyMap({options}) *NERDTreeAddKeyMap()*
Example: > Example: >
call NERDTreeAddKeyMap({ call NERDTreeAddKeyMap({
\ 'key': 'foo', \ 'key': 'foo',
\ 'callback': 'NERDTreeCDHandler', \ 'callback': 'NERDTreeEchoPathHandler',
\ 'quickhelpText': 'echo full path of current node', \ 'quickhelpText': 'echo full path of current node',
\ 'scope': 'DirNode' }) \ 'scope': 'DirNode' })
function! NERDTreeCDHandler(dirnode) function! NERDTreeEchoPathHandler(dirnode)
call a:dirnode.changeToDir() echo a:dirnode.path.str()
endfunction endfunction
< <
This code should sit in a file like ~/.vim/nerdtree_plugin/mymapping.vim. This code should sit in a file like ~/.vim/nerdtree_plugin/mymapping.vim.

View File

@@ -366,7 +366,7 @@ function! s:Creator.toggleTabTree(dir)
if g:NERDTree.ExistsForTab() if g:NERDTree.ExistsForTab()
if !g:NERDTree.IsOpen() if !g:NERDTree.IsOpen()
call self._createTreeWin() call self._createTreeWin()
if !empty(a:dir) if !empty(a:dir) && a:dir !=# b:NERDTree.root.path.str()
call self.createTabTree(a:dir) call self.createTabTree(a:dir)
elseif !&hidden elseif !&hidden
call b:NERDTree.render() call b:NERDTree.render()

View File

@@ -195,7 +195,7 @@ function! s:Opener._newVSplit()
endif endif
call nerdtree#exec('wincmd p', 1) call nerdtree#exec('wincmd p', 1)
call nerdtree#exec('vnew', 1) call nerdtree#exec('vsplit', 1)
let l:currentWindowNumber = winnr() let l:currentWindowNumber = winnr()

View File

@@ -199,7 +199,7 @@ function! s:Path.copy(dest)
let cmd_prefix = (self.isDirectory ? g:NERDTreeCopyDirCmd : g:NERDTreeCopyFileCmd) let cmd_prefix = (self.isDirectory ? g:NERDTreeCopyDirCmd : g:NERDTreeCopyFileCmd)
endif endif
let cmd = cmd_prefix . ' ' . escape(self.str(), self._escChars()) . ' ' . escape(a:dest, self._escChars()) let cmd = cmd_prefix . ' ' . shellescape(self.str()) . ' ' . shellescape(a:dest)
let success = system(cmd) let success = system(cmd)
if v:shell_error !=# 0 if v:shell_error !=# 0
throw "NERDTree.CopyError: Could not copy '". self.str() ."' to: '" . a:dest . "'" throw "NERDTree.CopyError: Could not copy '". self.str() ."' to: '" . a:dest . "'"
@@ -295,7 +295,10 @@ endfunction
" FUNCTION: Path.edit() {{{1 " FUNCTION: Path.edit() {{{1
function! s:Path.edit() function! s:Path.edit()
exec 'edit ' . self.str({'format': 'Edit'}) let l:bufname = self.str({'format': 'Edit'})
if bufname('%') !=# l:bufname
exec 'edit ' . l:bufname
endif
endfunction endfunction
" FUNCTION: Path.extractDriveLetter(fullpath) {{{1 " FUNCTION: Path.extractDriveLetter(fullpath) {{{1

View File

@@ -209,7 +209,8 @@ function! NERDTreeMoveNode()
try try
if curNode.path.isDirectory if curNode.path.isDirectory
let l:openBuffers = filter(range(1,bufnr('$')),'bufexists(v:val) && fnamemodify(bufname(v:val),":p") =~# curNode.path.str() . "/.*"') let l:curPath = escape(curNode.path.str(),'\') . (nerdtree#runningWindows()?'\\':'/') . '.*'
let l:openBuffers = filter(range(1,bufnr('$')),'bufexists(v:val) && fnamemodify(bufname(v:val),":p") =~# "'.escape(l:curPath,'\').'"')
else else
let l:openBuffers = filter(range(1,bufnr('$')),'bufexists(v:val) && fnamemodify(bufname(v:val),":p") ==# curNode.path.str()') let l:openBuffers = filter(range(1,bufnr('$')),'bufexists(v:val) && fnamemodify(bufname(v:val),":p") ==# curNode.path.str()')
endif endif
@@ -387,44 +388,67 @@ endfunction
" FUNCTION: NERDTreeQuickLook() {{{1 " FUNCTION: NERDTreeQuickLook() {{{1
function! NERDTreeQuickLook() function! NERDTreeQuickLook()
let treenode = g:NERDTreeFileNode.GetSelected() let l:node = g:NERDTreeFileNode.GetSelected()
if treenode !=# {}
call system("qlmanage -p 2>/dev/null '" . treenode.path.str() . "'") if empty(l:node)
return
endif endif
call system('qlmanage -p 2>/dev/null ' . shellescape(l:node.path.str()))
endfunction endfunction
" FUNCTION: NERDTreeRevealInFinder() {{{1 " FUNCTION: NERDTreeRevealInFinder() {{{1
function! NERDTreeRevealInFinder() function! NERDTreeRevealInFinder()
let treenode = g:NERDTreeFileNode.GetSelected() let l:node = g:NERDTreeFileNode.GetSelected()
if treenode !=# {}
call system("open -R '" . treenode.path.str() . "'") if empty(l:node)
return
endif endif
call system('open -R ' . shellescape(l:node.path.str()))
endfunction endfunction
" FUNCTION: NERDTreeExecuteFile() {{{1 " FUNCTION: NERDTreeExecuteFile() {{{1
function! NERDTreeExecuteFile() function! NERDTreeExecuteFile()
let treenode = g:NERDTreeFileNode.GetSelected() let l:node = g:NERDTreeFileNode.GetSelected()
if treenode !=# {}
call system("open '" . treenode.path.str() . "'") if empty(l:node)
return
endif endif
call system('open ' . shellescape(l:node.path.str()))
endfunction endfunction
" FUNCTION: NERDTreeRevealFileLinux() {{{1 " FUNCTION: NERDTreeRevealFileLinux() {{{1
function! NERDTreeRevealFileLinux() function! NERDTreeRevealFileLinux()
let treenode = g:NERDTreeFileNode.GetSelected() let l:node = g:NERDTreeFileNode.GetSelected()
let parentnode = treenode.parent
if parentnode !=# {} if empty(l:node)
call system("xdg-open '" . parentnode.path.str() . "' &") return
endif endif
" Handle the edge case of "/", which has no parent.
if l:node.path.str() ==# '/'
call system('xdg-open /')
return
endif
if empty(l:node.parent)
return
endif
call system('xdg-open ' . shellescape(l:node.parent.path.str()))
endfunction endfunction
" FUNCTION: NERDTreeExecuteFileLinux() {{{1 " FUNCTION: NERDTreeExecuteFileLinux() {{{1
function! NERDTreeExecuteFileLinux() function! NERDTreeExecuteFileLinux()
let treenode = g:NERDTreeFileNode.GetSelected() let l:node = g:NERDTreeFileNode.GetSelected()
if treenode !=# {}
call system("xdg-open '" . treenode.path.str() . "' &") if empty(l:node)
return
endif endif
call system('xdg-open ' . shellescape(l:node.path.str()))
endfunction endfunction
" vim: set sw=4 sts=4 et fdm=marker: " vim: set sw=4 sts=4 et fdm=marker:

View File

@@ -34,7 +34,7 @@ endfunction
function! s:FindParentVCSRoot(path) function! s:FindParentVCSRoot(path)
let l:path = a:path let l:path = a:path
while !empty(l:path) && while !empty(l:path) &&
\ l:path._str() !~# '^\(\a:\\\|\/\)$' && \ l:path._str() !~# '^\(\a:[\\\/]\|\/\)$' &&
\ !isdirectory(l:path._str() . '/.git') && \ !isdirectory(l:path._str() . '/.git') &&
\ !isdirectory(l:path._str() . '/.svn') && \ !isdirectory(l:path._str() . '/.svn') &&
\ !isdirectory(l:path._str() . '/.hg') && \ !isdirectory(l:path._str() . '/.hg') &&
@@ -42,6 +42,6 @@ function! s:FindParentVCSRoot(path)
\ !isdirectory(l:path._str() . '/_darcs') \ !isdirectory(l:path._str() . '/_darcs')
let l:path = l:path.getParent() let l:path = l:path.getParent()
endwhile endwhile
return (empty(l:path) || l:path._str() =~# '^\(\a:\\\|\/\)$') ? a:path : l:path return (empty(l:path) || l:path._str() =~# '^\(\a:[\\\/]\|\/\)$') ? a:path : l:path
endfunction endfunction