3ef2ca
To: vim_dev@googlegroups.com
3ef2ca
Subject: Patch 7.4.265
3ef2ca
Fcc: outbox
3ef2ca
From: Bram Moolenaar <Bram@moolenaar.net>
3ef2ca
Mime-Version: 1.0
3ef2ca
Content-Type: text/plain; charset=UTF-8
3ef2ca
Content-Transfer-Encoding: 8bit
3ef2ca
------------
3ef2ca
3ef2ca
Patch 7.4.265 (after 7.4.260)
3ef2ca
Problem:    Can't call a global function with "g:" in an expression.
3ef2ca
Solution:   Skip the "g:" when looking up the function.
3ef2ca
Files:	    src/eval.c, src/testdir/test_eval.in, src/testdir/test_eval.ok
3ef2ca
3ef2ca
3ef2ca
*** ../vim-7.4.264/src/eval.c	2014-04-23 20:43:07.290689167 +0200
3ef2ca
--- src/eval.c	2014-04-24 17:06:38.884920215 +0200
3ef2ca
***************
3ef2ca
*** 8485,8517 ****
3ef2ca
      /* execute the function if no errors detected and executing */
3ef2ca
      if (evaluate && error == ERROR_NONE)
3ef2ca
      {
3ef2ca
  	rettv->v_type = VAR_NUMBER;	/* default rettv is number zero */
3ef2ca
  	rettv->vval.v_number = 0;
3ef2ca
  	error = ERROR_UNKNOWN;
3ef2ca
  
3ef2ca
! 	if (!builtin_function(fname, -1))
3ef2ca
  	{
3ef2ca
  	    /*
3ef2ca
  	     * User defined function.
3ef2ca
  	     */
3ef2ca
! 	    fp = find_func(fname);
3ef2ca
  
3ef2ca
  #ifdef FEAT_AUTOCMD
3ef2ca
  	    /* Trigger FuncUndefined event, may load the function. */
3ef2ca
  	    if (fp == NULL
3ef2ca
  		    && apply_autocmds(EVENT_FUNCUNDEFINED,
3ef2ca
! 						     fname, fname, TRUE, NULL)
3ef2ca
  		    && !aborting())
3ef2ca
  	    {
3ef2ca
  		/* executed an autocommand, search for the function again */
3ef2ca
! 		fp = find_func(fname);
3ef2ca
  	    }
3ef2ca
  #endif
3ef2ca
  	    /* Try loading a package. */
3ef2ca
! 	    if (fp == NULL && script_autoload(fname, TRUE) && !aborting())
3ef2ca
  	    {
3ef2ca
  		/* loaded a package, search for the function again */
3ef2ca
! 		fp = find_func(fname);
3ef2ca
  	    }
3ef2ca
  
3ef2ca
  	    if (fp != NULL)
3ef2ca
--- 8485,8523 ----
3ef2ca
      /* execute the function if no errors detected and executing */
3ef2ca
      if (evaluate && error == ERROR_NONE)
3ef2ca
      {
3ef2ca
+ 	char_u *rfname = fname;
3ef2ca
+ 
3ef2ca
+ 	/* Ignore "g:" before a function name. */
3ef2ca
+ 	if (fname[0] == 'g' && fname[1] == ':')
3ef2ca
+ 	    rfname = fname + 2;
3ef2ca
+ 
3ef2ca
  	rettv->v_type = VAR_NUMBER;	/* default rettv is number zero */
3ef2ca
  	rettv->vval.v_number = 0;
3ef2ca
  	error = ERROR_UNKNOWN;
3ef2ca
  
3ef2ca
! 	if (!builtin_function(rfname, -1))
3ef2ca
  	{
3ef2ca
  	    /*
3ef2ca
  	     * User defined function.
3ef2ca
  	     */
3ef2ca
! 	    fp = find_func(rfname);
3ef2ca
  
3ef2ca
  #ifdef FEAT_AUTOCMD
3ef2ca
  	    /* Trigger FuncUndefined event, may load the function. */
3ef2ca
  	    if (fp == NULL
3ef2ca
  		    && apply_autocmds(EVENT_FUNCUNDEFINED,
3ef2ca
! 						     rfname, rfname, TRUE, NULL)
3ef2ca
  		    && !aborting())
3ef2ca
  	    {
3ef2ca
  		/* executed an autocommand, search for the function again */
3ef2ca
! 		fp = find_func(rfname);
3ef2ca
  	    }
3ef2ca
  #endif
3ef2ca
  	    /* Try loading a package. */
3ef2ca
! 	    if (fp == NULL && script_autoload(rfname, TRUE) && !aborting())
3ef2ca
  	    {
3ef2ca
  		/* loaded a package, search for the function again */
3ef2ca
! 		fp = find_func(rfname);
3ef2ca
  	    }
3ef2ca
  
3ef2ca
  	    if (fp != NULL)
3ef2ca
*** ../vim-7.4.264/src/testdir/test_eval.in	2014-04-23 20:43:07.290689167 +0200
3ef2ca
--- src/testdir/test_eval.in	2014-04-24 17:07:57.108918330 +0200
3ef2ca
***************
3ef2ca
*** 172,182 ****
3ef2ca
  :endtry
3ef2ca
  :"
3ef2ca
  :" function name starting with/without "g:", buffer-local funcref.
3ef2ca
! :function! g:Foo()
3ef2ca
! :  $put ='called Foo()'
3ef2ca
  :endfunction
3ef2ca
  :let b:my_func = function('Foo')
3ef2ca
! :call b:my_func()
3ef2ca
  :"
3ef2ca
  :/^start:/+1,$wq! test.out
3ef2ca
  :" vim: et ts=4 isk-=\: fmr=???,???
3ef2ca
--- 172,184 ----
3ef2ca
  :endtry
3ef2ca
  :"
3ef2ca
  :" function name starting with/without "g:", buffer-local funcref.
3ef2ca
! :function! g:Foo(n)
3ef2ca
! :  $put ='called Foo(' . a:n . ')'
3ef2ca
  :endfunction
3ef2ca
  :let b:my_func = function('Foo')
3ef2ca
! :call b:my_func(1)
3ef2ca
! :echo g:Foo(2)
3ef2ca
! :echo Foo(3)
3ef2ca
  :"
3ef2ca
  :/^start:/+1,$wq! test.out
3ef2ca
  :" vim: et ts=4 isk-=\: fmr=???,???
3ef2ca
*** ../vim-7.4.264/src/testdir/test_eval.ok	2014-04-23 20:43:07.290689167 +0200
3ef2ca
--- src/testdir/test_eval.ok	2014-04-24 16:54:36.856937613 +0200
3ef2ca
***************
3ef2ca
*** 338,341 ****
3ef2ca
  Vim(function):E128: Function name must start with a capital or "s:": g:test()
3ef2ca
  Vim(function):E128: Function name must start with a capital or "s:": b:test()
3ef2ca
  Vim(function):E128: Function name must start with a capital or "s:": test2() "#
3ef2ca
! called Foo()
3ef2ca
--- 338,343 ----
3ef2ca
  Vim(function):E128: Function name must start with a capital or "s:": g:test()
3ef2ca
  Vim(function):E128: Function name must start with a capital or "s:": b:test()
3ef2ca
  Vim(function):E128: Function name must start with a capital or "s:": test2() "#
3ef2ca
! called Foo(1)
3ef2ca
! called Foo(2)
3ef2ca
! called Foo(3)
3ef2ca
*** ../vim-7.4.264/src/version.c	2014-04-23 20:43:07.290689167 +0200
3ef2ca
--- src/version.c	2014-04-24 16:56:24.520935019 +0200
3ef2ca
***************
3ef2ca
*** 736,737 ****
3ef2ca
--- 736,739 ----
3ef2ca
  {   /* Add new patch number below this line */
3ef2ca
+ /**/
3ef2ca
+     265,
3ef2ca
  /**/
3ef2ca
3ef2ca
-- 
3ef2ca
The sooner you fall behind, the more time you'll have to catch up.
3ef2ca
3ef2ca
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
3ef2ca
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
3ef2ca
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
3ef2ca
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///