From 69dab33ea3c4823d2c1645ec0ea3aabc1c93ee63 Mon Sep 17 00:00:00 2001 From: IdanArye Date: Sat, 18 Jan 2014 00:36:13 +0200 Subject: [PATCH] Added expression evaluation functionality --- autoload/vebugger/jdb.vim | 21 ++++++++++++++++++++ autoload/vebugger/std.vim | 40 ++++++++++++++++++++++++++++++++++++--- plugin/vebugger.vim | 24 ++++++++++++++++++++++- 3 files changed, 81 insertions(+), 4 deletions(-) diff --git a/autoload/vebugger/jdb.vim b/autoload/vebugger/jdb.vim index fc3031e..006eb3d 100644 --- a/autoload/vebugger/jdb.vim +++ b/autoload/vebugger/jdb.vim @@ -16,9 +16,11 @@ function! vebugger#jdb#start(entryClass,args) call l:debugger.writeLine('monitor where') call l:debugger.addReadHandler(function('s:readWhere')) + call l:debugger.addReadHandler(function('s:readEvaluatedExpressions')) call l:debugger.setWriteHandler('std','flow',function('s:writeFlow')) call l:debugger.setWriteHandler('std','breakpoints',function('s:writeBreakpoints')) + call l:debugger.setWriteHandler('std','evaluateExpressions',function('s:requestEvaluateExpression')) call l:debugger.generateWriteActionsFromTemplate() @@ -100,3 +102,22 @@ function! s:writeBreakpoints(writeAction,debugger) endif endfor endfunction + +function! s:requestEvaluateExpression(writeAction,debugger) + for l:evalAction in a:writeAction + call a:debugger.writeLine('eval '.l:evalAction.expression) + endfor +endfunction + +function! s:readEvaluatedExpressions(pipeName,line,readResult,debugger) + if 'out'==a:pipeName + let l:matches=matchlist(a:line,'\v^%(\s*%(%(%(\w|\.)+)\[\d+\] )+)? ([^=]+) \= (.*)$') + if 3) +command! -nargs=0 VBGevalWordUnderCursor call vebugger#std#eval(expand('')) + +"Shamefully stolen from http://stackoverflow.com/a/6271254/794380 +function! s:get_visual_selection() + " Why is this not a built-in Vim script function?! + let [lnum1, col1] = getpos("'<")[1:2] + let [lnum2, col2] = getpos("'>")[1:2] + let lines = getline(lnum1, lnum2) + let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)] + let lines[0] = lines[0][col1 - 1:] + return join(lines, "\n") +endfunction + +command! -range -nargs=0 VBGevalSelectedText call vebugger#std#eval(s:get_visual_selection()) + + if exists('g:vebugger_leader') if !empty(g:vebugger_leader) for s:mapping in items({ @@ -20,8 +37,13 @@ if exists('g:vebugger_leader') \'O':'VBGstepOut', \'c':'VBGcontinue', \'l':'VBGtoggleLogBuffer', - \'b':'VBGtoggleBreakpointThisLine'}) + \'b':'VBGtoggleBreakpointThisLine', + \'e':'VBGevalWordUnderCursor'}) exe 'nnoremap '.g:vebugger_leader.s:mapping[0].' :'.s:mapping[1].'' endfor + for s:mapping in items({ + \'e':'VBGevalSelectedText'}) + exe 'vnoremap '.g:vebugger_leader.s:mapping[0].' :'.s:mapping[1].'' + endfor endif endif