From: Guido van Rossum Date: Sat, 1 Mar 2003 02:14:53 +0000 (+0000) Subject: - Backported SF patch #676342: after using pdb, the readline command X-Git-Tag: v2.2.3c1~119 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e0cf01371f59fe70bc5a93eb3552a2ae3e7b0287;p=thirdparty%2FPython%2Fcpython.git - Backported SF patch #676342: after using pdb, the readline command completion was botched. --- diff --git a/Lib/cmd.py b/Lib/cmd.py index 3f88235c0b6c..ab9ca002a06d 100644 --- a/Lib/cmd.py +++ b/Lib/cmd.py @@ -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() diff --git a/Misc/NEWS b/Misc/NEWS index bd5b05ecd04a..e81e87a2f716 100644 --- 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.) diff --git a/Modules/readline.c b/Modules/readline.c index 3aa62724c1bb..4d88d13b69d9 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -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},