Work around needed. How to repeat last command in the debug console, despite there was an 'undo' ?
I have a custom script that I associate with a key shortcut. The script sends the selected commented code to the debug console and runs it. I've been using this script or equivalent since wingide 3, long time! the current script I use is this:
from __future__ import with_statement
import os.path, sys
sys.path += [
os.path.dirname(__file__),
os.path.join(os.path.dirname(__file__), 'third_party.zip'),
]
import wingapi
def comment_evaluate_sel_in_debug_probe(editor=None):
'''
Evaluate a commented selection in debug probe, do `select-more` if no selection.
Suggested key combination: `Ctrl-Alt-D`
'''
if editor is None:
editor = wingapi.gApplication.GetActiveEditor()
assert isinstance(editor, wingapi.CAPIEditor)
wingapi.gApplication.ExecuteCommand('comment-toggle')
wingapi.gApplication.ExecuteCommand('evaluate-sel-in-debug-console')
editor.ExecuteCommand('undo')
This works as intended. However, in the latest version of wingide 10, once the code is executed in the debug console, if I press the up arrow to repeat the last command the code snipped is not there. I have to select it again from the editor and run the script again.
It used to be possible to press the up arrow and get the last piece of code that run in the debug console using this script. Maybe something changed in how the debug console history works? Or is there an alternative way of doing what I want? Maybe different steps in the script that don't require an 'undo' at the end?
Comments
What OS is this on? I'm not seeing the problem if I use the above code. It successfully un-comments, evaluates in debug console, and does undo to restore the comment, and if I press up arrow in the debug console afterward then I get the same thing again and can reevaluate it. Is Debug Console definitely back at the prompt when you try up arrow?
It's in ubuntu 22.04. Yes, the console is back in the prompt. When I press up arrow, sometimes I get something else I had typed in the console before I run the comment_evaluate_sel_in_debug_probe shortcut. So the code that just run in the console is not in the history. I hypothesized that the 'undo' in the editor may undo that history in the console too.
That's odd. I just tried the above on Ubuntu 22.04 with Wing 10.0.8.2 and also didn't run into the problem. The 'undo' couldn't cause this. Do you have other scripts that might be affecting the functionality? I did inspect the code that implements history and also couldn't see any clues there for what might be going wrong. Even if it's at the 100 item history limit it should be handling that correctly, as far as I can tell so far. But clearly something is going wrong somehow...
I know what's going on. If I select a large section of commented text and run this script, it sends it to the debug console and runs it but disappears from the history. If the section of selected text is smaller then it runs it in the debug console and remembers it in the history. I think I had already run into this issue long time ago but I had forgotten about it. So I think it's a limitation on how big a section of code run on the debugger console can be remembered in the history.
Oh, that makes sense. Beyond a certain size we don't actually post the text to the console, just cause it to be executed and show the results, and as a side effect we're not adding it to the history. We should probably change that. Thanks for pointing this out!