summaryrefslogtreecommitdiffstats
path: root/Modules/main.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-05-04 18:08:35 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-05-04 18:08:35 (GMT)
commit1a6cb30a346ba8812d6abc77fddee636ae06ccff (patch)
tree3ba3f519e8e29fd616365fec41803795ba406bf3 /Modules/main.c
parent4c14b5de1cf372e963a4378fc6cb2bca36d24eb8 (diff)
downloadcpython-1a6cb30a346ba8812d6abc77fddee636ae06ccff.zip
cpython-1a6cb30a346ba8812d6abc77fddee636ae06ccff.tar.gz
cpython-1a6cb30a346ba8812d6abc77fddee636ae06ccff.tar.bz2
Issue #5845: Enable tab-completion in the interactive interpreter by default, thanks to a new sys.__interactivehook__.
(original patch by Éric Araujo)
Diffstat (limited to 'Modules/main.c')
-rw-r--r--Modules/main.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/Modules/main.c b/Modules/main.c
index 1d6c09a..2daefb8 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -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;
}