Loading ...
Sorry, an error occurred while loading the content.
 

trouble with the trick for copy/pasting wrapped lines

Expand Messages
  • Joël Riou
    Hi, There is a trouble with the « trick to make copy/paste of wrapped lines work with xterm/screen : write an extra character beyond the end of the line. »
    Message 1 of 3 , Jan 18, 2005
      Hi,

      There is a trouble with the « trick to make copy/paste of wrapped lines
      work with xterm/screen : write an extra character beyond the end of the
      line. » (see vim/src/screen.c, lines 4136-4183) : in a utf-8 encoded
      terminal, if the last character in the last column is multibyte and if
      the line is wrapped, an extra byte will printed, this byte will be the
      first byte of that multibyte character, which may confuse the terminal
      (because its input may not be well-formed UTF-8). Recent xterm versions
      reject this whereas the trick works on older versions (e.g. xterm-165).

      To reproduce the bug, launch a utf-8 encoded xterm with 80 columns,
      launch vim, :set ttyfast and edit a file whose xxd dump is :

      0000000: 2020 2020 2020 2020 2020 2020 2020 2020
      0000010: 2020 2020 2020 2020 2020 2020 2020 2020
      0000020: 2020 2020 2020 2020 2020 2020 2020 2020
      0000030: 2020 2020 2020 2020 2020 2020 2020 2020
      0000040: 2020 2020 2020 2020 2020 2020 2020 20c3 .
      0000050: a920 0a . .

      i.e. 79 spaces, a LATIN SMALL LETTER E WITH ACUTE, a space and \n.
      The string "\33[1;80H\303\251\303\33[2;1H \r\n" (note the second « \303 »)
      will be written to the terminal so that you should see a correct first line,
      but the second one may contain « [2;1H ».

      The trouble seems to stand in the following code in screen.c:4169-4178 :

      #ifdef FEAT_MBYTE
      /* When there is a multi-byte character, just output a
      * space to keep it simple. */
      if (has_mbyte && mb_off2cells(LineOffset[screen_row - 1]
      + (unsigned)Columns - 1) != 1)
      out_char(' ');
      else
      #endif
      out_char(ScreenLines[LineOffset[screen_row - 1]
      + (Columns - 1)]);

      I do not know how to correct this so that we both make wrapped-lines
      selection work in xterm and avoid outputting garbage. If you just need a
      correct output, « set nottyfast » works.

      --
      Joël Riou
    • Bram Moolenaar
      ... Very good explanation of the problem. ... The trouble is that the comment says it s checking for a multi-byte character, but the code is checking for a
      Message 2 of 3 , Jan 19, 2005
        Joël Riou wrote:

        > There is a trouble with the « trick to make copy/paste of wrapped lines
        > work with xterm/screen : write an extra character beyond the end of the
        > line. » (see vim/src/screen.c, lines 4136-4183) : in a utf-8 encoded
        > terminal, if the last character in the last column is multibyte and if
        > the line is wrapped, an extra byte will printed, this byte will be the
        > first byte of that multibyte character, which may confuse the terminal
        > (because its input may not be well-formed UTF-8). Recent xterm versions
        > reject this whereas the trick works on older versions (e.g. xterm-165).
        >
        > To reproduce the bug, launch a utf-8 encoded xterm with 80 columns,
        > launch vim, :set ttyfast and edit a file whose xxd dump is :
        >
        > 0000000: 2020 2020 2020 2020 2020 2020 2020 2020
        > 0000010: 2020 2020 2020 2020 2020 2020 2020 2020
        > 0000020: 2020 2020 2020 2020 2020 2020 2020 2020
        > 0000030: 2020 2020 2020 2020 2020 2020 2020 2020
        > 0000040: 2020 2020 2020 2020 2020 2020 2020 20c3 .
        > 0000050: a920 0a . .
        >
        > i.e. 79 spaces, a LATIN SMALL LETTER E WITH ACUTE, a space and \n.
        > The string "\33[1;80H\303\251\303\33[2;1H \r\n" (note the second « \303 »)
        > will be written to the terminal so that you should see a correct first line,
        > but the second one may contain « [2;1H ».

        Very good explanation of the problem.

        > The trouble seems to stand in the following code in screen.c:4169-4178 :
        >
        > #ifdef FEAT_MBYTE
        > /* When there is a multi-byte character, just output a
        > * space to keep it simple. */
        > if (has_mbyte && mb_off2cells(LineOffset[screen_row - 1]
        > + (unsigned)Columns - 1) != 1)
        > out_char(' ');
        > else
        > #endif
        > out_char(ScreenLines[LineOffset[screen_row - 1]
        > + (Columns - 1)]);
        >
        > I do not know how to correct this so that we both make wrapped-lines
        > selection work in xterm and avoid outputting garbage. If you just need a
        > correct output, « set nottyfast » works.

        The trouble is that the comment says it's checking for a multi-byte
        character, but the code is checking for a character that occupies two
        columns. That should be easy to fix:

        *** screen.c.orig Thu Jan 13 19:21:40 2005
        --- screen.c Wed Jan 19 11:03:00 2005
        ***************
        *** 4169,4176 ****
        #ifdef FEAT_MBYTE
        /* When there is a multi-byte character, just output a
        * space to keep it simple. */
        ! if (has_mbyte && mb_off2cells(LineOffset[screen_row - 1]
        ! + (unsigned)Columns - 1) != 1)
        out_char(' ');
        else
        #endif
        --- 4169,4176 ----
        #ifdef FEAT_MBYTE
        /* When there is a multi-byte character, just output a
        * space to keep it simple. */
        ! if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
        ! screen_row - 1] + (Columns - 1)]) > 1)
        out_char(' ');
        else
        #endif

        --
        Arthur pulls Pin out. The MONK blesses the grenade as ...
        ARTHUR: (quietly) One, two, five ...
        GALAHAD: Three, sir!
        ARTHUR: Three.
        "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
        \\\ Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html ///
      • Joël Riou
        ... It works for me. :) -- Joël Riou
        Message 3 of 3 , Jan 19, 2005
          Le mercredi 19 janvier 2005, Bram Moolenaar a écrit :
          > The trouble is that the comment says it's checking for a multi-byte
          > character, but the code is checking for a character that occupies two
          > columns. That should be easy to fix:
          >
          > [snip patch]

          It works for me. :)

          --
          Joël Riou
        Your message has been successfully submitted and would be delivered to recipients shortly.