Hiroo_HAYASHI via RT <bug-Term-ReadLine-Gnu@rt.cpan.org> [2015-03-24 12:42:57 -0400]:
Show quoted text
I did read all of the readline doc carefully before posting the ticket.
The problem is that it is not at all clear from the entirety of the readline
doc what "moving around the history list" might mean.
One entirely reasonable interpretation of "moving around" is that when you
"move" the 'offset' pointer, it "moves" (i.e. redefines) the location at
which readline() will insert the next history line.
Why does that seem like a reasonable interpretation? Because the documentation
for the 'offset' member tells the reader that:
int offset; /* The location pointer within this array */
Given that 'offset' is "the location pointer within the array", it does not
seem foolish to interpret that to mean that adjusting the value of 'offset'
adjusts the location of the logical end of the array; hence the expectation
that a subsequent call to readline() will place the new history line after
the newly adjusted value of 'offset'.
That turns out not to be correct, no argument about that. But given the doc,
it does not seem an unreasonable interpretation.
Show quoted text>
> You overlook one point, add_history() is called after readline() in
> readline method in Term-ReadLine-Gnu (unless you disable it explicitly
> by using MinLine() method).
>
No, I didn't overlook that, I was aware of it. See below.
Show quoted text>
> The behavior is defined by Term::ReadLine.
>
Yes, and the doc for add_history() says: "Place string at the end of the
history list", but does not define what is meant by "the end of the list".
In view of the above definition of 'offset', one could reasonably assume
that it means "Place string at the position following the one specified
by 'offset'". After all, 'offset' is "the location pointer within the array".
Show quoted text>
> It is a right behavior that add_history() set the pointer to the tail of
> the list.
>
If by "pointer" you mean the 'offset' member of HISTORY_STATE struct, then
what you say above is not correct: add_history() does not touch the offset
pointer at all; it leaves it exactly as it was before the call.
What add_history() does is use the variable history_length as though it were
an offset into the pointer array, then places the new item at at that location.
Then it increments history_length. But it does not "set the pointer to the
tail of the list".
Show quoted text>
> I hope this helps you.
>
Despite the fact that we have disagreed on the clarity of the readline
documentation (which is certainly not your responsibility) I sincerely thank
you for your time in responding! I will bring this doc issue up on the
readline mailing list and not annoy you any further with it.
Thanks again,
Glenn