--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: > > remove_history(pos) -- remove history entry specified by pos > > replace_history_entry(pos, line) -- replace history entry specified > by pos with the given line > > get_history_buffer_size() -- 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:18: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--
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4