]> granicus.if.org Git - python/commitdiff
SF patch #443759: Add Interface to readline's add_history
authorGuido van Rossum <guido@python.org>
Fri, 19 Oct 2001 01:18:43 +0000 (01:18 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 19 Oct 2001 01:18:43 +0000 (01:18 +0000)
This was submitted by Moshe, but apparently he's too busy to check it
in himself.  He wrote:

    Here is a function in GNU readline called add_history,
    which is used to manage the history list. Though Python
    uses this function internally, it does not expose it to
    the Python programmer. This patch adds direct interface
    to this function with documentation.

    This could be used by friendly modules to "seed" the
    history with commands.

Doc/lib/libreadline.tex
Modules/readline.c

index 73508453bb15a42418d6d7a1bd0c883748b5d902..3988052fef7d7dd22170ca8021f9856527abb398 100644 (file)
@@ -96,6 +96,10 @@ Set the readline word delimiters for tab-completion.
 Get the readline word delimiters for tab-completion.
 \end{funcdesc}
 
+\begin{funcdesc}{add_history}{line}
+Append a line to the history buffer, as if it was the last line typed.
+\end{funcdesc}
+
 
 \begin{seealso}
   \seemodule{rlcompleter}{Completion of Python identifiers at the
index 49839c4c2b2716efc654ac9c1a7602e7cc11a27d..aa29a61d0db3eb35d0c1bbdc9fd3b65b5af86882 100644 (file)
@@ -287,6 +287,23 @@ static char doc_set_completer_delims[] = "\
 set_completer_delims(string) -> None\n\
 set the readline word delimiters for tab-completion";
 
+static PyObject *
+py_add_history(PyObject *self, PyObject *args)
+{
+       char *line;
+
+       if(!PyArg_ParseTuple(args, "s:add_history", &line)) {
+               return NULL;
+       }
+       add_history(line);
+       Py_INCREF(Py_None);
+       return Py_None;
+}
+
+static char doc_add_history[] = "\
+add_history(string) -> None\n\
+add a line to the history buffer";
+
 
 /* get the tab-completion word-delimiters that readline uses */
 
@@ -375,6 +392,7 @@ static struct PyMethodDef readline_methods[] =
 
        {"set_completer_delims", set_completer_delims, 
         METH_VARARGS, doc_set_completer_delims},
+       {"add_history", py_add_history, METH_VARARGS, doc_add_history},
        {"get_completer_delims", get_completer_delims, 
         METH_OLDARGS, doc_get_completer_delims},