bug-readline
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bracketed paste causes readline() to return multiple lines


From: Chet Ramey
Subject: Re: Bracketed paste causes readline() to return multiple lines
Date: Tue, 2 Jan 2024 16:43:40 -0500
User-agent: Mozilla Thunderbird

On 1/2/24 4:28 PM, Martin Buck wrote:
Hi,

I noticed some unexpected behavior in readline v8.2 when pasting multi-line
text into an application using readline with bracketed paste mode enabled
(which defaults to enabled since v8.1, if I understand CHANGES correctly).

According to
https://tiswww.case.edu/php/chet/readline/readline.html#Basic-Behavior
readline() is supposed to return a single line of text without the trailing
newline. However, when pasting multiple lines, they are returned all at once
by readline() and without removing the newline at the end. This is different
from the pre-bracketed-paste-mode behavior where you got the multi-line text
line by line and it also contradicts the documentation.

I see how this can be confusing. The whole idea behind bracketed paste is
that everything in the pasted text is inserted into the readline line,
without any of the characters causing execution of any readline function
that might be bound to them. Think of it as if you had executed the
readline `quoted-insert' command before every character in the pasted text.

This means that the single readline `line' can contain embedded newlines,
since those were inserted without triggering a readline command like
`accept-line'.

It's always been possible to do this, even before bracketed paste, by using
quoted-insert.

So say you have text you'd like to paste into the readline line buffer:

one
two
three

with newlines after each line. If you use bracketed paste, these newlines
will become part of the line buffer, and readline() won't return the line
to its caller until you type another newline (which causes accept-line to
be executed, etc.)

Bracketed paste is all or nothing: either it's on and everything that
gets pasted is inserted into the line buffer, or it's off and every pasted
character is treated as if it had been typed at the keyboard and causes
execution of any readline function bound to it.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]