--- Python-2.3.4/Modules/readline.c 2003-11-13 02:42:13.000000000 -0500 +++ Python-2.3.4-patched/Modules/readline.c 2007-03-28 08:57:00.000000000 -0400 @@ -56,7 +56,6 @@ "parse_and_bind(string) -> None\n\ Parse and execute single line of a readline init file."); - /* Exported function to parse a readline init file */ static PyObject * @@ -156,6 +155,19 @@ return the maximum number of items that will be written to\n\ the history file."); +/* redraw prompt on new line */ + +static PyObject* +on_new_line(PyObject *self, PyObject *noarg) +{ + rl_on_new_line(); + return Py_None; +} + +PyDoc_STRVAR(doc_on_new_line, +"on_new_line() -> None\n\ +redraws the prompt after a newline\n"); + /* Generic hook function setter */ @@ -197,6 +209,9 @@ static PyObject *startup_hook = NULL; static PyThreadState *startup_hook_tstate = NULL; +static PyObject *custom_hook = NULL; +static PyThreadState *custom_hook_tstate = NULL; + #ifdef HAVE_RL_PRE_INPUT_HOOK static PyObject *pre_input_hook = NULL; static PyThreadState *pre_input_hook_tstate = NULL; @@ -230,12 +245,27 @@ PyDoc_STRVAR(doc_set_pre_input_hook, "set_pre_input_hook([function]) -> None\n\ Set or remove the pre_input_hook function.\n\ +This custom function can be bound to a key or keyseq using parse_and_bind().\n\ +"); + +#endif + +PyDoc_STRVAR(doc_set_custom_hook, +"set_custom_hook([function]) -> None\n\ +Set or remove the custom_hook function.\n\ The function is called with no arguments after the first prompt\n\ has been printed and just before readline starts reading input\n\ characters."); -#endif +/* Set custom hook */ + +static PyObject * +set_custom_hook(PyObject *self, PyObject *args) +{ + return set_hook("custom_hook", &custom_hook, + &custom_hook_tstate, args); +} /* Exported function to specify a word completer in Python */ @@ -484,6 +514,10 @@ {"set_pre_input_hook", set_pre_input_hook, METH_VARARGS, doc_set_pre_input_hook}, #endif + {"set_custom_hook", set_custom_hook, + METH_VARARGS, doc_set_custom_hook}, + {"on_new_line", on_new_line, + METH_NOARGS, doc_on_new_line}, {0, 0} }; @@ -531,6 +565,11 @@ } #endif +static int +on_custom_hook(int count, int key) +{ + return on_hook(custom_hook, &custom_hook_tstate); +} /* C function to call the Python completer. */ @@ -620,6 +659,9 @@ rl_completion_append_character ='\0'; #endif + /* register custom function */ + rl_add_defun("custom", (rl_command_func_t *)on_custom_hook, -1); + begidx = PyInt_FromLong(0L); endidx = PyInt_FromLong(0L); /* Initialize (allows .inputrc to override) @@ -717,7 +759,6 @@ return p; } - /* Initialize the module */ PyDoc_STRVAR(doc_module,