commit a03a639390011a51358ec3460a3be58d6cd86e8a
parent c0b90811b08b336c4378cff17e0b6af578ae2b18
Author: Jason Franklin <j_fra@fastmail.us>
Date: Sat, 10 Jun 2017 13:29:27 -0400
Refactor and re-document Bookmark.getNode()
A few minor changes were made to the "Bookmark.getNode()" function for
the purposes of improving readability and documentation clarity.
This process also led me to the conclusion that the "findNode()"
function should be refactored to throw an error if a node cannot be
found. This would lead to greater uniformity in the reporting of
failures to find a node. It is generally better style to have an error
thrown as close to the source as possible. A substantial change like
this should wait for now.
Diffstat:
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/lib/nerdtree/bookmark.vim b/lib/nerdtree/bookmark.vim
@@ -157,18 +157,23 @@ function! s:Bookmark.delete()
endfunction
" FUNCTION: Bookmark.getNode(nerdtree, searchFromAbsoluteRoot) {{{1
-" Gets the treenode for this bookmark
+" Returns the tree node object associated with this Bookmark.
+" Throws "NERDTree.BookmarkedNodeNotFoundError" if the node is not found.
"
" Args:
-" searchFromAbsoluteRoot: specifies whether we should search from the current
-" tree root, or the highest cached node
+" searchFromAbsoluteRoot: boolean flag, search from the highest cached node
+" if true and from the current tree root if false
function! s:Bookmark.getNode(nerdtree, searchFromAbsoluteRoot)
- let searchRoot = a:searchFromAbsoluteRoot ? a:nerdtree.root.AbsoluteTreeRoot() : a:nerdtree.root
- let targetNode = searchRoot.findNode(self.path)
- if empty(targetNode)
- throw "NERDTree.BookmarkedNodeNotFoundError: no node was found for bookmark: " . self.name
+ if a:searchFromAbsoluteRoot
+ let l:searchRoot = a:nerdtree.root.AbsoluteTreeRoot()
+ else
+ let l:searchRoot = a:nerdtree.root
+ endif
+ let l:targetNode = l:searchRoot.findNode(self.path)
+ if empty(l:targetNode)
+ throw 'NERDTree.BookmarkedNodeNotFoundError: node for bookmark "' . self.name . '" not found'
endif
- return targetNode
+ return l:targetNode
endfunction
" FUNCTION: Bookmark.GetNodeForName(name, searchFromAbsoluteRoot, nerdtree) {{{1