summaryrefslogtreecommitdiff
path: root/Modules/readline.c
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-05-15 01:26:25 +0000
committerMartin Panter <vadmium+py@gmail.com>2016-05-15 01:26:25 +0000
commitf0dbf7a6abc821c77e912deae81e3a27cf334c54 (patch)
treebf28e30216f084dc637caa140960a9b14e7aef60 /Modules/readline.c
parent4dd27f0adcee901bff19c536d8442d666440a415 (diff)
downloadcpython-git-f0dbf7a6abc821c77e912deae81e3a27cf334c54.tar.gz
Issue #26870: Add readline.set_auto_history(), originally by Tyler Crompton
Diffstat (limited to 'Modules/readline.c')
-rw-r--r--Modules/readline.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/Modules/readline.c b/Modules/readline.c
index a323b69622..de1cc17d18 100644
--- a/Modules/readline.c
+++ b/Modules/readline.c
@@ -575,6 +575,24 @@ PyDoc_STRVAR(doc_add_history,
"add_history(string) -> None\n\
add an item to the history buffer");
+static int should_auto_add_history = 1;
+
+/* Enable or disable automatic history */
+
+static PyObject *
+py_set_auto_history(PyObject *self, PyObject *args)
+{
+ if (!PyArg_ParseTuple(args, "p:set_auto_history",
+ &should_auto_add_history)) {
+ return NULL;
+ }
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(doc_set_auto_history,
+"set_auto_history(enabled) -> None\n\
+Enables or disables automatic history.");
+
/* Get the tab-completion word-delimiters that readline uses */
@@ -791,6 +809,7 @@ static struct PyMethodDef readline_methods[] =
{"set_completer_delims", set_completer_delims,
METH_VARARGS, doc_set_completer_delims},
+ {"set_auto_history", py_set_auto_history, METH_VARARGS, doc_set_auto_history},
{"add_history", py_add_history, METH_VARARGS, doc_add_history},
{"remove_history_item", py_remove_history, METH_VARARGS, doc_remove_history},
{"replace_history_item", py_replace_history, METH_VARARGS, doc_replace_history},
@@ -1266,7 +1285,7 @@ call_readline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt)
/* we have a valid line */
n = strlen(p);
- if (n > 0) {
+ if (should_auto_add_history && n > 0) {
const char *line;
int length = _py_get_history_length();
if (length > 0)