Repository: spyder-ide/spyder

Issue:
Suppress ipdb output during debug
Is this the right place to make a feature request in spyder ide to suppress the source code echo while using ipdb (thank you for making spyder an awesome ide)?  

when i am using spyder to debug the ipdb prompt echos the source code (and a few lines below and above) please let me add a  way to suppress this source code echo.  

I am a python tutor and i really like to use sypder and ipdb to show new programmers how each line of code changes the variable values and the output of some simple loop or if statement.

Do i need to make a feature request for ipdb?

other people on stackoverflow have made this request and i agree with them:

https://stackoverflow.com/questions/44308115/suppressing-ipdb-output-in-spyder-ipython-interpreter

https://stackoverflow.com/questions/51703320/python-spyder-is-there-a-way-to-suppress-the-position-output-during-debugging?rq=1


Discussion:
Something like this in the appropriate spot might work:

```Python
ipdb.set_trace(context=0)
```


Nope that doesn't work.  IPython debugger doesn't allow zero context.  

I can get it down to one line though by change a couple line in spydercustomize.py:

~line 387 change to:
```python
@monkeypatch_method(pdb.Pdb, 'Pdb')
def __init__(self, completekey='tab', stdin=None, stdout=None,
             skip=None, nosigint=False, context=5):
    self._old_Pdb___init__(context=context)
```
~line 682 in the debugfile function change to:
```python
debugger = pdb.Pdb(context=1)
```



thank you for the information about ipython debugger, should i make a feature request in ipython (or ipython debugger)?
This is the file that would need to be changed:
https://github.com/ipython/ipython/blob/master/IPython/core/debugger.py

I checked the line return logic and it returns an empty list with a context of 0, but that might break some things further down the line. 

I don't think many people would want 0 context other than Spyder users.

@lazy2late, they will be removed in Spyder 4. For now, there's nothing we can do about it, sorry.
thank you very much
The echo is created in spydercustomize.py by `self.print_stack_entry(self.stack[self.curindex])`. I personally like it but there could be an option to remove the echo.
@impact27, thanks for finding the source of the problem. I think we should remove that line and let users press `ll` or `list` on the debugger to find the current location they are placed in.

@bcolsen?
I disagree, my eyes have to travel much more if I have to refer to the editor each time I make a step.
I don't use debug that much(But I might use it more with all these great improvements :+1: ) but I can see both sides. 

I think we should definitely have them as an option. Maybe off by default though? The only thing I have against them is it just makes me have to go back further in the console to find the problem I was having.  

Could we have the lines displayed if the commands are entered into the console and not if hotkeys or the buttons are used?
We can do hidden execution to send an enable / disable command with the comms.
How about: no option, echo if typed in the console, and don't echo if using the buttons?

Resolving patch:
diff --git a/spyder/plugins/editor/plugin.py b/spyder/plugins/editor/plugin.py
--- a/spyder/plugins/editor/plugin.py
+++ b/spyder/plugins/editor/plugin.py
@@ -2334,7 +2334,7 @@ def clear_breakpoint(self, filename, lineno):
     def debug_command(self, command):
         """Debug actions"""
         self.switch_to_plugin()
-        self.main.ipyconsole.pdb_execute(command)
+        self.main.ipyconsole.pdb_execute(command, hidden=True, echo_code=False)
         focus_widget = self.main.ipyconsole.get_focus_widget()
         if focus_widget:
             focus_widget.setFocus()
diff --git a/spyder/plugins/ipythonconsole/plugin.py b/spyder/plugins/ipythonconsole/plugin.py
--- a/spyder/plugins/ipythonconsole/plugin.py
+++ b/spyder/plugins/ipythonconsole/plugin.py
@@ -576,12 +576,13 @@ def execute_code(self, lines, current_client=True, clear_variables=False):
             self.activateWindow()
             self.get_current_client().get_control().setFocus()
 
-    def pdb_execute(self, line, hidden=False):
+    def pdb_execute(self, line, hidden=False, echo_code=False):
         sw = self.get_current_shellwidget()
         if sw is not None:
             # Needed to handle an error when kernel_client is None.
             # See spyder-ide/spyder#7578.
             try:
+                sw.set_pdb_echo_code(echo_code)
                 sw.pdb_execute(line, hidden)
             except AttributeError:
                 pass
diff --git a/spyder/plugins/ipythonconsole/widgets/debugging.py b/spyder/plugins/ipythonconsole/widgets/debugging.py
--- a/spyder/plugins/ipythonconsole/widgets/debugging.py
+++ b/spyder/plugins/ipythonconsole/widgets/debugging.py
@@ -110,7 +110,7 @@ def pdb_execute(self, line, hidden=False):
 
             # Print the text if it is programatically added.
             if line.strip() != self.input_buffer.strip():
-                self._append_plain_text(line)
+                self.input_buffer = line
             self._append_plain_text('\n')
             # Save history to browse it later
             self._pdb_line_num += 1
@@ -279,8 +279,13 @@ def _readline_callback(self, line):
             line = "__spy_code__ = get_ipython().run_cell('%s')" % line
             self.pdb_execute(line, hidden=True)
         else:
+            self.set_pdb_echo_code(True)
             self.pdb_execute(line)
 
+    def set_pdb_echo_code(self, state):
+        """Choose if the code should echo in the console."""
+        self.call_kernel(interrupt=True).set_pdb_echo_code(state)
+
     def _handle_input_request(self, msg):
         """Save history and add a %plot magic."""
         if self._hidden:


Test patch: