Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e7a9796

Browse files
committed
Patch #800697: Add readline.clear_history.
1 parent c6bb6c0 commit e7a9796

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

Doc/lib/libreadline.tex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ \section{\module{readline} ---
4242
The default filename is \file{\~{}/.history}.
4343
\end{funcdesc}
4444

45+
\begin{funcdesc}{clear_history}{}
46+
Clear the current history. (Note: this function is not available if
47+
the installed version of GNU readline doesn't support it.)
48+
\versionadded{2.4}
49+
\end{funcdesc}
50+
4551
\begin{funcdesc}{get_history_length}{}
4652
Return the desired length of the history file. Negative values imply
4753
unlimited history file size.

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Core and builtins
2929
Extension modules
3030
-----------------
3131

32+
- readline.clear_history was added.
33+
3234
- select.select() now accepts sequences for its first three arguments.
3335

3436
- cStringIO now supports the f.closed attribute.

Modules/readline.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,24 @@ PyDoc_STRVAR(doc_get_line_buffer,
412412
return the current contents of the line buffer.");
413413

414414

415+
#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
416+
417+
/* Exported function to clear the current history */
418+
419+
static PyObject *
420+
py_clear_history(PyObject *self, PyObject *noarg)
421+
{
422+
clear_history();
423+
Py_INCREF(Py_None);
424+
return Py_None;
425+
}
426+
427+
PyDoc_STRVAR(doc_clear_history,
428+
"clear_history() -> None\n\
429+
Clear the current readline history.");
430+
#endif
431+
432+
415433
/* Exported function to insert text into the line buffer */
416434

417435
static PyObject *
@@ -483,6 +501,9 @@ static struct PyMethodDef readline_methods[] =
483501
#ifdef HAVE_RL_PRE_INPUT_HOOK
484502
{"set_pre_input_hook", set_pre_input_hook,
485503
METH_VARARGS, doc_set_pre_input_hook},
504+
#endif
505+
#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
506+
{"clear_history", py_clear_history, METH_NOARGS, doc_clear_history},
486507
#endif
487508
{0, 0}
488509
};

0 commit comments

Comments
 (0)