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

Dumb question: variables in the statusline

Expand Messages
  • Ben Klein
    (Maybe this will be like last time, where I just had to send the question to the list before I could realize how idiotically wrong I was...) I have a function
    Message 1 of 8 , Feb 27, 2014
    • 0 Attachment
      (Maybe this will be like last time, where I just had to send the question to the list before I could realize how idiotically wrong I was...)

      I have a function which takes ... arguments, and when I try to call it from another function to set the statusline, I basically get:

      E121: Undefined variable: a:1
      E116: Invalid arguments for function FunctionFromWhichIAmTryingToGetAStatusline(a:1)

      So the function getting the error is more or less:

      function! SetUpTheStatusline(...)
        setlocal statusline=%!FunctionFromWhichIAmTryingToGetAStatusline(a:1)
      endfunction

      And that is just getting those two errors.

      To be clear, I have verified that there is indeed a:1 in the SetUpTheStatusline() function. I can do (it seems) anything with it -- even use it in the call to FunctionFromWhichIAmTryingToGetAStatusline() -- except for using it in a function called in the statusline.

      What am I doing wrong?

      --
      b

      --
      --
      You received this message from the "vim_use" 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_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Paul Isambert
      Ben Klein ... “statusline” is a string, so I guess the correct form is: exe setlocal
      Message 2 of 8 , Feb 27, 2014
      • 0 Attachment
        "Ben Klein" <ben@...>
        >
        > (Maybe this will be like last time, where I just had to send the
        > question to the list before I could realize how idiotically wrong I
        > was...)
        >
        >
        > I have a function which takes ... arguments, and when I try to call
        > it from another function to set the statusline, I basically get:
        >
        >
        >
        > E121: Undefined variable: a:1
        > E116: Invalid arguments for function
        > FunctionFromWhichIAmTryingToGetAStatusline(a:1)
        >
        >
        > So the function getting the error is more or less:
        >
        >
        > function! SetUpTheStatusline(...)
        > setlocal statusline=%!FunctionFromWhichIAmTryingToGetAStatusline(a:1)
        > endfunction
        >
        >
        > And that is just getting those two errors.
        >
        >
        > To be clear, I have verified that there is indeed a:1 in the
        > SetUpTheStatusline() function. I can do (it seems) anything with it
        > -- even use it in the call to
        > FunctionFromWhichIAmTryingToGetAStatusline() -- except for using it
        > in a function called in the statusline.
        >
        >
        > What am I doing wrong?

        “statusline” is a string, so I guess the correct form is:

        exe "setlocal statusline=%!FunctionFromWhichIAmTryingToGetAStatusline('" . a:1 . "')"

        Of course, a:1 should be of the proper type.

        Best,
        Paul

        --
        --
        You received this message from the "vim_use" 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_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Benjamin Klein
        ... I was wondering whether I would have to use execute. Thanks! -- b Sent from my iPhone -- -- You received this message from the vim_use maillist. Do not
        Message 3 of 8 , Feb 27, 2014
        • 0 Attachment
          On Feb 27, 2014, at 10:05 AM, Paul Isambert <zappathustra@...> wrote:

          > “statusline” is a string, so I guess the correct form is:
          >
          > exe "setlocal statusline=%!FunctionFromWhichIAmTryingToGetAStatusline('" . a:1 . "')"

          I was wondering whether I would have to use execute. Thanks!

          --
          b

          Sent from my iPhone

          --
          --
          You received this message from the "vim_use" 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_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • Benjamin Klein
          Huh. Trying that, with a statusline containing %= , gives me E518: Unknown option: %= That’s setting the statusline with execute. -- b Sent from my iPhone
          Message 4 of 8 , Feb 27, 2014
          • 0 Attachment
            Huh. Trying that, with a statusline containing "%=", gives me

            E518: Unknown option: %=

            That’s setting the statusline with execute.

            --
            b

            Sent from my iPhone

            --
            --
            You received this message from the "vim_use" 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_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • Charles Campbell
            ... * Could you give us the new exe line you re using to set the statusline? * What does :echo &l:stl show ? * You re passing a:1 to exe; perhaps it should
            Message 5 of 8 , Feb 27, 2014
            • 0 Attachment
              Benjamin Klein wrote:
              > Huh. Trying that, with a statusline containing "%=", gives me
              >
              > E518: Unknown option: %=
              >
              > That’s setting the statusline with execute.
              >
              >
              * Could you give us the new exe line you're using to set the statusline?
              * What does :echo &l:stl show ?
              * You're passing a:1 to exe; perhaps it should be escaped, too: ...
              fnameescape(a:1) ...

              Regards,
              C Campbell

              --
              --
              You received this message from the "vim_use" 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_use" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            • Benjamin Klein
              ... Right now it s execute setlocal statusline= . status where `status` is the string returned by the function. ... The function which is supposed to get the
              Message 6 of 8 , Feb 27, 2014
              • 0 Attachment
                On Feb 27, 2014, at 11:42 AM, Charles Campbell <Charles.E.Campbell@...> wrote:

                > * Could you give us the new exe line you're using to set the statusline?

                Right now it's

                execute "setlocal statusline=" . status

                where `status` is the string returned by the function.

                > * What does :echo &l:stl show ?

                The function which is supposed to get the status line begins the string with the a:1, and then appends %= and the rest of the line to that. &l:stl, after I get the error, is the a:1 (message) passed to the function. Everything from that =% onward is being left out.

                > * You're passing a:1 to exe; perhaps it should be escaped, too: ... fnameescape(a:1) ...

                A good idea -- thanks. (It hasn't seemed to affect this situation though, sadly.)

                Ben

                --
                b

                Sent from my iPhone

                --
                --
                You received this message from the "vim_use" 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_use" group.
                To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                For more options, visit https://groups.google.com/groups/opt_out.
              • Nikolay Pavlov
                ... with the a:1, and then appends %= and the rest of the line to that. &l:stl, after I get the error, is the a:1 (message) passed to the function. Everything
                Message 7 of 8 , Feb 28, 2014
                • 0 Attachment


                  On Feb 27, 2014 9:55 PM, "Benjamin Klein" <ben@...> wrote:
                  >
                  > On Feb 27, 2014, at 11:42 AM, Charles Campbell <Charles.E.Campbell@...> wrote:
                  >
                  > > * Could you give us the new exe line you're using to set the statusline?
                  >
                  > Right now it's
                  >
                  > execute "setlocal statusline=" . status
                  >
                  > where `status` is the string returned by the function.
                  >
                  > > * What does   :echo &l:stl  show ?
                  >
                  > The function which is supposed to get the status line begins the string with the a:1, and then appends %= and the rest of the line to that. &l:stl, after I get the error, is the a:1 (message) passed to the function. Everything from that =% onward is being left out.
                  >
                  > > * You're passing a:1 to exe; perhaps it should be escaped, too:  ... fnameescape(a:1) ...
                  >
                  > A good idea -- thanks. (It hasn't seemed to affect this situation though, sadly.)

                  Don't use :execute and incorrect escaping. The following should work:

                      let &l:statusline='%!FunctionFromWhichIAmTryingToGetAStatusline('.string(a:1).')'

                  Function fnameescape() has other purpose and it must not be used to escape strings for statusline.

                  I am not sure how this would deal with some special characters though: those below 0x20 and %. They should not cause trouble AFAIK, but I may be wrong.

                  >
                  > Ben
                  >
                  > --
                  > b
                  >
                  > Sent from my iPhone
                  >
                  > --
                  > --
                  > You received this message from the "vim_use" 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_use" group.
                  > To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                  > For more options, visit https://groups.google.com/groups/opt_out.

                  --
                  --
                  You received this message from the "vim_use" 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_use" group.
                  To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                  For more options, visit https://groups.google.com/groups/opt_out.
                • Benjamin Klein
                  ... That does seem to have worked. Thanks! Ben -- b Sent from my iPhone -- -- You received this message from the vim_use maillist. Do not top-post! Type your
                  Message 8 of 8 , Feb 28, 2014
                  • 0 Attachment
                    On Feb 28, 2014, at 7:58 AM, Nikolay Pavlov <zyx.vim@...> wrote: 

                    Don't use :execute and incorrect escaping. The following should work:

                        let &l:statusline='%!FunctionFromWhichIAmTryingToGetAStatusline('.string(a:1).')'


                    That does seem to have worked. Thanks!

                    Ben

                    --
                    b

                    Sent from my iPhone

                    --
                    --
                    You received this message from the "vim_use" 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_use" group.
                    To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                    For more options, visit https://groups.google.com/groups/opt_out.
                  Your message has been successfully submitted and would be delivered to recipients shortly.