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

virtcol() subject to showbreak

Expand Messages
  • Axel Bender
    virtcol() fails to deliver the correct screen column if showbreak is set to a value other than and wrap is on, i.e. it doesn t take into account the length
    Message 1 of 8 , Jun 2, 2014
    • 0 Attachment
      virtcol() fails to deliver the correct screen column if showbreak is set to a value other than "" and wrap is on, i.e. it doesn't take into account the length of the string that showbreak is set to.

      To reproduce:

      1) Start a "bare" gvim with a text containing a long line.
      2) :set nowrap
      3) Position the cursor at the beginning of a word towards the end of the line.
      4) :echo virtcol(".")
      5) :set wrap " Make sure the cursor is in a 'wrapped' line
      6) :echo virtcol(".") " Returns the same value
      7) :set showbreak=(-->)
      8) :echo virtcol(".") " Will return a distinct value

      col(".")'s return value would not change, but it's not Unicode (UTF-8) proof...

      --
      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
      For more options, visit https://groups.google.com/d/optout.
    • Павлов Николай Алекса
      ... Hash: SHA512 ... Neither is virtcol(). In Unicode you have the following things: - - Variable-length tabs. - - Control characters which take one byte and
      Message 2 of 8 , Jun 3, 2014
      • 0 Attachment
        -----BEGIN PGP SIGNED MESSAGE-----
        Hash: SHA512



        On June 2, 2014 10:18:40 PM GMT+03:00, Axel Bender <axel.bender@...> wrote:
        >virtcol() fails to deliver the correct screen column if showbreak is
        >set to a value other than "" and wrap is on, i.e. it doesn't take into
        >account the length of the string that showbreak is set to.
        >
        >To reproduce:
        >
        >1) Start a "bare" gvim with a text containing a long line.
        >2) :set nowrap
        >3) Position the cursor at the beginning of a word towards the end of
        >the line.
        >4) :echo virtcol(".")
        >5) :set wrap " Make sure the cursor is in a 'wrapped' line
        >6) :echo virtcol(".") " Returns the same value
        >7) :set showbreak=(-->)
        >8) :echo virtcol(".") " Will return a distinct value
        >
        >col(".")'s return value would not change, but it's not Unicode (UTF-8)
        >proof...

        Neither is virtcol(). In Unicode you have the following things:

        - - Variable-length tabs.
        - - Control characters which take one byte and occupy two or four cells (depending on vim settings).
        - - Fullwidth characters that are 2 cells wide.
        - - Ambiguous width characters which are one or two cells wide depending on terminal and vim settings.
        - - Combining characters which are zero cells wide (and are sometimes considered a part of a symbol).
        - - Unprintable characters which occupy at least 6 cells (e.g. U+FFFE represented as <fffe>).

        Additionally there are

        - - Incorrect bytes that vim represents as <XX>.
        - - Different terminal encodings which may alter Unicode character representation (I have not tested how though).

        . All this affect output of virtcol(). If you want to count a number of characters you should use something different. If you need exactly display cells do not say it has something to do with Unicode. In the last case you may use col(), getline() and strdisplaywidth().
        -----BEGIN PGP SIGNATURE-----
        Version: APG v1.1.1

        iQI1BAEBCgAfBQJTjboSGBxaeVggPHp5eC52aW1AZ21haWwuY29tPgAKCRCf3UKj
        HhHSvvKPEAClwRq4OAAsuVjxZiqjfjkntq3jbai29zetIWEVS75pO4lZDYr6mHqD
        xa9+KVFNxUzKby8zh1CYQpp0+rU2dO0XW53j6lhYRKW+t2QfswPjC4TX3wECdJKv
        uuQQa2m/khnWpXV0mUizainIj3MWPVNu89/5xqcE7vyGAlq+kTl8N2h7l8933+Y0
        2GAydQit6T6c8DK5h2P/v/uZrokSSKaF7zhdwo9RxFlzpX09fmX1llkllB1TxMF3
        jvGhLlLAnrgVj8DFWabj6xCij8zchHc1vw4qRy8vVJEGllTyDSAQHyQm2rvmrrzw
        5ZuIbr/w6DgdJKwM98qH9QedPFpxVfziv7S0hGTzyknvxr5HM1Ct4ac3MilewSY/
        N/NDczDdB+OPUq7zluuvXMdASDIiNcCYQWd1uCyEcZogapjmZ1xT60FQFm+QLZ9e
        RIrnBSPsx5lJl1V6Hpm4minAPQfXEdfXovF+I6rHVjuBfBQvn/KcDt13mdriYzwQ
        jXyrNg7Ys2mdxq3exlWUcVbiBeb57eg518ihw6pvZghagFizV3BV8CB7WJwjqmME
        2I8pTmsmPL3RxbAlnP49b1K4DqqamrsiwCFQVycG2RKrLxyzNC9QbU0WUaagHuen
        473Fy3wAOk7OUzgNV3H2k7aEQpq7lYG1LsJ+LorCx73TV96X9dIhSw==
        =ONg5
        -----END PGP SIGNATURE-----

        --
        --
        You received this message from the "vim_dev" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_dev" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
        For more options, visit https://groups.google.com/d/optout.
      • Axel Bender
        I d already be happy if virtcol() would take into account the length of the showbreak string. I m otherwise prepared to work with UTF-8 characters... I
        Message 3 of 8 , Jun 4, 2014
        • 0 Attachment
          I'd already be happy if virtcol() would take into account the length of the showbreak string. I'm otherwise prepared to work with UTF-8 characters...

          I consider this a flaw (well maybe a bug?) that should be fixed.

          --
          --
          You received this message from the "vim_dev" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php

          ---
          You received this message because you are subscribed to the Google Groups "vim_dev" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
          For more options, visit https://groups.google.com/d/optout.
        • Ingo Karkat
          ... Character widths are not directly related to this, but that little incorrectness in your otherwise precise and welcome bug report shouldn t have provoked
          Message 4 of 8 , Jun 4, 2014
          • 0 Attachment
            On 04-Jun-2014 13:34 +0200, Axel Bender wrote:

            > I'd already be happy if virtcol() would take into account the length of the showbreak string. I'm otherwise prepared to work with UTF-8 characters...

            Character widths are not directly related to this, but that little
            incorrectness in your otherwise precise and welcome bug report shouldn't
            have provoked such a rant. Sorry.

            > I consider this a flaw (well maybe a bug?) that should be fixed.

            I can reproduce this issue with 7.4.264. Even worse, :set linebreak also
            affects the virtcol() value and makes it wrong (when such wrap occurs).
            So, one only gets correct values out of virtcol() with :set sbr= nolbr;
            which indeed should be fixed!

            -- regards, ingo

            --
            --
            You received this message from the "vim_dev" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php

            ---
            You received this message because you are subscribed to the Google Groups "vim_dev" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
            For more options, visit https://groups.google.com/d/optout.
          • Павлов Николай Алекса
            ... Hash: SHA512 ... I am not sure it is a bug. Most likely it is absolutely correct behavior: pretend you need to know on which virtual line of the current
            Message 5 of 8 , Jun 4, 2014
            • 0 Attachment
              -----BEGIN PGP SIGNED MESSAGE-----
              Hash: SHA512



              On June 4, 2014 3:48:42 PM GMT+03:00, Ingo Karkat <swdev@...> wrote:
              >On 04-Jun-2014 13:34 +0200, Axel Bender wrote:
              >
              >> I'd already be happy if virtcol() would take into account the length
              >of the showbreak string. I'm otherwise prepared to work with UTF-8
              >characters...
              >
              >Character widths are not directly related to this, but that little
              >incorrectness in your otherwise precise and welcome bug report
              >shouldn't
              >have provoked such a rant. Sorry.
              >
              >> I consider this a flaw (well maybe a bug?) that should be fixed.
              >
              >I can reproduce this issue with 7.4.264. Even worse, :set linebreak
              >also
              >affects the virtcol() value and makes it wrong (when such wrap occurs).
              >So, one only gets correct values out of virtcol() with :set sbr= nolbr;
              >which indeed should be fixed!

              I am not sure it is a bug. Most likely it is absolutely correct behavior: pretend you need to know on which virtual line of the current line cursor is located and on which virtual column on this virtual line. Please describe how you will solve this with current behavior of virtcol() and with proposed one.

              Discussing whether this behavior is a bug or not is pointless without showing the use-case. I know that the above task may only be solved with "bugged" virtcol(), otherwise you will have to do option parsing for yourself which is a waste of time.

              I though think that virtcol() behavior is not a bug, but documentation is incorrect (it says "the last screen position occupied by the character at that position, when the screen would be of **unlimited width**" which obviously contradicts with the current behavior: no wraps are possible on the screen with unlimited width hence these options may not apply).

              >
              >-- regards, ingo
              -----BEGIN PGP SIGNATURE-----
              Version: APG v1.1.1

              iQI1BAEBCgAfBQJTjzDRGBxaeVggPHp5eC52aW1AZ21haWwuY29tPgAKCRCf3UKj
              HhHSvg4uEAClhxgkmHRrWOvApOa70j8Zzw560RRQA6xRspJWg9UiyOEEsc2e+7O1
              3gMy2HBr3kdPz7dwtWpe3azoDPvvIQe2+cznn1HPuqxtsQfGy/bWntGbBknpNhff
              3V3AAD2DfmjU+0mu9gUs5+9NG7ROZg0PfHSgRkbfa759cD7GUG1fsVBPsbPy+aYM
              jjEV27/X61pkKsF5JgyyFpNG7pYXYrAEl9JiH0/QSuXYYjt9ptwHoEdrdwF9CFVi
              Ums+bp74pGwyOCMlVoVUImJT3MrHk6yiUFAgGBZqZsFWUsRYTvFluxWMTD6pLeJz
              +wL6WCnVxqRIZxvKFtySmZeAgRF1aRWVbFOEFz0IUjv1yhCleNWNVSdCK7FAFmvO
              Z6aSfyxTcgaKw9SEOxBtwysl8+BrmERv26zGt4Mfo6zxHLgPEV6eGA6e7wdWmy0z
              9Cb4VKl395aLvlH2BqTQdKCp5OPhYt9wiVTHtB8LVM6DIMkyGOsscbLFNRiLedfx
              SovSVnsl2jzszxeOzKtmHW5uKMrrutNS3dVilZCMs1j/qm45+b0O+KGpiMwNTNHP
              wxJYU5jpXGEjZePZ98F5nUmopRFKDmNNfiMJQCuxVCNUJN6HKA2NfTWRiVb98HQx
              F05yoz1yfjEVtkWJjt+7Tg8JXCta55BkW8QhyRTgJNQLDFNUWJOQZA==
              =5tsG
              -----END PGP SIGNATURE-----

              --
              --
              You received this message from the "vim_dev" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php

              ---
              You received this message because you are subscribed to the Google Groups "vim_dev" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
              For more options, visit https://groups.google.com/d/optout.
            • Павлов Николай Алекса
              ... Hash: SHA512 ... I have a use-case: if you need to move to some character you usually use bar motion and bar motion ignores additional characters from
              Message 6 of 8 , Jun 4, 2014
              • 0 Attachment
                -----BEGIN PGP SIGNED MESSAGE-----
                Hash: SHA512



                On June 4, 2014 6:44:34 PM GMT+03:00, "Павлов Николай Александрович" <zyx.vim@...> wrote:
                >-----BEGIN PGP SIGNED MESSAGE-----
                >Hash: SHA512
                >
                >
                >
                >On June 4, 2014 3:48:42 PM GMT+03:00, Ingo Karkat
                ><swdev@...> wrote:
                >>On 04-Jun-2014 13:34 +0200, Axel Bender wrote:
                >>
                >>> I'd already be happy if virtcol() would take into account the length
                >>of the showbreak string. I'm otherwise prepared to work with UTF-8
                >>characters...
                >>
                >>Character widths are not directly related to this, but that little
                >>incorrectness in your otherwise precise and welcome bug report
                >>shouldn't
                >>have provoked such a rant. Sorry.
                >>
                >>> I consider this a flaw (well maybe a bug?) that should be fixed.
                >>
                >>I can reproduce this issue with 7.4.264. Even worse, :set linebreak
                >>also
                >>affects the virtcol() value and makes it wrong (when such wrap
                >occurs).
                >>So, one only gets correct values out of virtcol() with :set sbr=
                >nolbr;
                >>which indeed should be fixed!
                >
                >I am not sure it is a bug. Most likely it is absolutely correct
                >behavior: pretend you need to know on which virtual line of the current
                >line cursor is located and on which virtual column on this virtual
                >line. Please describe how you will solve this with current behavior of
                >virtcol() and with proposed one.
                >
                >Discussing whether this behavior is a bug or not is pointless without
                >showing the use-case. I know that the above task may only be solved
                >with "bugged" virtcol(), otherwise you will have to do option parsing
                >for yourself which is a waste of time.

                I have a use-case: if you need to move to some character you usually use bar motion and bar motion ignores additional characters from &showbreak.

                Thus I would suggest to patch bar motion to also take breaks into account like virtcol() does.

                >
                >I though think that virtcol() behavior is not a bug, but documentation
                >is incorrect (it says "the last screen position occupied by the
                >character at that position, when the screen would be of **unlimited
                >width**" which obviously contradicts with the current behavior: no
                >wraps are possible on the screen with unlimited width hence these
                >options may not apply).
                >
                >>
                >>-- regards, ingo
                >-----BEGIN PGP SIGNATURE-----
                >Version: APG v1.1.1
                >
                >iQI1BAEBCgAfBQJTjzDRGBxaeVggPHp5eC52aW1AZ21haWwuY29tPgAKCRCf3UKj
                >HhHSvg4uEAClhxgkmHRrWOvApOa70j8Zzw560RRQA6xRspJWg9UiyOEEsc2e+7O1
                >3gMy2HBr3kdPz7dwtWpe3azoDPvvIQe2+cznn1HPuqxtsQfGy/bWntGbBknpNhff
                >3V3AAD2DfmjU+0mu9gUs5+9NG7ROZg0PfHSgRkbfa759cD7GUG1fsVBPsbPy+aYM
                >jjEV27/X61pkKsF5JgyyFpNG7pYXYrAEl9JiH0/QSuXYYjt9ptwHoEdrdwF9CFVi
                >Ums+bp74pGwyOCMlVoVUImJT3MrHk6yiUFAgGBZqZsFWUsRYTvFluxWMTD6pLeJz
                >+wL6WCnVxqRIZxvKFtySmZeAgRF1aRWVbFOEFz0IUjv1yhCleNWNVSdCK7FAFmvO
                >Z6aSfyxTcgaKw9SEOxBtwysl8+BrmERv26zGt4Mfo6zxHLgPEV6eGA6e7wdWmy0z
                >9Cb4VKl395aLvlH2BqTQdKCp5OPhYt9wiVTHtB8LVM6DIMkyGOsscbLFNRiLedfx
                >SovSVnsl2jzszxeOzKtmHW5uKMrrutNS3dVilZCMs1j/qm45+b0O+KGpiMwNTNHP
                >wxJYU5jpXGEjZePZ98F5nUmopRFKDmNNfiMJQCuxVCNUJN6HKA2NfTWRiVb98HQx
                >F05yoz1yfjEVtkWJjt+7Tg8JXCta55BkW8QhyRTgJNQLDFNUWJOQZA==
                >=5tsG
                >-----END PGP SIGNATURE-----
                -----BEGIN PGP SIGNATURE-----
                Version: APG v1.1.1

                iQI1BAEBCgAfBQJTjzMOGBxaeVggPHp5eC52aW1AZ21haWwuY29tPgAKCRCf3UKj
                HhHSvvTUD/98tB8KRVDs+HEA2msY0VbsPvETHCHalvd1GWGRybaPd1MFSP4amiAd
                xzwSMcFSYbDGq2F0QKwYe+mQxefr0wBiv4ko/HyL4lLv+/Bf9St/EO+fPO5EsILg
                EXwI5eEvgr/aLFiXllluyegWhSZgelz3QsmkSKlbhMaU1RZ3xj10fTyIGp6S/tRi
                IOVXD54MbEfxMr5Y9k3JMuhu/bUK+UBNYyOyUYrH/w3uX5Li0XhRkApt1tcaed5H
                I8aRwcIvzgs05mNzaRnJA5b4e1RhEa60VYvPYonR4UFwR5mUG8LRN/6/PwGL0KDP
                +xC2Uv0Eez0P1u/FWna5Thz9YolA65mEm+lVu4D4ZlXapZTwo3hbgvl7NnZfshtr
                Gpl/Vm7CLtXbt3EqeRw63oKXpbyEuh1pgpBKB43bZ29IcIuyIaihSp/ajxksQE+z
                ozZCpYPc+BbbYxFK5mJCg7eAucwU5hQP8OHdGIJh9Qbx2EDqrhEO84eMdo2e41oq
                NKgnOdFfO+xSdH/kfc4agsy56vtkMuynn1jtT/GbkKmWz4HikPFLnoHVoYsEF57g
                OIK9kXYPrUzeeBzqs0xBIKsMZGaLfmoxbC7Rcg+3lXUSw2JyhalXufgTTP2RVbJR
                kPx7DVv0iVVpigw0Xqsw1e0Px64FjJopZwibP0xEGJ+FxHSVAtgt7w==
                =Mj64
                -----END PGP SIGNATURE-----

                --
                --
                You received this message from the "vim_dev" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php

                ---
                You received this message because you are subscribed to the Google Groups "vim_dev" group.
                To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
                For more options, visit https://groups.google.com/d/optout.
              • Ingo Karkat
                On 04-Jun-2014 16:54 +0200, Павлов Николай Александрович wrote: On 04-Jun-2014 16:54, Павлов Николай
                Message 7 of 8 , Jun 4, 2014
                • 0 Attachment
                  On 04-Jun-2014 16:54 +0200, Павлов Николай Александрович wrote:

                  On 04-Jun-2014 16:54, Павлов Николай Александрович wrote:>
                  >
                  > On June 4, 2014 6:44:34 PM GMT+03:00, "Павлов Николай
                  > Александрович" <zyx.vim@...> wrote:
                  >> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512
                  >
                  >
                  >
                  >> On June 4, 2014 3:48:42 PM GMT+03:00, Ingo Karkat
                  >> <swdev@...> wrote:
                  >>> On 04-Jun-2014 13:34 +0200, Axel Bender wrote:
                  >>>
                  >>>> I'd already be happy if virtcol() would take into account
                  >>>> the length
                  >>> of the showbreak string. I'm otherwise prepared to work with
                  >>> UTF-8 characters...
                  >>>
                  >>> Character widths are not directly related to this, but that
                  >>> little incorrectness in your otherwise precise and welcome bug
                  >>> report shouldn't have provoked such a rant. Sorry.
                  >>>
                  >>>> I consider this a flaw (well maybe a bug?) that should be
                  >>>> fixed.
                  >>>
                  >>> I can reproduce this issue with 7.4.264. Even worse, :set
                  >>> linebreak also affects the virtcol() value and makes it wrong
                  >>> (when such wrap
                  >> occurs).
                  >>> So, one only gets correct values out of virtcol() with :set
                  >>> sbr=
                  >> nolbr;
                  >>> which indeed should be fixed!
                  >
                  >> I am not sure it is a bug. Most likely it is absolutely correct
                  >> behavior: pretend you need to know on which virtual line of the
                  >> current line cursor is located and on which virtual column on
                  >> this virtual line. Please describe how you will solve this with
                  >> current behavior of virtcol() and with proposed one.
                  >
                  >> Discussing whether this behavior is a bug or not is pointless
                  >> without showing the use-case. I know that the above task may
                  >> only be solved with "bugged" virtcol(), otherwise you will have
                  >> to do option parsing for yourself which is a waste of time.
                  >
                  > I have a use-case: if you need to move to some character you
                  > usually use bar motion and bar motion ignores additional
                  > characters from &showbreak.
                  >
                  > Thus I would suggest to patch bar motion to also take breaks into
                  > account like virtcol() does.

                  I use virtcol() in several of my plugins (e.g. AlignFromCursor,
                  http://www.vim.org/scripts/script.php?script_id=4155), mostly to align
                  the current line to a column. With the current (broken) behavior of
                  virtcol(), this alignment would be off when wrapping and linebreak /
                  showbreak is enabled! When I use the plugin to align the text right of
                  the cursor to column 80, I want the plugin to manipulate *the text*
                  (not including any editor embellishments like showbreak!) before the
                  cursor so that it occupies 79 display cells, regardless of the way
                  that text line is currently wrapped and displayed. Of course, my
                  plugin could replace virtcol() with strdisplaywidth(), but the latter
                  is a recent addition only, and in the next paragraph I'm going to
                  argue that the two should correspond, not have slightly different
                  semantics (that before this bug report nobody was aware of).

                  >> I though think that virtcol() behavior is not a bug, but
                  >> documentation is incorrect (it says "the last screen position
                  >> occupied by the character at that position, when the screen
                  >> would be of **unlimited width**" which obviously contradicts with
                  >> the current behavior: no wraps are possible on the screen with
                  >> unlimited width hence these options may not apply).

                  To me, what the documentation describes is the sensible and desired
                  behavior, and the implementation should be changed, not the other way
                  around. Vim's wrapping behavior and 'showbreak' is limited to this
                  editor and the user's settings, but when I do formatting, I usually
                  want to align to "idealistic" screen columns. Same applies to the bar
                  motion; I think the current behavior is correct.

                  -- regards, ingo

                  --
                  --
                  You received this message from the "vim_dev" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php

                  ---
                  You received this message because you are subscribed to the Google Groups "vim_dev" group.
                  To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
                  For more options, visit https://groups.google.com/d/optout.
                • Axel Bender
                  I cannot follow your argumentation. The docs say: The result is a Number, which is the screen column of the file position given with {expr}. That is, the
                  Message 8 of 8 , Jun 5, 2014
                  • 0 Attachment
                    I cannot follow your argumentation. The docs say:

                    "The result is a Number, which is the screen column of the file position given with {expr}. That is, the last screen position occupied by the character at that position, *when the screen would be of unlimited width*."

                    The last sentence clearly states that "side-effects" like showbreak, or wrap must not have any influence on the returned value of virtcol().

                    They way it is implemented now is inconsistent with the description - let alone with the results...

                    --
                    --
                    You received this message from the "vim_dev" maillist.
                    Do not top-post! Type your reply below the text you are replying to.
                    For more information, visit http://www.vim.org/maillist.php

                    ---
                    You received this message because you are subscribed to the Google Groups "vim_dev" group.
                    To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
                    For more options, visit https://groups.google.com/d/optout.
                  Your message has been successfully submitted and would be delivered to recipients shortly.