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

funcrtion func refs and autoloading ?

Expand Messages
  • Marc Weber
    Hi. I d like to enhance user experience when installing plugins. I stumbled uppone one small but important issue: funcref( a#foo#Func ) barks if the functions
    Message 1 of 5 , Nov 28, 2008
      Hi.

      I'd like to enhance user experience when installing plugins.
      I stumbled uppone one small but important issue:
      funcref('a#foo#Func') barks if the functions hasn't been loaded yet.
      Why is this bad? Because it's no longer lazy.
      Wether the function should be loaded if it doesn't exist yet should be
      done when it is called, not when the reference is created!

      Is there any chance to change this?
      I really don't want to add pseudo types such as
      {'funcref': 'funcname'}. But I think I don't have a choice right now.
      How do you feel about this?

      I'd like to be able to use function references inconfiguration files
      without those references files beeing loaded when loading the config.

      Of course I can use Function('name') instead of fucntion which loads the
      file. But then I don't have to use autoloading at all.

      Sincerly
      Marc Weber

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Marc Weber
      ... Indeed this does work very well. Marc Weber --~--~---------~--~----~------------~-------~--~----~ You received this message from the vim_dev maillist.
      Message 2 of 5 , Nov 28, 2008
        > {'funcref': 'funcname'}. But I think I don't have a choice right now.
        > How do you feel about this?
        Indeed this does work very well.

        Marc Weber

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_dev" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Kana Natsuno
        ... How about using a wrapper function for an autoloaded function as follows? in plugin/foo.vim function WrapperFunction(...) return
        Message 3 of 5 , Nov 28, 2008
          On Sat, 29 Nov 2008 06:51:34 +0900, Marc Weber <marco-oweber@...> wrote:
          > I stumbled uppone one small but important issue:
          > funcref('a#foo#Func') barks if the functions hasn't been loaded yet.
          > Why is this bad? Because it's no longer lazy.
          > Wether the function should be loaded if it doesn't exist yet should be
          > done when it is called, not when the reference is created!
          > ...
          > I'd like to be able to use function references inconfiguration files
          > without those references files beeing loaded when loading the config.

          How about using a wrapper function for an autoloaded function as follows?

          " in plugin/foo.vim
          function WrapperFunction(...)
          return call('original#function', a:000)
          endfunction

          " in someone's vimrc
          let FuncRef = function('WrapperFunction')

          If you don't have to use funcrefs, there is another way which
          uses the name of a function instead of a reference for it, as follows:

          let funcname = 'original#function'
          call {funcname}() "==> same as :call original#function()


          --
          To Vim, or not to Vim.
          kana <http://whileimautomaton.net/>

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_dev" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Bram Moolenaar
          ... I don t see a problem with accepting a function name for auto-loading as a funcref. The only problem might be that you get an error for the function not
          Message 4 of 5 , Nov 29, 2008
            Marc Weber wrote:

            > I'd like to enhance user experience when installing plugins.
            > I stumbled uppone one small but important issue:
            > funcref('a#foo#Func') barks if the functions hasn't been loaded yet.
            > Why is this bad? Because it's no longer lazy.
            > Wether the function should be loaded if it doesn't exist yet should be
            > done when it is called, not when the reference is created!
            >
            > Is there any chance to change this?
            > I really don't want to add pseudo types such as
            > {'funcref': 'funcname'}. But I think I don't have a choice right now.
            > How do you feel about this?
            >
            > I'd like to be able to use function references inconfiguration files
            > without those references files beeing loaded when loading the config.
            >
            > Of course I can use Function('name') instead of fucntion which loads the
            > file. But then I don't have to use autoloading at all.

            I don't see a problem with accepting a function name for auto-loading as
            a funcref. The only problem might be that you get an error for the
            function not being defined when it's used, instead of when the funcref
            is set.

            Try this patch:


            *** ../vim-7.2.055/src/eval.c Fri Nov 28 21:26:50 2008
            --- src/eval.c Sat Nov 29 12:28:51 2008
            ***************
            *** 10339,10345 ****
            s = get_tv_string(&argvars[0]);
            if (s == NULL || *s == NUL || VIM_ISDIGIT(*s))
            EMSG2(_(e_invarg2), s);
            ! else if (!function_exists(s))
            EMSG2(_("E700: Unknown function: %s"), s);
            else
            {
            --- 10339,10346 ----
            s = get_tv_string(&argvars[0]);
            if (s == NULL || *s == NUL || VIM_ISDIGIT(*s))
            EMSG2(_(e_invarg2), s);
            ! /* Don't check an autoload name for existence here. */
            ! else if (vim_strchr(s, AUTOLOAD_CHAR) == NULL && !function_exists(s))
            EMSG2(_("E700: Unknown function: %s"), s);
            else
            {


            --
            FATHER: Did you kill all those guards?
            LAUNCELOT: Yes ... I'm very sorry ...
            FATHER: They cost fifty pounds each!
            "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/ \\\
            \\\ download, build and distribute -- http://www.A-A-P.org ///
            \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_dev" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          • Marc Weber
            ... no way. much too complicated. I won t create a wrapper function in each case I d like to create a funcref ... That might have been an option if I had known
            Message 5 of 5 , Dec 1, 2008
              > How about using a wrapper function for an autoloaded function as follows?
              >
              > " in plugin/foo.vim
              > function WrapperFunction(...)
              > return call('original#function', a:000)
              > endfunction
              >
              > " in someone's vimrc
              > let FuncRef = function('WrapperFunction')
              no way. much too complicated. I won't create a wrapper function in each
              case I'd like to create a funcref

              > If you don't have to use funcrefs, there is another way which
              > uses the name of a function instead of a reference for it, as follows:
              >
              > let funcname = 'original#function'
              > call {funcname}() "==> same as :call original#function()
              That might have been an option if I had known about it earlier.

              Thanks for your input!
              Marc

              --~--~---------~--~----~------------~-------~--~----~
              You received this message from the "vim_dev" maillist.
              For more information, visit http://www.vim.org/maillist.php
              -~----------~----~----~----~------~----~------~--~---
            Your message has been successfully submitted and would be delivered to recipients shortly.