commit e2a9929bbea0ec2050f2ea44b7e7bae3ccac66e6
parent a3fdf1e3c111e011af09d6d5a6b58517ea4fa6d7
Author: Jason Franklin <lifecrisis@users.noreply.github.com>
Date: Mon, 17 Jul 2017 08:13:12 -0400
Merge pull request #722 from lifecrisis/open-bookmark
Have bookmarked directories open with all children closed.
Diffstat:
2 files changed, 15 insertions(+), 19 deletions(-)
diff --git a/lib/nerdtree/bookmark.vim b/lib/nerdtree/bookmark.vim
@@ -293,23 +293,26 @@ function! s:Bookmark.str()
endfunction
" FUNCTION: Bookmark.toRoot(nerdtree) {{{1
-" Make the node for this bookmark the new tree root
+" Set the root of the given NERDTree to the node for this Bookmark. If a node
+" for this Bookmark does not exist, a new one is initialized.
function! s:Bookmark.toRoot(nerdtree)
if self.validate()
try
- let targetNode = self.getNode(a:nerdtree, 1)
+ let l:targetNode = self.getNode(a:nerdtree, 1)
+ call l:targetNode.closeChildren()
catch /^NERDTree.BookmarkedNodeNotFoundError/
- let targetNode = g:NERDTreeFileNode.New(s:Bookmark.BookmarkFor(self.name).path, a:nerdtree)
+ let l:targetNode = g:NERDTreeFileNode.New(s:Bookmark.BookmarkFor(self.name).path, a:nerdtree)
endtry
- call a:nerdtree.changeRoot(targetNode)
+ call a:nerdtree.changeRoot(l:targetNode)
endif
endfunction
" FUNCTION: Bookmark.ToRoot(name, nerdtree) {{{1
-" Make the node for this bookmark the new tree root
+" Class method that makes the Bookmark with the given name the root of
+" specified NERDTree.
function! s:Bookmark.ToRoot(name, nerdtree)
- let bookmark = s:Bookmark.BookmarkFor(a:name)
- call bookmark.toRoot(a:nerdtree)
+ let l:bookmark = s:Bookmark.BookmarkFor(a:name)
+ call l:bookmark.toRoot(a:nerdtree)
endfunction
" FUNCTION: Bookmark.validate() {{{1
diff --git a/lib/nerdtree/tree_dir_node.vim b/lib/nerdtree/tree_dir_node.vim
@@ -56,12 +56,12 @@ function! s:TreeDirNode.close()
endfunction
" FUNCTION: TreeDirNode.closeChildren() {{{1
-" Closes all the child dir nodes of this node
+" Recursively close any directory nodes that are descendants of this node.
function! s:TreeDirNode.closeChildren()
- for i in self.children
- if i.path.isDirectory
- call i.close()
- call i.closeChildren()
+ for l:child in self.children
+ if l:child.path.isDirectory
+ call l:child.close()
+ call l:child.closeChildren()
endif
endfor
endfunction
@@ -220,13 +220,6 @@ function! s:TreeDirNode.getChildIndex(path)
return -1
endfunction
-" FUNCTION: TreeDirNode.getDirChildren() {{{1
-" Return a list of all child nodes from "self.children" that are of type
-" TreeDirNode.
-function! s:TreeDirNode.getDirChildren()
- return filter(self.children, 'v:val.path.isDirectory == 1')
-endfunction
-
" FUNCTION: TreeDirNode._glob(pattern, all) {{{1
" Return a list of strings naming the descendants of the directory in this
" TreeDirNode object that match the specified glob pattern.