[Top][All Lists]

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

bracketed paste breaks in vi mode

From: Gabe 🍰 Krabbe
Subject: bracketed paste breaks in vi mode
Date: Wed, 21 Mar 2018 19:53:56 +0000

Hi -

When bracketed paste is on, pasting leaves the commandline in movement
mode, with a 200 prefix.

This is the issue mentioned e.g. in

Trivial patch attached.


## To reproduce

In a suitable terminal (e.g. xterm):

$ set -o vi
$ bind 'set enable-bracketed-paste on'

Select the word "anything", middle-click, display is:
(arg: 200) anything

Expected display:
$ anything

## Root cause:

The delivered sequence is \033[200~anything\033[201~

The leader \033[200~ correctly triggers the bracketed paste: kill.c:698,

That function consumes input up to and including the trailer, and returns
the (net) number of characters pasted, which is >=0.

*** Possible fix 1: Return zero here.

The initial \033 sets "got_subseq" to true for the entire prefix, so the
positive return gets interpreted by _rl_subseq_result (readline.c:1017) as
"no match", in ll. 1072:
    else if (r && got_subseq)
        /* OK, back up the chain. */

This backtracking should not happen.

*** Possible fix 2: Change the two "if (r && ...)" conditions in
_rl_subseq_result function to explicitly test for r == -1

Emacs mode is not impacted, because there is no matching prefix
subsequence, so "got_subseq" is zero.

For completeness: The "arg: 200" is the result of interpreting \033 as
movement mode, skipping the bracket as unbound, parsing the 2 and following
"0" digits from vi_arg_digit and grabbing the two zeroes.
The tilde that completed the sequence does not get returned to the input
buffer; it is read into "newkey" when the second zero has been read
        newkey = _rl_subseq_getchar (key);
        if (newkey < 0)
            _rl_abort_internal ();
            return -1;

        r = _rl_dispatch_subseq (newkey, _rl_dispatching_keymap, got_subseq
|| map[ANYOTHERKEY].function);
        return _rl_subseq_result (r, map, key, got_subseq);

This is the correct behaviour, the problem requires one of the above two
fixes. Patch implements option 1.

Do not think by infection, catching an opinion like a cold.

Attachment: 0001-Fix-bracketed-paste-for-vi-mode.patch
Description: Text Data

reply via email to

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