From 030cff2edaedb4b78f56bb392010451fee78491c Mon Sep 17 00:00:00 2001 From: Martin Grenfell Date: Mon, 30 Jun 2008 09:36:50 +1200 Subject: [PATCH] sort bookmarks when we add a new one --- plugin/NERD_tree.vim | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index 86d182c..4b02a2f 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -166,6 +166,7 @@ function! s:oBookmark.AddBookmark(name, path) dict endif endfor call add(s:oBookmark.Bookmarks(), s:oBookmark.New(a:name, a:path)) + call s:oBookmark.Sort() endfunction " Function: oBookmark.Bookmarks() {{{3 " Class method to get all bookmarks. Lazily initializes the bookmarks global @@ -222,6 +223,11 @@ function! s:oBookmark.CacheBookmarks() dict endif endif endfunction +" FUNCTION: oBookmark.CompareTo(otherbookmark) {{{3 +" Compare these two bookmarks for sorting purposes +function! s:oBookmark.CompareTo(otherbookmark) dict + return a:otherbookmark.name < self.name +endfunction " FUNCTION: oBookmark.ClearAll() {{{3 " Class method to delete all bookmarks. function! s:oBookmark.ClearAll() dict @@ -280,6 +286,12 @@ function! s:oBookmark.New(name, path) dict let newBookmark.path = a:path return newBookmark endfunction +" Function: oBookmark.Sort() {{{3 +" Class method that sorts all bookmarks +function! s:oBookmark.Sort() dict + let CompareFunc = function("s:CompareBookmarks") + call sort(s:oBookmark.Bookmarks(), CompareFunc) +endfunction " Function: oBookmark.Str() {{{3 " Get the string that should be rendered in the view for this bookmark function! s:oBookmark.Str() dict @@ -1581,6 +1593,12 @@ function! s:BufInWindows(bnum) return cnt endfunction " >>> +"FUNCTION: CompareBookmarks(first, second) {{{2 +"Compares two bookmarks +function! s:CompareBookmarks(first, second) + return a:first.CompareTo(a:second) +endfunction + " FUNCTION: s:CompleteBookmarks(A,L,P) {{{2 " completion function for the bookmark commands function! s:CompleteBookmarks(A,L,P)