Add hook for pre&post user actions

This commit is contained in:
IdanArye 2015-02-28 19:37:54 +02:00
parent 4567ad166b
commit e3c069b5b6
2 changed files with 33 additions and 0 deletions

View File

@ -295,16 +295,47 @@ function! vebugger#killDebugger()
endif
endfunction
"Perform an action on the actvie debugger, and register that action
function! vebugger#userAction(action, ...)
if exists('s:debugger')
if has_key(s:debugger, a:action)
let s:debugger.lastUserAction = {
\'action': a:action,
\'args': a:000}
try
doautocmd User Vebugger_PreUserAction
catch
endtry
call call(s:debugger[a:action], a:000, s:debugger)
try
doautocmd User Vebugger_PostUserAction
catch
endtry
else
throw 'Current debugger does not support action '.a:action
endif
endif
endfunction
augroup vebugger_hooks
autocmd!
"Make a blank action hook to prevent 'No matching autocommands" warning
autocmd User Vebugger_* echo
augroup END
"Repeat the last action performed on the active debugger
function! vebugger#repeatLastUserAction()
if exists('s:debugger')
if has_key(s:debugger, 'lastUserAction')
let l:lastUserAction = s:debugger.lastUserAction
call call(s:debugger[l:lastUserAction.action], l:lastUserAction.args, s:debugger)
endif
endif
endfunction
"Write a line to the currently active debugger
function! vebugger#writeLine(line)
if exists('s:debugger')

View File

@ -1,5 +1,7 @@
command! -nargs=0 VBGrepeat call vebugger#repeatLastUserAction()
command! -nargs=1 VBGrawWrite call vebugger#userAction('writeLine', <q-args>)
command! -nargs=0 VBGkill call vebugger#killDebugger()