-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
readline documentation needs work #51202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The documentation for the readline module is a bit too minimal.
The latter is a confusing API in the underlying readline library and (If readline were a new addition to the stdlib I'd prefer to fix the |
It is history_base-based, not 1-based. The history_base changes when the history is stifled and old entries "drop off" the list. |
To be zero-based, get_history_item would need to look like: diff --git a/rl/readline.c b/rl/readline.c
index 33e9905..800bc00 100644
--- a/rl/readline.c
+++ b/rl/readline.c
@@ -559,7 +559,7 @@ get_history_item(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i:index", &idx))
return NULL;
- if ((hist_ent = history_get(idx)))
+ if ((hist_ent = history_get(history_base + idx)))
return PyString_FromString(hist_ent->line);
else {
Py_RETURN_NONE; |
On Tue, Mar 9, 2010 at 4:24 PM, stefanholek <report@bugs.python.org> wrote:
Did you test this with libedit? |
Changing get_history_item to be 0-based would be a backward incompatible change. The point of my report is that the documentation of the readline documentation should mention how the APIs actually behave, you currently have to hunt down that information in the documentation from libreadline. Stefan's message does point to a potentional issue though: history_base is not exposed to python code, and hence Python code cannot use the correct offset. I don't understand the documentation for history_get in that same document though, it says "get the item at |
I have read the readline source code, and it does mean just that. :-) Anyway, this does not really apply to the stdlib because unless someone implements 'stifle_history' and friends 'history_base' is going to be 1 at all times. |
I would like to revive this issue. From the discussion, it seems to me that the following changes in the Python Library documentation would make sense:
I have the following additional comments:
Andy |
This patch addresses the following points: 1: Moved add_history() into new “History file” section with related functions. 2: Documented that remove_ and replace_history_item() are zero-based. 3: Documented that get_history_item() is one-based. 4: Listed the main underlying Readline function or variable that each Python function accesses. In many cases it should be fairly obvious because the name is essentially the same, but not always. I added them all for consistency. 5: Added six new sections to group functions: Init file, Line buffer, History file, History list, Startup hooks, and Completer. 7: Clarify that the parse_and_bind() line comes directly from the string argument, not a file. 8: Changed “command line” to “line buffer”. 9: read_init_file() also executes the bindings it reads; it does not return anything. 10: read_history_file() appends to the history list, contrary to what Andy suggested. 11: write_history_file() overwrites any existing file, and writes the history list 12: clear_history() is conditionally compiled in 13: Combined get_ and set_history_length() entries 14: Differentiated lines in the history file from history list items, which can be multi-line if an item includes a line break. 15: Added brief description of word completion in the new section. Entry get_completion_type() refers to the rl_completion_type variable, so it should be refer back to the Gnu documentation. Referred beginning and ending indexes to the corresponding callback arguments (these are affected by bpo-16182). Suggested that the word delimiters determine the word completion scope. 16: Whether libedit (Editline) is used or not really only depends on the -lreadline library at run time (out of Python’s hands). I clarified that its detection is what is implemented on OS X. See also bpo-13501 for expanding this support. Another change: 17: Expanded information on setting up the completion word delimiters for a custom completer, to address bpo-10796. Not addressed in my patch: 6: Init file information. May be better to just refer to the Gnu documentation <https://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC1\> and Editline documentation (does this exist?). 8: I do not know what “the last filename used” means for read_init_file(). It passes a null pointer as the filename in this case. I suspect the answer may actually be it uses the INPUTRC config file instead. 12: I do not know what Readline version clear_history() is available in. Anyway, this might vary between Gnu and Editline implementations. |
Looks good to me. I left a comment on Rietveld. |
Here is a modified patch. Does the new wording for clear_history() clarify things for you Berker? In theory that function could be included or omitted for both the Gnu Readline and Editline cases. |
Here is v3 which adds “. . . in the underlying library” for all the function and variable references. |
readline-doc.v3.patch looks good to me. |
New changeset 6137c46cb8df by Martin Panter in branch '2.7': New changeset b1acd6cf15b6 by Martin Panter in branch '3.5': New changeset 856d50130154 by Martin Panter in branch 'default': |
Thanks for the reviews. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: