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

Bug in 'statusline' - without pictures

Expand Messages
  • Peter Slížik
    OK, Thunderbird messed with references to external pictures; and it was a stupid idea to include pictures, I should have foreseen it. So, here s a copy with
    Message 1 of 5 , Sep 2, 2011
    • 0 Attachment
      OK, Thunderbird messed with references to external pictures; and it
      was a stupid idea to include pictures, I should have foreseen it.
      So, here's a copy with external links instead:

      ==========================================

      Recently I dediced to put the &ff option in my statusline. However, I
      want to edit my files *always* in the unix format, even when I am on
      Windows. For this reason, I want to have no message shown in the
      status line if the file format is set to "unix" (`uncluttered' is the
      word here). I want any other format displayed as an error (with red
      background).

      I wrote this code

        :set statusline+=@%(\ %#ErrorMsg#[%{&ff!='unix'?&ff:''}]%*%)@

      @ - my debugging begin and end of string markers, in order to be able
      to "see" an empty string
      %(...%) - grouping is used here to make the leading empty space and
      the brackets disappear if the expression yields an empty string

      Results:
       - if &ff is set to 'dos' or 'mac', the status line is correct:

      http://tinyurl.com/vim-statusline-dos
      http://tinyurl.com/vim-statusline-mac

       - if &ff is set to 'unix', the expression produces an empty string
      ('@@') followed by two superfluous red spaces:

      http://tinyurl.com/vim-statusline-unix

      (Note the same is true for empty &ff, in this case the 'else' branch
      of the ternary operator comes into force.)

      If I remove the '@' markers, just two red spaces are produced.

      Strangely, if I put the brackets outside of the #ErrorMsg# code,
      everything works perfectly:

        :set statusline+=@%(\ [%#ErrorMsg#%{&ff!='unix'?&ff:''}%*]%)@

      http://tinyurl.com/vim-statusline-alt-unix

      However, that's not a good workaround - it is not exactly what I
      imagined for [dos] and [mac] cases:

      http://tinyurl.com/vim-statusline-alt-dos

      This is not a top-priority bug, of course; but I would appreciate any insights.

      Best regards,

      Peter

      --
      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
    • Tony Mechelynck
      ... Well, isn t that what you want? Your ternary operator resolves to the empty string if fileformat is set to unix , otherwise it resolves to the
      Message 2 of 5 , Sep 2, 2011
      • 0 Attachment
        On 02/09/11 15:33, Peter Slížik wrote:
        > OK, Thunderbird messed with references to external pictures; and it
        > was a stupid idea to include pictures, I should have foreseen it.
        > So, here's a copy with external links instead:
        >
        > ==========================================
        >
        > Recently I dediced to put the&ff option in my statusline. However, I
        > want to edit my files *always* in the unix format, even when I am on
        > Windows. For this reason, I want to have no message shown in the
        > status line if the file format is set to "unix" (`uncluttered' is the
        > word here). I want any other format displayed as an error (with red
        > background).
        >
        > I wrote this code
        >
        > :set statusline+=@%(\ %#ErrorMsg#[%{&ff!='unix'?&ff:''}]%*%)@
        >
        > @ - my debugging begin and end of string markers, in order to be able
        > to "see" an empty string
        > %(...%) - grouping is used here to make the leading empty space and
        > the brackets disappear if the expression yields an empty string
        >
        > Results:
        > - if&ff is set to 'dos' or 'mac', the status line is correct:
        >
        > http://tinyurl.com/vim-statusline-dos
        > http://tinyurl.com/vim-statusline-mac
        >
        > - if&ff is set to 'unix', the expression produces an empty string
        > ('@@') followed by two superfluous red spaces:
        >
        > http://tinyurl.com/vim-statusline-unix

        Well, isn't that what you want? Your ternary operator resolves to the
        empty string if 'fileformat' is set to "unix", otherwise it resolves to
        the 'fileformat' setting.

        >
        > (Note the same is true for empty&ff, in this case the 'else' branch
        > of the ternary operator comes into force.)

        No, for empty ff it's the "then" branch (not equal to 'unix').

        >
        > If I remove the '@' markers, just two red spaces are produced.
        >
        > Strangely, if I put the brackets outside of the #ErrorMsg# code,
        > everything works perfectly:
        >
        > :set statusline+=@%(\ [%#ErrorMsg#%{&ff!='unix'?&ff:''}%*]%)@
        >
        > http://tinyurl.com/vim-statusline-alt-unix
        >
        > However, that's not a good workaround - it is not exactly what I
        > imagined for [dos] and [mac] cases:
        >
        > http://tinyurl.com/vim-statusline-alt-dos
        >
        > This is not a top-priority bug, of course; but I would appreciate any insights.
        >
        > Best regards,
        >
        > Peter
        >

        What about a simpler 'statusline' for a start? (If it works, you can
        make it more complex)

        First, let's start with setting explicitly what the default 'statusline'
        (with 'ruler') would say (this is in the help: go to ":help
        'statusline'" then search for /with 'ruler' set/

        :set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P

        Now let's add someting that should never be empty, or at least, not if
        'fileformats' (plural) it not empty itself.

        :set statusline=%<%f\ %h%m%r[%{&ff}]%=%-14.(%l,%c%V%)\ %P
        ------------------------------------^^^^^^^^

        This should add the fileformat in brackets at the end of the left part
        (just before the elastic blank filler), as one of:

        [dos]
        [unix]
        [mac]


        I think I know what happened in your case: Seeing that the expression
        between [ and ] resolved to the empty string, the statusline code
        removed the brackets: quoting from 'statusline' help:

        > When all items in a group becomes an empty string (i.e. flags that are
        > not set) and a minwid is not set for the group, the whole group will
        > become empty. This will make a group like the following disappear
        > completely from the statusline when none of the flags are set. >
        > :set statusline=...%(\ [%M%R%H]%)...


        Best regards,
        Tony.
        --
        hundred-and-one symptoms of being an internet addict:
        168. You have your own domain name.

        --
        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
      • Peter Slížik
        Dear Tony, others, I tried to explain all the possibilities I explored, and it seems that I failed to state the core of the problem clearly. ... To simplify
        Message 3 of 5 , Sep 2, 2011
        • 0 Attachment
          Dear Tony, others,

          I tried to explain all the possibilities I explored, and it seems that
          I failed to state the core of the problem clearly.

          >>   :set statusline+=@%(\ %#ErrorMsg#[%{&ff!='unix'?&ff:''}]%*%)@
          >>
          >>     http://tinyurl.com/vim-statusline-unix

          To simplify the code, it basically says:

          set statusline += @ %#ErrorMsg# %{this evaluates to an empty string} %* @

          If you look at the picture again, you'll see the expression actually produces:

          @@%#ErrorMsg#<Space><Space>%*

          I can't see any logical explanation of how the %#ErrorMsg# switch was
          able to move from inbetween @'s to the right. Morever, the grouping
          operators %( %) should have gotten rid of the %#ErrorMsg# completely.

          In short, there are two red spaces after '@@' that should not be
          there. I believe that is a bug in Vim.

          Could you confirm?

          Peter

          --
          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
        • Tony Mechelynck
          ... Yes, I see what you mean (I didn t yet try to reproduce); but what I proposed was to try something simpler, see if it worked as it was supposed to, and
          Message 4 of 5 , Sep 2, 2011
          • 0 Attachment
            On 02/09/11 22:12, Peter Slížik wrote:
            > Dear Tony, others,
            >
            > I tried to explain all the possibilities I explored, and it seems that
            > I failed to state the core of the problem clearly.
            >
            >>> :set statusline+=@%(\ %#ErrorMsg#[%{&ff!='unix'?&ff:''}]%*%)@
            >>>
            >>> http://tinyurl.com/vim-statusline-unix
            >
            > To simplify the code, it basically says:
            >
            > set statusline += @ %#ErrorMsg# %{this evaluates to an empty string} %* @
            >
            > If you look at the picture again, you'll see the expression actually produces:
            >
            > @@%#ErrorMsg#<Space><Space>%*
            >
            > I can't see any logical explanation of how the %#ErrorMsg# switch was
            > able to move from inbetween @'s to the right. Morever, the grouping
            > operators %( %) should have gotten rid of the %#ErrorMsg# completely.
            >
            > In short, there are two red spaces after '@@' that should not be
            > there. I believe that is a bug in Vim.
            >
            > Could you confirm?
            >
            > Peter
            >

            Yes, I see what you mean (I didn't yet try to reproduce); but what I
            proposed was to try something simpler, see if it worked as it was
            supposed to, and complexify it by _small_ steps if it did, until we
            could have a "good" case and a "bad" case that differed from each other
            by as little as possible. This would have helped Bram to locate exactly
            the part of the code which has the bug.

            Best regards,
            Tony.
            --
            Bubble Memory, n.:
            A derogatory term, usually referring to a person's
            intelligence. See also "vacuum tube".

            --
            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
          • Peter Slížik
            ... A minimal example you mean; thank you for pointing me in this way. ... that is, grouping is used to remove some text colored with %#ErrorMsg#. If the code
            Message 5 of 5 , Sep 5, 2011
            • 0 Attachment
              > ... but what I proposed was to try something simpler, see if it worked as it was
              > supposed ...

              A minimal example you mean; thank you for pointing me in this way.
              Well, after some playing it seems the minimal example is:

              :set statusline=%(%#ErrorMsg#xxx%*%)abcde

              that is, grouping is used to remove some text colored with %#ErrorMsg#.

              If the code between %#ErrorMsg# and %* is evaluated to something else
              than empty string ('xxx' in our example), it is properly removed, but
              the following text contains strlen('xxx') colored positions. That
              means, 'abc' gets colored.

              http://tinyurl.com/vim-statusline-minimal-example

              Hope that's its more clear now,

              Peter

              --
              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
            Your message has been successfully submitted and would be delivered to recipients shortly.