From 81a42acb97deac6b83db464999d77036c5bf42da Mon Sep 17 00:00:00 2001 From: Jason Franklin Date: Sat, 10 Jun 2017 09:20:52 -0400 Subject: [PATCH] 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. --- lib/nerdtree/bookmark.vim | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/nerdtree/bookmark.vim b/lib/nerdtree/bookmark.vim index ad8c3d1..9024077 100644 --- 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