]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
- Backported SF patch #676342: after using pdb, the readline command
authorGuido van Rossum <guido@python.org>
Sat, 1 Mar 2003 02:14:53 +0000 (02:14 +0000)
committerGuido van Rossum <guido@python.org>
Sat, 1 Mar 2003 02:14:53 +0000 (02:14 +0000)
  completion was botched.

Lib/cmd.py
Misc/NEWS
Modules/readline.c

index 3f88235c0b6c984780e5a32ff8925e1aa65c9807..ab9ca002a06d8ab98e1d6768a36dc337df920428 100644 (file)
@@ -86,13 +86,7 @@ class Cmd:
 
         """
         self.cmdqueue = []
-        if completekey:
-            try:
-                import readline
-                readline.set_completer(self.complete)
-                readline.parse_and_bind(completekey+": complete")
-            except ImportError:
-                pass
+        self.completekey = completekey
 
     def cmdloop(self, intro=None):
         """Repeatedly issue a prompt, accept input, parse an initial prefix
@@ -143,14 +137,26 @@ class Cmd:
 
     def preloop(self):
         """Hook method executed once when the cmdloop() method is called."""
-        pass
+        if self.completekey:
+            try:
+                import readline
+                self.old_completer = readline.get_completer()
+                readline.set_completer(self.complete)
+                readline.parse_and_bind(self.completekey+": complete")
+            except ImportError:
+                pass
 
     def postloop(self):
         """Hook method executed once when the cmdloop() method is about to
         return.
 
         """
-        pass
+        if self.completekey:
+            try:
+                import readline
+                readline.set_completer(self.old_completer)
+            except ImportError:
+                pass
 
     def parseline(self, line):
         line = line.strip()
index bd5b05ecd04ade039860fbdcaec07e43972a8499..e81e87a2f716daaa5d5df5306df7c0e28fd8c1ab 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -2,6 +2,9 @@ What's New in Python 2.2.3 ?
 Release date: XX-XXX-2003
 ============================
 
+- Backported SF patch #676342: after using pdb, the readline command
+  completion was botched.
+
 - Fix problem building on OSF1 because the compiler only accepted
   preprocessor directives that start in column 1.  (SF bug #691793.)
 
index 3aa62724c1bbd844c78b53b4d8c8979f255176ce..4d88d13b69d9b6d33fe63a3350b00bde70fac339 100644 (file)
@@ -332,6 +332,23 @@ for state in 0, 1, 2, ..., until it returns a non-string.\n\
 It should return the next possible completion starting with 'text'.\
 ";
 
+static PyObject *
+get_completer(PyObject *self, PyObject *args)
+{
+       if (completer == NULL) {
+               Py_INCREF(Py_None);
+               return Py_None;
+       }
+       Py_INCREF(completer);
+       return completer;
+}
+
+static char doc_get_completer[] = "\
+get_completer() -> function\n\
+\n\
+Returns current completer function.\
+";
+
 /* Exported function to read the current line buffer */
 
 static PyObject *
@@ -385,6 +402,7 @@ static struct PyMethodDef readline_methods[] =
        {"get_history_length", get_history_length, 
         METH_VARARGS, get_history_length_doc},
        {"set_completer", set_completer, METH_VARARGS, doc_set_completer},
+       {"get_completer", get_completer, METH_VARARGS, doc_get_completer},
        {"get_begidx", get_begidx, METH_OLDARGS, doc_get_begidx},
        {"get_endidx", get_endidx, METH_OLDARGS, doc_get_endidx},