On 1/5/24 8:34 AM, Martin Buck wrote:
On Wed, Jan 03, 2024 at 10:37:46AM -0500, Chet Ramey wrote:On 1/2/24 7:21 PM, Martin Buck wrote:Thanks for your quick explanation! May I suggest a big fat warning in the docs next to the "single line, no newline" description of readline(), making library users more aware of the fact that they can't rely on always getting just a single line?Readline has always been able to return lines with embedded newlines.I guess I now understand where the confusion is coming from: For you a line with an embedded newline is a single line whereas I considered that to be two lines so far. For a newline inserted via quoted-insert your interpretation really makes more sense if you think about the user's intent, but for several lines pasted via bracketed-pasted, I prefer mine ;-)
That's fair. From readline's perspective, the `line' is what it returns, and what it returns is whatever's in the line buffer when `accept-line' is executed. A quoted newline doesn't cause accept-line to be executed, and accept-line can be bound to other keys besides newline.
That's on the application, isn't it? If I can trick an application into misbehaving just because I quote a newline, I'd report that as a bug.Well, calc just wants to read user input line by line. It doesn't know or care about quoted newlines. A newline - no matter whether quoted or not - simply ends a line. If that happens in the middle of a command, the remainder of the command is read from the next line.
Sure, that's one way to handle it.
When adding readline support to calc, I read readline's documentation and assumed that readline() returns exactly what calc expects (I just had to add back the trailing newline which readline removed but calc wanted to see). The documentation didn't give me a clue that I would have to perform line-splitting myself. After all, the function I'm calling is named readline(), not readlines() ;-)
Would you expect the line readline returns to contain a tab, even though
tab is bound to word completion? Once you have the ability to quote
certain characters and remove their special meaning to readline, you have
to be prepared for anything.
I'll add something to the documentation clarifying this.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU [email protected] http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
Description: OpenPGP digital signature
