summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-05-15 01:26:25 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-05-15 01:26:25 (GMT)
commitf0dbf7a6abc821c77e912deae81e3a27cf334c54 (patch)
treebf28e30216f084dc637caa140960a9b14e7aef60 /Modules
parent4dd27f0adcee901bff19c536d8442d666440a415 (diff)
downloadcpython-f0dbf7a6abc821c77e912deae81e3a27cf334c54.zip
cpython-f0dbf7a6abc821c77e912deae81e3a27cf334c54.tar.gz
cpython-f0dbf7a6abc821c77e912deae81e3a27cf334c54.tar.bz2
Issue #26870: Add readline.set_auto_history(), originally by Tyler Crompton
Diffstat (limited to 'Modules')
-rw-r--r--Modules/readline.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/Modules/readline.c b/Modules/readline.c
index a323b69..de1cc17 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)