commit a052a0db65460537077c7bca768e801238fa89fa
parent 65dd1137da79a5e7fd63dcdd2356ecc44b59a1ca
Author: marty <marty@rodney.(none)>
Date: Wed, 12 Aug 2009 00:53:16 +1200
add an API to add custom key maps
Diffstat:
1 file changed, 38 insertions(+), 0 deletions(-)
diff --git 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 <silent> <buffer> ". self.key ." :call ". self.callback ."()<cr>"
+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 <silent> <buffer> ". g:NERDTreeMapDeleteBookmark ." :call <SID>deleteBookmark()<cr>"
+ "bind all the user custom maps
+ call s:KeyMap.BindAll()
+
command! -buffer -nargs=1 Bookmark :call <SID>bookmarkNode('<args>')
command! -buffer -complete=customlist,s:completeBookmarks -nargs=1 RevealBookmark :call <SID>revealBookmark('<args>')
command! -buffer -complete=customlist,s:completeBookmarks -nargs=1 OpenBookmark :call <SID>openBookmark('<args>')