commit f9a933991d8e6033e501603ba2ff6f3319b4f308
parent aa831e242b50f0a20ea9f86cca360e808ffa3626
Author: Martin Grenfell <martin.grenfell@gmail.com>
Date: Tue, 15 Jul 2014 18:54:57 +0100
allow plugins to override the default mappings
Diffstat:
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/doc/NERD_tree.txt b/doc/NERD_tree.txt
@@ -1060,6 +1060,9 @@ NERDTreeAddKeyMap({options}) *NERDTreeAddKeyMap()*
"callback" - the function the new mapping will be bound to
"quickhelpText" - the text that will appear in the quickhelp (see
|NERDTree-?|)
+ "override" - if 1 then this new mapping will override whatever previous
+ mapping was defined for the key/scope combo. Useful for overriding the
+ default mappings.
Additionally, a "scope" argument may be supplied. This constrains the
mapping so that it is only activated if the cursor is on a certain object.
diff --git a/lib/nerdtree/key_map.vim b/lib/nerdtree/key_map.vim
@@ -134,8 +134,14 @@ endfunction
"FUNCTION: KeyMap.Create(options) {{{1
function! s:KeyMap.Create(options)
- let newKeyMap = copy(self)
let opts = extend({'scope': 'all', 'quickhelpText': ''}, copy(a:options))
+
+ "dont override other mappings unless the 'override' option is given
+ if get(opts, 'override', 0) == 0 && !empty(s:KeyMap.FindFor(opts['key'], opts['scope']))
+ return
+ end
+
+ let newKeyMap = copy(self)
let newKeyMap.key = opts['key']
let newKeyMap.quickhelpText = opts['quickhelpText']
let newKeyMap.callback = opts['callback']