summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Doc/lib/libreadline.tex6
-rw-r--r--Misc/NEWS2
-rw-r--r--Modules/readline.c21
3 files changed, 29 insertions, 0 deletions
diff --git a/Doc/lib/libreadline.tex b/Doc/lib/libreadline.tex
index d428594..17b48c5 100644
--- a/Doc/lib/libreadline.tex
+++ b/Doc/lib/libreadline.tex
@@ -42,6 +42,12 @@ Save a readline history file.
The default filename is \file{\~{}/.history}.
\end{funcdesc}
+\begin{funcdesc}{clear_history}{}
+Clear the current history. (Note: this function is not available if
+the installed version of GNU readline doesn't support it.)
+\versionadded{2.4}
+\end{funcdesc}
+
\begin{funcdesc}{get_history_length}{}
Return the desired length of the history file. Negative values imply
unlimited history file size.
diff --git a/Misc/NEWS b/Misc/NEWS
index 2f0aec8..9bfd738 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -29,6 +29,8 @@ Core and builtins
Extension modules
-----------------
+- readline.clear_history was added.
+
- select.select() now accepts sequences for its first three arguments.
- cStringIO now supports the f.closed attribute.
diff --git a/Modules/readline.c b/Modules/readline.c
index 64935c6..5053d1c 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -412,6 +412,24 @@ PyDoc_STRVAR(doc_get_line_buffer,
return the current contents of the line buffer.");
+#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+
+/* Exported function to clear the current history */
+
+static PyObject *
+py_clear_history(PyObject *self, PyObject *noarg)
+{
+ clear_history();
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+PyDoc_STRVAR(doc_clear_history,
+"clear_history() -> None\n\
+Clear the current readline history.");
+#endif
+
+
/* Exported function to insert text into the line buffer */
static PyObject *
@@ -484,6 +502,9 @@ static struct PyMethodDef readline_methods[] =
{"set_pre_input_hook", set_pre_input_hook,
METH_VARARGS, doc_set_pre_input_hook},
#endif
+#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
+ {"clear_history", py_clear_history, METH_NOARGS, doc_clear_history},
+#endif
{0, 0}
};