Skip to content

Commit 8f7b706

Browse files
committed
Merge pull request #193 from benjifisher/master
Allow for persistent code evaluation in the watch window.
2 parents 90ac5e5 + d06d42e commit 8f7b706

4 files changed

Lines changed: 44 additions & 9 deletions

File tree

doc/Vdebug.txt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -742,19 +742,25 @@ of evaluating expressions: you can either write them yourself
742742
the source window.
743743

744744
On evaluating an expression, the result is shown in the watch window. To return
745-
back to the context view, press <F11> (default).
745+
back to the context view, press <F11> (default). Use |VdebugTrace| to show the
746+
result in a separate window instead.
746747

747748
------------------------------------------------------------------------------
748-
4.5.1 Evaluating any expression *VdebugEvalExpression*
749+
4.5.1 Evaluating any expression *:VdebugEval!* *VdebugEvalExpression*
749750

750751
To evaluate an expression, use the command :VdebugEval: >
751752
:VdebugEval <code>
752753
<
753-
754-
The result is shown on the watch window. E.g: >
755-
:VdebugEval $x + 2
754+
The result is shown in the watch window. By default, when you run code and the
755+
watch window refreshes, it will return to the context view. If you want to
756+
change the default behavior, so that your expression is re-evaluated and shown
757+
in the watch window after running code, then use :VdebugEval!: >
758+
:VdebugEval! $x + 2
759+
<
760+
To return to the default behavior of the watch window, use :VdebugEval! with
761+
no argument: >
762+
:VdebugEval!
756763
<
757-
758764
------------------------------------------------------------------------------
759765
4.5.2 Evaluating highlighted expressions *VdebugEvalHighlighted*
760766

@@ -779,7 +785,8 @@ request for the history: https://github.com/joonty/vdebug/pull/178.
779785
If you want to track an expression (any piece of code that can be evaluated)
780786
or clearly see how a single variable changes through your code's execution,
781787
you can trace it. At each point that the debugger stops in your code the
782-
expression will be re-evaluated and displayed in the trace window.
788+
expression will be re-evaluated and displayed in the trace window. This is
789+
similar to using |:VdebugEval!| but preserves the default watch window.
783790

784791
To use this feature, when you're connected to the debugger use the command
785792
:VdebugTrace: >

plugin/python/start_vdebug.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ def eval_under_cursor(self):
128128
except Exception, e:
129129
self.handle_exception(e)
130130

131+
def save_eval(self,args):
132+
"""Save a code snippet for later display in the watch window.
133+
"""
134+
try:
135+
return self.runner.save_code(args)
136+
except Exception as e:
137+
self.handle_exception(e)
138+
131139
def toggle_breakpoint_window(self):
132140
"""Open or close the breakpoint window.
133141
"""

plugin/python/vdebug/runner.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def __init__(self):
2222
self.breakpoints = vdebug.breakpoint.Store()
2323
self.keymapper = vdebug.util.Keymapper()
2424
self.ui = vdebug.ui.vimui.Ui(self.breakpoints)
25+
self.saved_code = ''
2526

2627
def open(self):
2728
""" Open the connection and debugging vdebug.ui.
@@ -87,6 +88,12 @@ def set_features(self):
8788
error_str = "Failed to set feature %s: %s" %(name,str(e.args[0]))
8889
self.ui.error(error_str)
8990

91+
def save_code(self,code):
92+
"""Save a code snippet for later display in the watch window.
93+
"""
94+
self.saved_code = code
95+
return code
96+
9097
def refresh(self,status):
9198
"""The main action performed after a deubugger step.
9299
@@ -121,7 +128,10 @@ def refresh(self,status):
121128
self.cur_file,\
122129
self.cur_lineno)
123130

124-
self.get_context(0)
131+
if self.saved_code != '':
132+
self.eval(self.saved_code)
133+
else:
134+
self.get_context(0)
125135

126136
def get_context(self,context_id = 0):
127137
self.ui.watchwin.clean()

plugin/vdebug.vim

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ command! -nargs=? -complete=customlist,s:BreakpointTypes Breakpoint python debug
115115
command! VdebugStart python debugger.run()
116116
command! -nargs=? BreakpointRemove python debugger.remove_breakpoint(<q-args>)
117117
command! BreakpointWindow python debugger.toggle_breakpoint_window()
118-
command! -nargs=? VdebugEval python debugger.handle_eval(<q-args>)
118+
command! -nargs=? -bang VdebugEval call s:HandleEval('<bang>', <q-args>)
119119
command! -nargs=+ -complete=customlist,s:OptionNames VdebugOpt python debugger.handle_opt(<f-args>)
120120
command! -nargs=? VdebugTrace python debugger.handle_trace(<q-args>)
121121

@@ -146,6 +146,16 @@ function! s:BreakpointTypes(A,L,P)
146146
endif
147147
endfunction
148148

149+
function! s:HandleEval(bang,code)
150+
let code = escape(a:code,'"')
151+
if strlen(a:bang)
152+
execute 'python debugger.save_eval("'.code.'")'
153+
endif
154+
if strlen(a:code)
155+
execute 'python debugger.handle_eval("'.code.'")'
156+
endif
157+
endfunction
158+
149159
" Reload options dictionary, by merging with default options.
150160
"
151161
" This should be called if you want to update the options after vdebug has

0 commit comments

Comments
 (0)