Commit 6d3e624c authored by Skip Montanaro's avatar Skip Montanaro

Add get_history_item and replace_history_item functions to the readline

module.  Closes patch #675551.  My apologies to Michal Vitecek for taking so
long to process this.
parent 594a8f64
...@@ -71,6 +71,16 @@ Return the current contents of history item at \var{index}. ...@@ -71,6 +71,16 @@ Return the current contents of history item at \var{index}.
\versionadded{2.3} \versionadded{2.3}
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{remove_history_item}{pos}
Remove history item specified by its position from the history.
\versionadded{2.4}
\end{funcdesc}
\begin{funcdesc}{replace_history_item}{pos, line}
Replace history item specified by its position with the given line.
\versionadded{2.4}
\end{funcdesc}
\begin{funcdesc}{redisplay}{} \begin{funcdesc}{redisplay}{}
Change what's displayed on the screen to reflect the current contents Change what's displayed on the screen to reflect the current contents
of the line buffer. \versionadded{2.3} of the line buffer. \versionadded{2.3}
...@@ -127,7 +137,6 @@ Get the readline word delimiters for tab-completion. ...@@ -127,7 +137,6 @@ Get the readline word delimiters for tab-completion.
Append a line to the history buffer, as if it was the last line typed. Append a line to the history buffer, as if it was the last line typed.
\end{funcdesc} \end{funcdesc}
\begin{seealso} \begin{seealso}
\seemodule{rlcompleter}{Completion of Python identifiers at the \seemodule{rlcompleter}{Completion of Python identifiers at the
interactive prompt.} interactive prompt.}
......
...@@ -44,9 +44,12 @@ Extension modules ...@@ -44,9 +44,12 @@ Extension modules
Library Library
------- -------
- patch #675551: Add get_history_item and replace_history_item functions
to the readline module.
- bug #989672: pdb.doc and the help messages for the help_d and help_u methods - bug #989672: pdb.doc and the help messages for the help_d and help_u methods
of the pdb.Pdb class gives have been corrected. d(own) goes to a newer frame, of the pdb.Pdb class gives have been corrected. d(own) goes to a newer
u(p) to an older frame, not the other way around. frame, u(p) to an older frame, not the other way around.
- bug #990669: os.path.realpath() will resolve symlinks before normalizing the - bug #990669: os.path.realpath() will resolve symlinks before normalizing the
path, as normalizing the path may alter the meaning of the path if it path, as normalizing the path may alter the meaning of the path if it
...@@ -82,6 +85,9 @@ Build ...@@ -82,6 +85,9 @@ Build
- The --with-tsc flag to configure to enable VM profiling with the - The --with-tsc flag to configure to enable VM profiling with the
processor's timestamp counter now works on PPC platforms. processor's timestamp counter now works on PPC platforms.
- patch #1006629: Define _XOPEN_SOURCE to 500 on Solaris 8/9 to match
GCC's definition and avoid redefinition warnings.
C API C API
----- -----
......
...@@ -294,6 +294,71 @@ PyDoc_STRVAR(doc_set_completer_delims, ...@@ -294,6 +294,71 @@ PyDoc_STRVAR(doc_set_completer_delims,
"set_completer_delims(string) -> None\n\ "set_completer_delims(string) -> None\n\
set the readline word delimiters for tab-completion"); set the readline word delimiters for tab-completion");
static PyObject *
py_remove_history(PyObject *self, PyObject *args)
{
int entry_number;
HIST_ENTRY *entry;
if (!PyArg_ParseTuple(args, "i:remove_history", &entry_number))
return NULL;
entry = remove_history(entry_number);
if (!entry) {
char buf[80];
PyOS_snprintf(buf, sizeof(buf),
"No history item at position %i",
entry_number);
PyErr_SetString(PyExc_ValueError, buf);
return NULL;
}
/* free memory allocated for the history entry */
if (entry->line)
free(entry->line);
if (entry->data)
free(entry->data);
free(entry);
Py_INCREF(Py_None);
return Py_None;
}
PyDoc_STRVAR(doc_remove_history,
"remove_history(pos) -> None\n\
remove history item given by its position");
static PyObject *
py_replace_history(PyObject *self, PyObject *args)
{
int entry_number;
char *line;
HIST_ENTRY *old_entry;
if (!PyArg_ParseTuple(args, "is:replace_history", &entry_number, &line)) {
return NULL;
}
old_entry = replace_history_entry(entry_number, line, (void *)NULL);
if (!old_entry) {
char buf[80];
PyOS_snprintf(buf, sizeof(buf),
"No history item at position %i",
entry_number);
PyErr_SetString(PyExc_ValueError, buf);
return NULL;
}
/* free memory allocated for the old history entry */
if (old_entry->line)
free(old_entry->line);
if (old_entry->data)
free(old_entry->data);
free(old_entry);
Py_INCREF(Py_None);
return Py_None;
}
PyDoc_STRVAR(doc_replace_history,
"replace_history(pos, line) -> None\n\
replaces history item given by its position with contents of line");
/* Add a line to the history buffer */ /* Add a line to the history buffer */
...@@ -493,6 +558,8 @@ static struct PyMethodDef readline_methods[] = ...@@ -493,6 +558,8 @@ static struct PyMethodDef readline_methods[] =
{"set_completer_delims", set_completer_delims, {"set_completer_delims", set_completer_delims,
METH_VARARGS, doc_set_completer_delims}, METH_VARARGS, doc_set_completer_delims},
{"add_history", py_add_history, METH_VARARGS, doc_add_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},
{"get_completer_delims", get_completer_delims, {"get_completer_delims", get_completer_delims,
METH_NOARGS, doc_get_completer_delims}, METH_NOARGS, doc_get_completer_delims},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment