Karsten Hopp 1eaeac
To: vim_dev@googlegroups.com
Karsten Hopp 1eaeac
Subject: Patch 7.4.264
Karsten Hopp 1eaeac
Fcc: outbox
Karsten Hopp 1eaeac
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 1eaeac
Mime-Version: 1.0
Karsten Hopp 1eaeac
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 1eaeac
Content-Transfer-Encoding: 8bit
Karsten Hopp 1eaeac
------------
Karsten Hopp 1eaeac
Karsten Hopp 1eaeac
Patch 7.4.264 (after 7.4.260)
Karsten Hopp 1eaeac
Problem:    Can't define a function starting with "g:".  Can't assign a
Karsten Hopp 1eaeac
	    funcref to a buffer-local variable.
Karsten Hopp 1eaeac
Solution:   Skip "g:" at the start of a function name.  Don't check for colons
Karsten Hopp 1eaeac
	    when assigning to a variable.
Karsten Hopp 1eaeac
Files:	    src/eval.c, src/testdir/test_eval.in, src/testdir/test_eval.ok
Karsten Hopp 1eaeac
Karsten Hopp 1eaeac
Karsten Hopp 1eaeac
*** ../vim-7.4.263/src/eval.c	2014-04-23 19:44:26.366774008 +0200
Karsten Hopp 1eaeac
--- src/eval.c	2014-04-23 20:40:16.738693276 +0200
Karsten Hopp 1eaeac
***************
Karsten Hopp 1eaeac
*** 21583,21589 ****
Karsten Hopp 1eaeac
       * Get the function name.  There are these situations:
Karsten Hopp 1eaeac
       * func	    normal function name
Karsten Hopp 1eaeac
       *		    "name" == func, "fudi.fd_dict" == NULL
Karsten Hopp 1eaeac
-      * s:func	    script-local function name
Karsten Hopp 1eaeac
       * dict.func    new dictionary entry
Karsten Hopp 1eaeac
       *		    "name" == NULL, "fudi.fd_dict" set,
Karsten Hopp 1eaeac
       *		    "fudi.fd_di" == NULL, "fudi.fd_newkey" == func
Karsten Hopp 1eaeac
--- 21583,21588 ----
Karsten Hopp 1eaeac
***************
Karsten Hopp 1eaeac
*** 21593,21598 ****
Karsten Hopp 1eaeac
--- 21592,21599 ----
Karsten Hopp 1eaeac
       * dict.func    existing dict entry that's not a Funcref
Karsten Hopp 1eaeac
       *		    "name" == NULL, "fudi.fd_dict" set,
Karsten Hopp 1eaeac
       *		    "fudi.fd_di" set, "fudi.fd_newkey" == NULL
Karsten Hopp 1eaeac
+      * s:func	    script-local function name
Karsten Hopp 1eaeac
+      * g:func	    global function name, same as "func"
Karsten Hopp 1eaeac
       */
Karsten Hopp 1eaeac
      p = eap->arg;
Karsten Hopp 1eaeac
      name = trans_function_name(&p, eap->skip, 0, &fudi);
Karsten Hopp 1eaeac
***************
Karsten Hopp 1eaeac
*** 22286,22292 ****
Karsten Hopp 1eaeac
      }
Karsten Hopp 1eaeac
      else
Karsten Hopp 1eaeac
      {
Karsten Hopp 1eaeac
! 	if (lead == 2)	/* skip over "s:" */
Karsten Hopp 1eaeac
  	    lv.ll_name += 2;
Karsten Hopp 1eaeac
  	len = (int)(end - lv.ll_name);
Karsten Hopp 1eaeac
      }
Karsten Hopp 1eaeac
--- 22287,22294 ----
Karsten Hopp 1eaeac
      }
Karsten Hopp 1eaeac
      else
Karsten Hopp 1eaeac
      {
Karsten Hopp 1eaeac
! 	/* skip over "s:" and "g:" */
Karsten Hopp 1eaeac
! 	if (lead == 2 || (lv.ll_name[0] == 'g' && lv.ll_name[1] == ':'))
Karsten Hopp 1eaeac
  	    lv.ll_name += 2;
Karsten Hopp 1eaeac
  	len = (int)(end - lv.ll_name);
Karsten Hopp 1eaeac
      }
Karsten Hopp 1eaeac
***************
Karsten Hopp 1eaeac
*** 22317,22333 ****
Karsten Hopp 1eaeac
      else if (!(flags & TFN_INT) && builtin_function(lv.ll_name, len))
Karsten Hopp 1eaeac
      {
Karsten Hopp 1eaeac
  	EMSG2(_("E128: Function name must start with a capital or \"s:\": %s"),
Karsten Hopp 1eaeac
! 								  lv.ll_name);
Karsten Hopp 1eaeac
  	goto theend;
Karsten Hopp 1eaeac
      }
Karsten Hopp 1eaeac
!     if (!skip)
Karsten Hopp 1eaeac
      {
Karsten Hopp 1eaeac
  	char_u *cp = vim_strchr(lv.ll_name, ':');
Karsten Hopp 1eaeac
  
Karsten Hopp 1eaeac
  	if (cp != NULL && cp < end)
Karsten Hopp 1eaeac
  	{
Karsten Hopp 1eaeac
! 	    EMSG2(_("E884: Function name cannot contain a colon: %s"),
Karsten Hopp 1eaeac
! 								  lv.ll_name);
Karsten Hopp 1eaeac
  	    goto theend;
Karsten Hopp 1eaeac
  	}
Karsten Hopp 1eaeac
      }
Karsten Hopp 1eaeac
--- 22319,22334 ----
Karsten Hopp 1eaeac
      else if (!(flags & TFN_INT) && builtin_function(lv.ll_name, len))
Karsten Hopp 1eaeac
      {
Karsten Hopp 1eaeac
  	EMSG2(_("E128: Function name must start with a capital or \"s:\": %s"),
Karsten Hopp 1eaeac
! 								       start);
Karsten Hopp 1eaeac
  	goto theend;
Karsten Hopp 1eaeac
      }
Karsten Hopp 1eaeac
!     if (!skip && !(flags & TFN_QUIET))
Karsten Hopp 1eaeac
      {
Karsten Hopp 1eaeac
  	char_u *cp = vim_strchr(lv.ll_name, ':');
Karsten Hopp 1eaeac
  
Karsten Hopp 1eaeac
  	if (cp != NULL && cp < end)
Karsten Hopp 1eaeac
  	{
Karsten Hopp 1eaeac
! 	    EMSG2(_("E884: Function name cannot contain a colon: %s"), start);
Karsten Hopp 1eaeac
  	    goto theend;
Karsten Hopp 1eaeac
  	}
Karsten Hopp 1eaeac
      }
Karsten Hopp 1eaeac
*** ../vim-7.4.263/src/testdir/test_eval.in	2014-04-23 17:43:37.362948683 +0200
Karsten Hopp 1eaeac
--- src/testdir/test_eval.in	2014-04-23 20:36:50.494698246 +0200
Karsten Hopp 1eaeac
***************
Karsten Hopp 1eaeac
*** 144,150 ****
Karsten Hopp 1eaeac
  :delcommand AR
Karsten Hopp 1eaeac
  :call garbagecollect(1)
Karsten Hopp 1eaeac
  :"
Karsten Hopp 1eaeac
! :" function name includes a colon
Karsten Hopp 1eaeac
  :try
Karsten Hopp 1eaeac
  :func! g:test()
Karsten Hopp 1eaeac
  :echo "test"
Karsten Hopp 1eaeac
--- 144,150 ----
Karsten Hopp 1eaeac
  :delcommand AR
Karsten Hopp 1eaeac
  :call garbagecollect(1)
Karsten Hopp 1eaeac
  :"
Karsten Hopp 1eaeac
! :" function name not starting with capital
Karsten Hopp 1eaeac
  :try
Karsten Hopp 1eaeac
  :func! g:test()
Karsten Hopp 1eaeac
  :echo "test"
Karsten Hopp 1eaeac
***************
Karsten Hopp 1eaeac
*** 153,158 ****
Karsten Hopp 1eaeac
--- 153,167 ----
Karsten Hopp 1eaeac
  :$put =v:exception
Karsten Hopp 1eaeac
  :endtry
Karsten Hopp 1eaeac
  :"
Karsten Hopp 1eaeac
+ :" function name includes a colon
Karsten Hopp 1eaeac
+ :try
Karsten Hopp 1eaeac
+ :func! b:test()
Karsten Hopp 1eaeac
+ :echo "test"
Karsten Hopp 1eaeac
+ :endfunc
Karsten Hopp 1eaeac
+ :catch
Karsten Hopp 1eaeac
+ :$put =v:exception
Karsten Hopp 1eaeac
+ :endtry
Karsten Hopp 1eaeac
+ :"
Karsten Hopp 1eaeac
  :" function name folowed by #
Karsten Hopp 1eaeac
  :try
Karsten Hopp 1eaeac
  :func! test2() "#
Karsten Hopp 1eaeac
***************
Karsten Hopp 1eaeac
*** 162,167 ****
Karsten Hopp 1eaeac
--- 171,183 ----
Karsten Hopp 1eaeac
  :$put =v:exception
Karsten Hopp 1eaeac
  :endtry
Karsten Hopp 1eaeac
  :"
Karsten Hopp 1eaeac
+ :" function name starting with/without "g:", buffer-local funcref.
Karsten Hopp 1eaeac
+ :function! g:Foo()
Karsten Hopp 1eaeac
+ :  $put ='called Foo()'
Karsten Hopp 1eaeac
+ :endfunction
Karsten Hopp 1eaeac
+ :let b:my_func = function('Foo')
Karsten Hopp 1eaeac
+ :call b:my_func()
Karsten Hopp 1eaeac
+ :"
Karsten Hopp 1eaeac
  :/^start:/+1,$wq! test.out
Karsten Hopp 1eaeac
  :" vim: et ts=4 isk-=\: fmr=???,???
Karsten Hopp 1eaeac
  :call getchar()
Karsten Hopp 1eaeac
*** ../vim-7.4.263/src/testdir/test_eval.ok	2014-04-23 17:43:37.362948683 +0200
Karsten Hopp 1eaeac
--- src/testdir/test_eval.ok	2014-04-23 20:37:45.526696920 +0200
Karsten Hopp 1eaeac
***************
Karsten Hopp 1eaeac
*** 336,339 ****
Karsten Hopp 1eaeac
--- 336,341 ----
Karsten Hopp 1eaeac
  Executing call setreg(1, ["", "", [], ""])
Karsten Hopp 1eaeac
  Vim(call):E730: using List as a String
Karsten Hopp 1eaeac
  Vim(function):E128: Function name must start with a capital or "s:": g:test()
Karsten Hopp 1eaeac
+ Vim(function):E128: Function name must start with a capital or "s:": b:test()
Karsten Hopp 1eaeac
  Vim(function):E128: Function name must start with a capital or "s:": test2() "#
Karsten Hopp 1eaeac
+ called Foo()
Karsten Hopp 1eaeac
*** ../vim-7.4.263/src/version.c	2014-04-23 19:44:26.370774008 +0200
Karsten Hopp 1eaeac
--- src/version.c	2014-04-23 20:27:17.614712050 +0200
Karsten Hopp 1eaeac
***************
Karsten Hopp 1eaeac
*** 736,737 ****
Karsten Hopp 1eaeac
--- 736,739 ----
Karsten Hopp 1eaeac
  {   /* Add new patch number below this line */
Karsten Hopp 1eaeac
+ /**/
Karsten Hopp 1eaeac
+     264,
Karsten Hopp 1eaeac
  /**/
Karsten Hopp 1eaeac
Karsten Hopp 1eaeac
-- 
Karsten Hopp 1eaeac
In order for something to become clean, something else must become dirty;
Karsten Hopp 1eaeac
but you can get everything dirty without getting anything clean.
Karsten Hopp 1eaeac
Karsten Hopp 1eaeac
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 1eaeac
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 1eaeac
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 1eaeac
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///