Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Broken "g:NERDTreeBookmarksSort" setting fixed. #696

Merged
merged 4 commits into from
May 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions autoload/nerdtree.vim
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ function! nerdtree#completeBookmarks(A,L,P)
return filter(g:NERDTreeBookmark.BookmarkNames(), 'v:val =~# "^' . a:A . '"')
endfunction

"FUNCTION: nerdtree#compareBookmarks(dir) {{{2
function! nerdtree#compareBookmarks(first, second)
return a:first.compareTo(a:second)
endfunction

"FUNCTION: nerdtree#compareNodes(dir) {{{2
function! nerdtree#compareNodes(n1, n2)
return a:n1.path.compareTo(a:n2.path)
Expand Down
10 changes: 7 additions & 3 deletions doc/NERD_tree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -835,11 +835,15 @@ This is where bookmarks are saved. See |NERDTreeBookmarkCommands|.

------------------------------------------------------------------------------
*'NERDTreeBookmarksSort'*
Values: 0 or 1
Values: 0, 1, or 2
Default: 1

If set to 0 then the bookmarks list is not sorted.
If set to 1 the bookmarks list is sorted.
This option controls the method by which the list of user bookmarks is
sorted. When sorted, bookmarks will render in alphabetical order by name.

If set to 0, the bookmarks list is not sorted.
If set to 1, the bookmarks list is sorted in a case-insensitive manner.
If set to 2, the bookmarks list is sorted in a case-sensitive manner.

------------------------------------------------------------------------------
*'NERDTreeMouseMode'*
Expand Down
57 changes: 34 additions & 23 deletions lib/nerdtree/bookmark.vim
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ function! s:Bookmark.AddBookmark(name, path)
endif
endfor
call add(s:Bookmark.Bookmarks(), s:Bookmark.New(a:name, a:path))
if g:NERDTreeBookmarksSort ==# 1
call s:Bookmark.Sort()
endif
endfunction

" FUNCTION: Bookmark.Bookmarks() {{{1
" FUNCTION: Bookmark.Bookmarks() {{{1
" Class method to get all bookmarks. Lazily initializes the bookmarks global
" variable
function! s:Bookmark.Bookmarks()
Expand All @@ -34,7 +31,7 @@ function! s:Bookmark.Bookmarks()
return g:NERDTreeBookmarks
endfunction

" FUNCTION: Bookmark.BookmarkExistsFor(name) {{{1
" FUNCTION: Bookmark.BookmarkExistsFor(name) {{{1
" class method that returns 1 if a bookmark with the given name is found, 0
" otherwise
function! s:Bookmark.BookmarkExistsFor(name)
Expand All @@ -46,7 +43,7 @@ function! s:Bookmark.BookmarkExistsFor(name)
endtry
endfunction

" FUNCTION: Bookmark.BookmarkFor(name) {{{1
" FUNCTION: Bookmark.BookmarkFor(name) {{{1
" Class method to get the bookmark that has the given name. {} is return if no
" bookmark is found
function! s:Bookmark.BookmarkFor(name)
Expand All @@ -58,7 +55,7 @@ function! s:Bookmark.BookmarkFor(name)
throw "NERDTree.BookmarkNotFoundError: no bookmark found for name: \"". a:name .'"'
endfunction

" FUNCTION: Bookmark.BookmarkNames() {{{1
" FUNCTION: Bookmark.BookmarkNames() {{{1
" Class method to return an array of all bookmark names
function! s:Bookmark.BookmarkNames()
let names = []
Expand Down Expand Up @@ -104,17 +101,31 @@ function! s:Bookmark.CacheBookmarks(silent)
call nerdtree#echo(invalidBookmarksFound . " invalid bookmarks were read. See :help NERDTreeInvalidBookmarks for info.")
endif
endif
if g:NERDTreeBookmarksSort ==# 1
call s:Bookmark.Sort()
endif
endif
endfunction

