From 3245007f0e9c3a99040591ac8fc2a647d6ced4ee Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Fri, 14 Jul 2017 17:17:25 -0400 Subject: [PATCH 1/4] Remove a method from the TreeDirNode class The "TreeDirNode.getDirChildren()" method is never called and can be safely removed. Further, note that this method has a bug. It calls the "filter()" builtin function, which modifies "self.children" in-place. This is obviously not a desirable side effect of calling this function. If the functionality is genuinely required later, "filter()" should be called on a copy of "self.children" to achieve the desired result. --- lib/nerdtree/tree_dir_node.vim | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/nerdtree/tree_dir_node.vim b/lib/nerdtree/tree_dir_node.vim index 5ca94d4..88ea9e6 100644 --- a/lib/nerdtree/tree_dir_node.vim +++ b/lib/nerdtree/tree_dir_node.vim @@ -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. From 1f089a362b859f8879f70f1ccdb7e40d1e5ba822 Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Fri, 14 Jul 2017 17:36:09 -0400 Subject: [PATCH 2/4] Rework the "TreeDirNode.closeChildren()" method This function needed polishing; in the choice of variable names and in the leading comment. --- lib/nerdtree/tree_dir_node.vim | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/nerdtree/tree_dir_node.vim b/lib/nerdtree/tree_dir_node.vim index 88ea9e6..4a6d213 100644 --- 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 From 3a7694aa555f2b421ce6d685c0a8f19861161ed9 Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Fri, 14 Jul 2017 17:52:00 -0400 Subject: [PATCH 3/4] Add a call to close the children of bookmarks When bookmarks are opened normally (i.e., when a bookmark is made the root of the current NERDTree), any open children of that bookmark will remain open. This is often inconvenient, especially for users who want bookmarks to appear "fresh" when opened. --- lib/nerdtree/bookmark.vim | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/nerdtree/bookmark.vim b/lib/nerdtree/bookmark.vim index f8606ee..d7b9d3d 100644 --- a/lib/nerdtree/bookmark.vim +++ b/lib/nerdtree/bookmark.vim @@ -293,15 +293,17 @@ 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 From 5daec4c7b7baaa1525b92a6a9ec08f7cd102aa59 Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Fri, 14 Jul 2017 18:02:02 -0400 Subject: [PATCH 4/4] Edit stale commentary and add proper sigils --- lib/nerdtree/bookmark.vim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/nerdtree/bookmark.vim b/lib/nerdtree/bookmark.vim index d7b9d3d..45f9950 100644 --- a/lib/nerdtree/bookmark.vim +++ b/lib/nerdtree/bookmark.vim @@ -308,10 +308,11 @@ function! s:Bookmark.toRoot(nerdtree) 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