Merge pull request #722 from lifecrisis/open-bookmark

Have bookmarked directories open with all children closed.
This commit is contained in:
Jason Franklin 2017-07-17 08:13:12 -04:00 committed by GitHub
commit e2a9929bbe
2 changed files with 15 additions and 19 deletions

View File

@ -293,23 +293,26 @@ function! s:Bookmark.str()
endfunction endfunction
" FUNCTION: Bookmark.toRoot(nerdtree) {{{1 " 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) function! s:Bookmark.toRoot(nerdtree)
if self.validate() if self.validate()
try try
let targetNode = self.getNode(a:nerdtree, 1) let l:targetNode = self.getNode(a:nerdtree, 1)
call l:targetNode.closeChildren()
catch /^NERDTree.BookmarkedNodeNotFoundError/ 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 endtry
call a:nerdtree.changeRoot(targetNode) call a:nerdtree.changeRoot(l:targetNode)
endif endif
endfunction endfunction
" FUNCTION: Bookmark.ToRoot(name, nerdtree) {{{1 " 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) function! s:Bookmark.ToRoot(name, nerdtree)
let bookmark = s:Bookmark.BookmarkFor(a:name) let l:bookmark = s:Bookmark.BookmarkFor(a:name)
call bookmark.toRoot(a:nerdtree) call l:bookmark.toRoot(a:nerdtree)
endfunction endfunction
" FUNCTION: Bookmark.validate() {{{1 " FUNCTION: Bookmark.validate() {{{1

View File

@ -56,12 +56,12 @@ function! s:TreeDirNode.close()
endfunction endfunction
" FUNCTION: TreeDirNode.closeChildren() {{{1 " 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() function! s:TreeDirNode.closeChildren()
for i in self.children for l:child in self.children
if i.path.isDirectory if l:child.path.isDirectory
call i.close() call l:child.close()
call i.closeChildren() call l:child.closeChildren()
endif endif
endfor endfor
endfunction endfunction
@ -220,13 +220,6 @@ function! s:TreeDirNode.getChildIndex(path)
return -1 return -1
endfunction 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 " FUNCTION: TreeDirNode._glob(pattern, all) {{{1
" Return a list of strings naming the descendants of the directory in this " Return a list of strings naming the descendants of the directory in this
" TreeDirNode object that match the specified glob pattern. " TreeDirNode object that match the specified glob pattern.