commit 81a42acb97deac6b83db464999d77036c5bf42da
parent a9ab90198be0581fe961125bba3f282a666ef7ff
Author: Jason Franklin <j_fra@fastmail.us>
Date: Sat, 10 Jun 2017 09:20:52 -0400
Refactor the bookmark query function
The function in "bookmark.vim" that allows the caller to query the list
of Bookmarks by name had stale commentary. In addition, the internals of
the function needed to be reworked to improve readability. Making this
function very clean is important because it is heavily used elsewhere.
As a side note, it might be beneficial to later rename this function to
something like "GetBookmarkByName" to further improve readability. That
change is not critical and can be safely delayed.
Diffstat:
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/lib/nerdtree/bookmark.vim b/lib/nerdtree/bookmark.vim
@@ -44,15 +44,20 @@ function! s:Bookmark.BookmarkExistsFor(name)
endfunction
" FUNCTION: Bookmark.BookmarkFor(name) {{{1
-" Class method to get the bookmark that has the given name. {} is return if no
-" bookmark is found
+" Class method that returns the Bookmark object having the specified name.
+" Throws "NERDTree.BookmarkNotFoundError" if no Bookmark is found.
function! s:Bookmark.BookmarkFor(name)
- for i in s:Bookmark.Bookmarks()
- if i.name ==# a:name
- return i
+ let l:result = {}
+ for l:bookmark in s:Bookmark.Bookmarks()
+ if l:bookmark.name ==# a:name
+ let l:result = l:bookmark
+ break
endif
endfor
- throw "NERDTree.BookmarkNotFoundError: no bookmark found for name: \"". a:name .'"'
+ if empty(l:result)
+ throw 'NERDTree.BookmarkNotFoundError: "' . a:name . '" not found'
+ endif
+ return l:result
endfunction
" FUNCTION: Bookmark.BookmarkNames() {{{1