Issue #5845: Enable tab-completion in the interactive interpreter by default, thanks to a new sys.__interactivehook__.

(original patch by Éric Araujo)
This commit is contained in:
Antoine Pitrou 2013-05-04 20:08:35 +02:00
parent 4c14b5de1c
commit 1a6cb30a34
9 changed files with 143 additions and 165 deletions

View file

@ -160,6 +160,32 @@ static void RunStartupFile(PyCompilerFlags *cf)
}
}
static void RunInteractiveHook(void)
{
PyObject *sys, *hook, *result;
sys = PyImport_ImportModule("sys");
if (sys == NULL)
goto error;
hook = PyObject_GetAttrString(sys, "__interactivehook__");
Py_DECREF(sys);
if (hook == NULL)
PyErr_Clear();
else {
result = PyObject_CallObject(hook, NULL);
Py_DECREF(hook);
if (result == NULL)
goto error;
else
Py_DECREF(result);
}
return;
error:
PySys_WriteStderr("Failed calling sys.__interactivehook__\n");
PyErr_Print();
PyErr_Clear();
}
static int RunModule(wchar_t *modname, int set_argv0)
{
@ -690,6 +716,7 @@ Py_Main(int argc, wchar_t **argv)
if (filename == NULL && stdin_is_interactive) {
Py_InspectFlag = 0; /* do exit on SystemExit */
RunStartupFile(&cf);
RunInteractiveHook();
}
/* XXX */
@ -755,6 +782,7 @@ Py_Main(int argc, wchar_t **argv)
if (Py_InspectFlag && stdin_is_interactive &&
(filename != NULL || command != NULL || module != NULL)) {
Py_InspectFlag = 0;
RunInteractiveHook();
/* XXX */
sts = PyRun_AnyFileFlags(stdin, "<stdin>", &cf) != 0;
}