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

calling a function in vimrc before defining it

Expand Messages
  • Ivan
    I wrote a function in my vimrc that builds my statusline (I use it to toggle certain elements). The function call occurs earlier in the file than the actual
    Message 1 of 3 , Mar 16, 2014
    • 0 Attachment
      I wrote a function in my vimrc that builds my statusline (I use it to toggle certain elements). The function call occurs earlier in the file than the actual definition, and I wondered whether that would be a problem, but when I started up MacVim it all worked fine. In terminal Vim however, I get an error on startup (E117: Unknown function: BuildStatusLn), though it still works fine.

      Is there a way around this? Is it bad practice? Does anyone know why it's not raising an error in MacVim?

      --
      --
      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/d/optout.
    • Nikolay Pavlov
      ... toggle certain elements). The function call occurs earlier in the file than the actual definition, and I wondered whether that would be a problem, but when
      Message 2 of 3 , Mar 16, 2014
      • 0 Attachment


        On Mar 16, 2014 8:53 PM, "Ivan" <ivan.brennan@...> wrote:
        >
        > I wrote a function in my vimrc that builds my statusline (I use it to toggle certain elements). The function call occurs earlier in the file than the actual definition, and I wondered whether that would be a problem, but when I started up MacVim it all worked fine. In terminal Vim however, I get an error on startup (E117: Unknown function: BuildStatusLn), though it still works fine.

        It is not possible to call function before it is defined. You must be mistaking about when this function gets called. If you have something like

            set statusline=%!BuildStatusLn()

        then function *will* be called when statusline is drawn, but it is not called *when this line is parsed*. I guess that in MacVim statusline draw is deferred until gui initialization (which happens after vimrc loading) and in terminal it is drown immediately when you set this option.

        >
        > Is there a way around this? Is it bad practice? Does anyone know why it's not raising an error in MacVim?
        >
        > --
        > --
        > 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/d/optout.

        --
        --
        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/d/optout.
      • Ivan
        ... That makes sense. Thanks! I wasn t sure how to describe the situation, re parsed vs called. -- -- You received this message from the vim_use maillist. Do
        Message 3 of 3 , Mar 18, 2014
        • 0 Attachment
          On Sunday, March 16, 2014 3:20:43 PM UTC-4, ZyX wrote:
          > then function *will* be called when statusline is drawn, but it is not called *when this line is parsed*. I guess that in MacVim statusline draw is deferred until gui initialization (which happens after vimrc loading) and in terminal it is drown immediately when you set this option.

          That makes sense. Thanks! I wasn't sure how to describe the situation, re parsed vs called.

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