Allow use of function references as callbacks (#1067)

This commit is contained in:
Alejandro Sanchez
2019-12-15 02:25:17 +01:00
committed by Phil Runninger
parent 82b1649f2e
commit a7886fb6c4
6 changed files with 19 additions and 7 deletions

View File

@@ -66,7 +66,7 @@ endfunction
"FUNCTION: KeyMap.invoke() {{{1
"Call the KeyMaps callback function
function! s:KeyMap.invoke(...)
let Callback = function(self.callback)
let Callback = type(self.callback) == v:t_func ? self.callback : function(self.callback)
if a:0
call Callback(a:1)
else

View File

@@ -79,7 +79,7 @@ endfunction
"specified
function! s:MenuItem.enabled()
if self.isActiveCallback != -1
return {self.isActiveCallback}()
return type(self.isActiveCallback) == v:t_func ? self.isActiveCallback() : {self.isActiveCallback}()
endif
return 1
endfunction
@@ -94,7 +94,11 @@ function! s:MenuItem.execute()
call mc.showMenu()
else
if self.callback != -1
call {self.callback}()
if type(self.callback) == v:t_func
call self.callback()
else
call {self.callback}()
endif
endif
endif
endfunction

View File

@@ -14,8 +14,9 @@ endfunction
function! s:Notifier.NotifyListeners(event, path, nerdtree, params)
let event = g:NERDTreeEvent.New(a:nerdtree, a:path, a:event, a:params)
for listener in s:Notifier.GetListenersForEvent(a:event)
call {listener}(event)
for Listener in s:Notifier.GetListenersForEvent(a:event)
let Callback = type(Listener) == v:t_func ? Listener : function(Listener)
call Callback(event)
endfor
endfunction

View File

@@ -500,8 +500,9 @@ function! s:Path.ignore(nerdtree)
endif
endfor
for callback in g:NERDTree.PathFilters()
if {callback}({'path': self, 'nerdtree': a:nerdtree})
for Callback in g:NERDTree.PathFilters()
let Callback = type(Callback) == v:t_func ? Callback : function(Callback)
if Callback({'path': self, 'nerdtree': a:nerdtree})
return 1
endif
endfor