[Python-Dev] Re: extending readline functionality (now with patch) (original) (raw)
Michal Vitecek fuf@mageo.cz
Mon, 27 Jan 2003 17:09:47 +0100
- Previous message: [Python-Dev] extending readline functionality (patch)
- Next message: [Python-Dev] extending readline functionality (patch)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
--zhXaljGHf11kAtnf Content-Type: text/plain; charset=us-ascii Content-Disposition: inline
and here comes the patch :)
Michal Vitecek wrote:
hello everyone,
attached is a patch against vanilla 2.2.2, which adds three new functions to module readline: removehistory(pos) -- remove history entry specified by pos replacehistoryentry(pos, line) -- replace history entry specified by pos with the given line gethistorybuffersize() -- get current number of history entries the libreadline.tex is also modified.
thank you for your consideration,
-- fuf (fuf@mageo.cz)
--zhXaljGHf11kAtnf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="python-2.2.2-ext-readline.diff"
Binary files Python-2.2.2/Doc/lib/.libreadline.tex.swp and Python-2.2.2-ext-readline/Doc/lib/.libreadline.tex.swp differ diff -uNr Python-2.2.2/Doc/lib/libreadline.tex Python-2.2.2-ext-readline/Doc/lib/libreadline.tex --- Python-2.2.2/Doc/lib/libreadline.tex Fri Oct 19 03🔞43 2001 +++ Python-2.2.2-ext-readline/Doc/lib/libreadline.tex Mon Jan 27 16:41:57 2003 @@ -100,6 +100,18 @@ Append a line to the history buffer, as if it was the last line typed. \end{funcdesc}
+\begin{funcdesc}{remove_history}{pos} +Remove history entry specified by its position from the history. +\end{funcdesc} + +\begin{funcdesc}{replace_history_entry}{pos, line} +Replace history entry specified by its position with the given line. +\end{funcdesc} + +\begin{funcdesc}{get_history_buffer_length}{} +Get number of history entries. +\end{funcdesc} +
\begin{seealso}
\seemodule{rlcompleter}{Completion of Python identifiers at the
Binary files Python-2.2.2/Modules/.readline.c.swp and Python-2.2.2-ext-readline/Modules/.readline.c.swp differ
diff -uNr Python-2.2.2/Modules/readline.c Python-2.2.2-ext-readline/Modules/readline.c
--- Python-2.2.2/Modules/readline.c Sun Oct 6 07:43:47 2002
+++ Python-2.2.2-ext-readline/Modules/readline.c Mon Jan 27 16:55:55 2003
@@ -302,6 +302,85 @@
add_history(string) -> None\n
add a line to the history buffer";
+static PyObject * +py_remove_history(PyObject *self, PyObject *args) +{
int entry_number;
HIST_ENTRY *entry;
char buf[80];
if (!PyArg_ParseTuple(args, "i:remove_history", &entry_number)) {
return NULL;
}
entry = remove_history(entry_number);
if (!entry) {
PyOS_snprintf(buf, sizeof(buf),
"No history entry at position %i",
entry_number);
PyErr_SetString(PyExc_ValueError, buf);
return NULL;
}
if (entry->line)
free(entry->line);
if (entry->data)
free(entry->data);
free(entry);
Py_INCREF(Py_None);
return Py_None;
+}
+
+static char doc_remove_history[] = "
+remove_history(pos) -> None\n
+removes history entry given by its position in history";
+
+static PyObject *
+py_replace_history_entry(PyObject *self, PyObject *args)
+{
int entry_number;
char *line;
HIST_ENTRY *old_entry;
char buf[80];
if (!PyArg_ParseTuple(args, "is:replace_history_entry", &entry_number, &line)) {
return NULL;
}
old_entry = replace_history_entry(entry_number, line, (void *)NULL);
if (!old_entry) {
PyOS_snprintf(buf, sizeof(buf),
"No history entry at position %i",
entry_number);
PyErr_SetString(PyExc_ValueError, buf);
return NULL;
}
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;
+}
+
+static char doc_replace_history_entry[] = "
+replace_history_entry(pos, line) -> None\n
+replaces history entry given by its position with contents of line";
+
+static PyObject *
+py_get_history_buffer_length(PyObject *self, PyObject *args)
+{
HISTORY_STATE *history_state;
if (!PyArg_ParseTuple(args, ":get_history_buffer_length"))
return NULL;
history_state = history_get_history_state();
return Py_BuildValue("i", history_state->length);
+}
+
+static char doc_get_history_buffer_length[] = "
+get_history_buffer_length() -> length\n
+returns number of entries in the history";
/* get the tab-completion word-delimiters that readline uses */
@@ -391,8 +470,10 @@ {"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},
{"remove_history", py_remove_history, METH_VARARGS, doc_remove_history},
{"replace_history_entry", py_replace_history_entry, METH_VARARGS, doc_replace_history_entry},
{"get_history_buffer_length", py_get_history_buffer_length, METH_VARARGS, doc_get_history_buffer_length},
{"get_completer_delims", get_completer_delims, METH_OLDARGS, doc_get_completer_delims},
{"set_startup_hook", set_startup_hook, METH_VARARGS, doc_set_startup_hook},
#ifdef HAVE_RL_PRE_INPUT_HOOK
--zhXaljGHf11kAtnf--
- Previous message: [Python-Dev] extending readline functionality (patch)
- Next message: [Python-Dev] extending readline functionality (patch)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]