Repository: ipython/ipython

Issue:
Multiple %%%% in tab-completion after pdb
```
[carlos@carlos ~]$ ipython
Python 3.4.3 (default, Feb 26 2015, 23:01:07) 
Type "copyright", "credits" or "license" for more information.

IPython 3.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: %pdb
Automatic pdb calling has been turned ON

In [2]: 1/0
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-2-05c9758a9c21> in <module>()
----> 1 1/0

ZeroDivisionError: division by zero
> <ipython-input-2-05c9758a9c21>(1)<module>()
----> 1 1/0

ipdb> q

In [3]: %<Tab><Tab><Tab><Tab>...
```

Each succesive tab press adds a new %.

Multiple %%%% in tab-completion after pdb
```
[carlos@carlos ~]$ ipython
Python 3.4.3 (default, Feb 26 2015, 23:01:07) 
Type "copyright", "credits" or "license" for more information.

IPython 3.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: %pdb
Automatic pdb calling has been turned ON

In [2]: 1/0
---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
<ipython-input-2-05c9758a9c21> in <module>()
----> 1 1/0

ZeroDivisionError: division by zero
> <ipython-input-2-05c9758a9c21>(1)<module>()
----> 1 1/0

ipdb> q

In [3]: %<Tab><Tab><Tab><Tab>...
```

Each succesive tab press adds a new %.



Discussion:
#8090 should fix it.

Yep, now I remember having something like that my ipython initialization because of a similar thing that used to happen with rmagic (I think), a long time ago.

Yep, #2759.

Regression: this is happening again with:

```
(ins)carlos@carlos ~$ ipython --version
4.0.0
(ins)carlos@carlos ~$ python --version
Python 3.5.0
```

Should I open a new issue?

#8090 should fix it.

Yep, now I remember having something like that my ipython initialization because of a similar thing that used to happen with rmagic (I think), a long time ago.

Yep, #2759.

Regression: this is happening again with:

```
(ins)carlos@carlos ~$ ipython --version
4.0.0
(ins)carlos@carlos ~$ python --version
Python 3.5.0
```

Should I open a new issue?


Resolving patch:
diff --git a/IPython/core/debugger.py b/IPython/core/debugger.py
--- a/IPython/core/debugger.py
+++ b/IPython/core/debugger.py
@@ -282,11 +282,13 @@ def interaction(self, frame, traceback):
         while True:
             try:
                 OldPdb.interaction(self, frame, traceback)
+                break
             except KeyboardInterrupt:
                 self.shell.write('\n' + self.shell.get_exception_only())
                 break
-            else:
-                break
+            finally:
+                # Pdb sets readline delimiters, so set them back to our own
+                self.shell.readline.set_completer_delims(self.shell.readline_delims)
 
     def new_do_up(self, arg):
         OldPdb.do_up(self, arg)
@@ -308,10 +310,6 @@ def new_do_quit(self, arg):
         if hasattr(self, 'old_all_completions'):
             self.shell.Completer.all_completions=self.old_all_completions
 
-        # Pdb sets readline delimiters, so set them back to our own
-        if self.shell.readline is not None:
-            self.shell.readline.set_completer_delims(self.shell.readline_delims)
-
         return OldPdb.do_quit(self, arg)
 
     do_q = do_quit = decorate_fn_with_doc(new_do_quit, OldPdb.do_quit)


Test patch: