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.
This commit is contained in:
parent
a9ab90198b
commit
81a42acb97
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user