" FUNCTION: Bookmark.compareTo(otherbookmark) {{{1
" Compare these two bookmarks for sorting purposes
function! s:Bookmark.compareTo(otherbookmark)
return a:otherbookmark.name < self.name
" FUNCTION: Bookmark.CompareBookmarksByName(firstBookmark, secondBookmark) {{{1
" Class method that indicates the relative position of two bookmarks when
" placed in alphabetical order by name. Case-sensitivity is determined by an
" option. Supports the "s:Bookmark.SortBookmarksList()" method.
function! s:Bookmark.CompareBookmarksByName(firstBookmark, secondBookmark)
let l:result = 0
if g:NERDTreeBookmarksSort == 1
if a:firstBookmark.name <? a:secondBookmark.name
let l:result = -1
elseif a:firstBookmark.name >? a:secondBookmark.name
let l:result = 1
endif
elseif g:NERDTreeBookmarksSort == 2
if a:firstBookmark.name <# a:secondBookmark.name
let l:result = -1
elseif a:firstBookmark.name ># a:secondBookmark.name
let l:result = 1
endif
endif
return l:result
endfunction

" FUNCTION: Bookmark.ClearAll() {{{1
" Class method to delete all bookmarks.
function! s:Bookmark.ClearAll()
Expand Down Expand Up @@ -170,7 +181,7 @@ function! s:Bookmark.GetSelected()
return {}
endfunction

" FUNCTION: Bookmark.InvalidBookmarks() {{{1
" FUNCTION: Bookmark.InvalidBookmarks() {{{1
" Class method to get all invalid bookmark strings read from the bookmarks
" file
function! s:Bookmark.InvalidBookmarks()
Expand Down Expand Up @@ -233,20 +244,20 @@ function! s:Bookmark.openInNewTab(options)
call self.open(a:options)
endfunction

" FUNCTION: Bookmark.setPath(path) {{{1
" FUNCTION: Bookmark.setPath(path) {{{1
" makes this bookmark point to the given path
function! s:Bookmark.setPath(path)
let self.path = a:path
endfunction

" FUNCTION: Bookmark.Sort() {{{1
" Class method that sorts all bookmarks
function! s:Bookmark.Sort()
let CompareFunc = function("nerdtree#compareBookmarks")
call sort(s:Bookmark.Bookmarks(), CompareFunc)
" FUNCTION: Bookmark.SortBookmarksList() {{{1
" Class method that sorts the global list of bookmarks alphabetically by name.
" Note that case-sensitivity is determined by a user option.
function! s:Bookmark.SortBookmarksList()
call sort(s:Bookmark.Bookmarks(), s:Bookmark.CompareBookmarksByName)
endfunction

" FUNCTION: Bookmark.str() {{{1
" FUNCTION: Bookmark.str() {{{1
" Get the string that should be rendered in the view for this bookmark
function! s:Bookmark.str()
let pathStrMaxLen = winwidth(g:NERDTree.GetWinNum()) - 4 - len(self.name)
Expand Down Expand Up @@ -292,7 +303,7 @@ function! s:Bookmark.validate()
endif
endfunction

" FUNCTION: Bookmark.Write() {{{1
" FUNCTION: Bookmark.Write() {{{1
" Class method to write all bookmarks to the bookmarks file
function! s:Bookmark.Write()
let bookmarkStrings = []
Expand Down
4 changes: 4 additions & 0 deletions lib/nerdtree/ui.vim
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ function! s:UI._renderBookmarks()
call cursor(line(".")+1, col("."))
endif

if g:NERDTreeBookmarksSort == 1 || g:NERDTreeBookmarksSort == 2
call g:NERDTreeBookmark.SortBookmarksList()
endif

for i in g:NERDTreeBookmark.Bookmarks()
call setline(line(".")+1, i.str())
call cursor(line(".")+1, col("."))
Expand Down