diff --git a/plugin/NERD_tree.vim b/plugin/NERD_tree.vim index eb0a511..42c620d 100644 --- a/plugin/NERD_tree.vim +++ b/plugin/NERD_tree.vim @@ -430,6 +430,37 @@ function! s:Bookmark.Write() endfor call writefile(bookmarkStrings, g:NERDTreeBookmarksFile) endfunction +"CLASS: KeyMap {{{2 +"============================================================ +let s:KeyMap = {} +"FUNCTION: KeyMap.All() {{{3 +function! s:KeyMap.All() + if !exists("s:keyMaps") + let s:keyMaps = [] + endif + return s:keyMaps +endfunction + +"FUNCTION: KeyMap.BindAll() {{{3 +function! s:KeyMap.BindAll() + for i in s:KeyMap.All() + call i.bind() + endfor +endfunction + +"FUNCTION: KeyMap.bind() {{{3 +function! s:KeyMap.bind() + exec "nnoremap ". self.key ." :call ". self.callback ."()" +endfunction + +"FUNCTION: KeyMap.Create(options) {{{3 +function! s:KeyMap.Create(options) + let newKeyMap = {} + let newKeyMap = copy(self) + let newKeyMap.key = a:options['key'] + let newKeyMap.callback = a:options['callback'] + call add(s:KeyMap.All(), newKeyMap) +endfunction "CLASS: MenuItem {{{2 "============================================================ let s:MenuItem = {} @@ -2434,6 +2465,10 @@ function! NERDTreeAddMenuItem(options) call s:MenuItem.Create(a:options) endfunction +function! NERDTreeAddKeyMap(options) + call s:KeyMap.Create(a:options) +endfunction + function! NERDTreeRender() call s:renderView() endfunction @@ -3232,6 +3267,9 @@ function! s:bindMappings() exec "nnoremap ". g:NERDTreeMapDeleteBookmark ." :call deleteBookmark()" + "bind all the user custom maps + call s:KeyMap.BindAll() + command! -buffer -nargs=1 Bookmark :call bookmarkNode('') command! -buffer -complete=customlist,s:completeBookmarks -nargs=1 RevealBookmark :call revealBookmark('') command! -buffer -complete=customlist,s:completeBookmarks -nargs=1 OpenBookmark :call openBookmark('')