|
|
073263 |
To: vim_dev@googlegroups.com
|
|
|
073263 |
Subject: Patch 7.4.260
|
|
|
073263 |
Fcc: outbox
|
|
|
073263 |
From: Bram Moolenaar <Bram@moolenaar.net>
|
|
|
073263 |
Mime-Version: 1.0
|
|
|
073263 |
Content-Type: text/plain; charset=UTF-8
|
|
|
073263 |
Content-Transfer-Encoding: 8bit
|
|
|
073263 |
------------
|
|
|
073263 |
|
|
|
073263 |
Patch 7.4.260
|
|
|
073263 |
Problem: It is possible to define a function with a colon in the name. It
|
|
|
073263 |
is possible to define a function with a lower case character if a
|
|
|
073263 |
"#" appears after the name.
|
|
|
073263 |
Solution: Disallow using a colon other than with "s:". Ignore "#" after the
|
|
|
073263 |
name.
|
|
|
073263 |
Files: runtime/doc/eval.txt, src/eval.c, src/testdir/test_eval.in,
|
|
|
073263 |
src/testdir/test_eval.ok
|
|
|
073263 |
|
|
|
073263 |
|
|
|
073263 |
*** ../vim-7.4.259/runtime/doc/eval.txt 2014-04-05 19:44:36.891160723 +0200
|
|
|
073263 |
--- runtime/doc/eval.txt 2014-04-23 17:19:57.914982886 +0200
|
|
|
073263 |
***************
|
|
|
073263 |
*** 123,128 ****
|
|
|
073263 |
--- 123,129 ----
|
|
|
073263 |
:echo Fn()
|
|
|
073263 |
< *E704* *E705* *E707*
|
|
|
073263 |
A Funcref variable must start with a capital, "s:", "w:", "t:" or "b:". You
|
|
|
073263 |
+ can use "g:" but the following name must still start with a capital. You
|
|
|
073263 |
cannot have both a Funcref variable and a function with the same name.
|
|
|
073263 |
|
|
|
073263 |
A special case is defining a function and directly assigning its Funcref to a
|
|
|
073263 |
***************
|
|
|
073263 |
*** 6675,6680 ****
|
|
|
073263 |
--- 6691,6698 ----
|
|
|
073263 |
and autocommands defined in the script. It is also possible to call the
|
|
|
073263 |
function from a mapping defined in the script, but then |<SID>| must be used
|
|
|
073263 |
instead of "s:" when the mapping is expanded outside of the script.
|
|
|
073263 |
+ There are only script-local functions, no buffer-local or window-local
|
|
|
073263 |
+ functions.
|
|
|
073263 |
|
|
|
073263 |
*:fu* *:function* *E128* *E129* *E123*
|
|
|
073263 |
:fu[nction] List all functions and their arguments.
|
|
|
073263 |
***************
|
|
|
073263 |
*** 6698,6708 ****
|
|
|
073263 |
<
|
|
|
073263 |
See |:verbose-cmd| for more information.
|
|
|
073263 |
|
|
|
073263 |
! *E124* *E125* *E853*
|
|
|
073263 |
:fu[nction][!] {name}([arguments]) [range] [abort] [dict]
|
|
|
073263 |
Define a new function by the name {name}. The name
|
|
|
073263 |
must be made of alphanumeric characters and '_', and
|
|
|
073263 |
! must start with a capital or "s:" (see above).
|
|
|
073263 |
|
|
|
073263 |
{name} can also be a |Dictionary| entry that is a
|
|
|
073263 |
|Funcref|: >
|
|
|
073263 |
--- 6716,6727 ----
|
|
|
073263 |
<
|
|
|
073263 |
See |:verbose-cmd| for more information.
|
|
|
073263 |
|
|
|
073263 |
! *E124* *E125* *E853* *E884*
|
|
|
073263 |
:fu[nction][!] {name}([arguments]) [range] [abort] [dict]
|
|
|
073263 |
Define a new function by the name {name}. The name
|
|
|
073263 |
must be made of alphanumeric characters and '_', and
|
|
|
073263 |
! must start with a capital or "s:" (see above). Note
|
|
|
073263 |
! that using "b:" or "g:" is not allowed.
|
|
|
073263 |
|
|
|
073263 |
{name} can also be a |Dictionary| entry that is a
|
|
|
073263 |
|Funcref|: >
|
|
|
073263 |
*** ../vim-7.4.259/src/eval.c 2014-04-11 10:22:46.288219453 +0200
|
|
|
073263 |
--- src/eval.c 2014-04-23 17:37:23.890957682 +0200
|
|
|
073263 |
***************
|
|
|
073263 |
*** 808,814 ****
|
|
|
073263 |
static void list_func_head __ARGS((ufunc_T *fp, int indent));
|
|
|
073263 |
static ufunc_T *find_func __ARGS((char_u *name));
|
|
|
073263 |
static int function_exists __ARGS((char_u *name));
|
|
|
073263 |
! static int builtin_function __ARGS((char_u *name));
|
|
|
073263 |
#ifdef FEAT_PROFILE
|
|
|
073263 |
static void func_do_profile __ARGS((ufunc_T *fp));
|
|
|
073263 |
static void prof_sort_list __ARGS((FILE *fd, ufunc_T **sorttab, int st_len, char *title, int prefer_self));
|
|
|
073263 |
--- 808,814 ----
|
|
|
073263 |
static void list_func_head __ARGS((ufunc_T *fp, int indent));
|
|
|
073263 |
static ufunc_T *find_func __ARGS((char_u *name));
|
|
|
073263 |
static int function_exists __ARGS((char_u *name));
|
|
|
073263 |
! static int builtin_function __ARGS((char_u *name, int len));
|
|
|
073263 |
#ifdef FEAT_PROFILE
|
|
|
073263 |
static void func_do_profile __ARGS((ufunc_T *fp));
|
|
|
073263 |
static void prof_sort_list __ARGS((FILE *fd, ufunc_T **sorttab, int st_len, char *title, int prefer_self));
|
|
|
073263 |
***************
|
|
|
073263 |
*** 8489,8495 ****
|
|
|
073263 |
rettv->vval.v_number = 0;
|
|
|
073263 |
error = ERROR_UNKNOWN;
|
|
|
073263 |
|
|
|
073263 |
! if (!builtin_function(fname))
|
|
|
073263 |
{
|
|
|
073263 |
/*
|
|
|
073263 |
* User defined function.
|
|
|
073263 |
--- 8489,8495 ----
|
|
|
073263 |
rettv->vval.v_number = 0;
|
|
|
073263 |
error = ERROR_UNKNOWN;
|
|
|
073263 |
|
|
|
073263 |
! if (!builtin_function(fname, -1))
|
|
|
073263 |
{
|
|
|
073263 |
/*
|
|
|
073263 |
* User defined function.
|
|
|
073263 |
***************
|
|
|
073263 |
*** 21584,21589 ****
|
|
|
073263 |
--- 21584,21590 ----
|
|
|
073263 |
* Get the function name. There are these situations:
|
|
|
073263 |
* func normal function name
|
|
|
073263 |
* "name" == func, "fudi.fd_dict" == NULL
|
|
|
073263 |
+ * s:func script-local function name
|
|
|
073263 |
* dict.func new dictionary entry
|
|
|
073263 |
* "name" == NULL, "fudi.fd_dict" set,
|
|
|
073263 |
* "fudi.fd_di" == NULL, "fudi.fd_newkey" == func
|
|
|
073263 |
***************
|
|
|
073263 |
*** 22314,22324 ****
|
|
|
073263 |
lead += (int)STRLEN(sid_buf);
|
|
|
073263 |
}
|
|
|
073263 |
}
|
|
|
073263 |
! else if (!(flags & TFN_INT) && builtin_function(lv.ll_name))
|
|
|
073263 |
{
|
|
|
073263 |
! EMSG2(_("E128: Function name must start with a capital or contain a colon: %s"), lv.ll_name);
|
|
|
073263 |
goto theend;
|
|
|
073263 |
}
|
|
|
073263 |
name = alloc((unsigned)(len + lead + 1));
|
|
|
073263 |
if (name != NULL)
|
|
|
073263 |
{
|
|
|
073263 |
--- 22315,22338 ----
|
|
|
073263 |
lead += (int)STRLEN(sid_buf);
|
|
|
073263 |
}
|
|
|
073263 |
}
|
|
|
073263 |
! else if (!(flags & TFN_INT) && builtin_function(lv.ll_name, len))
|
|
|
073263 |
{
|
|
|
073263 |
! EMSG2(_("E128: Function name must start with a capital or \"s:\": %s"),
|
|
|
073263 |
! lv.ll_name);
|
|
|
073263 |
goto theend;
|
|
|
073263 |
}
|
|
|
073263 |
+ if (!skip)
|
|
|
073263 |
+ {
|
|
|
073263 |
+ char_u *cp = vim_strchr(lv.ll_name, ':');
|
|
|
073263 |
+
|
|
|
073263 |
+ if (cp != NULL && cp < end)
|
|
|
073263 |
+ {
|
|
|
073263 |
+ EMSG2(_("E884: Function name cannot contain a colon: %s"),
|
|
|
073263 |
+ lv.ll_name);
|
|
|
073263 |
+ goto theend;
|
|
|
073263 |
+ }
|
|
|
073263 |
+ }
|
|
|
073263 |
+
|
|
|
073263 |
name = alloc((unsigned)(len + lead + 1));
|
|
|
073263 |
if (name != NULL)
|
|
|
073263 |
{
|
|
|
073263 |
***************
|
|
|
073263 |
*** 22331,22337 ****
|
|
|
073263 |
STRCPY(name + 3, sid_buf);
|
|
|
073263 |
}
|
|
|
073263 |
mch_memmove(name + lead, lv.ll_name, (size_t)len);
|
|
|
073263 |
! name[len + lead] = NUL;
|
|
|
073263 |
}
|
|
|
073263 |
*pp = end;
|
|
|
073263 |
|
|
|
073263 |
--- 22345,22351 ----
|
|
|
073263 |
STRCPY(name + 3, sid_buf);
|
|
|
073263 |
}
|
|
|
073263 |
mch_memmove(name + lead, lv.ll_name, (size_t)len);
|
|
|
073263 |
! name[lead + len] = NUL;
|
|
|
073263 |
}
|
|
|
073263 |
*pp = end;
|
|
|
073263 |
|
|
|
073263 |
***************
|
|
|
073263 |
*** 22452,22458 ****
|
|
|
073263 |
translated_function_exists(name)
|
|
|
073263 |
char_u *name;
|
|
|
073263 |
{
|
|
|
073263 |
! if (builtin_function(name))
|
|
|
073263 |
return find_internal_func(name) >= 0;
|
|
|
073263 |
return find_func(name) != NULL;
|
|
|
073263 |
}
|
|
|
073263 |
--- 22466,22472 ----
|
|
|
073263 |
translated_function_exists(name)
|
|
|
073263 |
char_u *name;
|
|
|
073263 |
{
|
|
|
073263 |
! if (builtin_function(name, -1))
|
|
|
073263 |
return find_internal_func(name) >= 0;
|
|
|
073263 |
return find_func(name) != NULL;
|
|
|
073263 |
}
|
|
|
073263 |
***************
|
|
|
073263 |
*** 22500,22513 ****
|
|
|
073263 |
|
|
|
073263 |
/*
|
|
|
073263 |
* Return TRUE if "name" looks like a builtin function name: starts with a
|
|
|
073263 |
! * lower case letter and doesn't contain a ':' or AUTOLOAD_CHAR.
|
|
|
073263 |
*/
|
|
|
073263 |
static int
|
|
|
073263 |
! builtin_function(name)
|
|
|
073263 |
char_u *name;
|
|
|
073263 |
{
|
|
|
073263 |
! return ASCII_ISLOWER(name[0]) && vim_strchr(name, ':') == NULL
|
|
|
073263 |
! && vim_strchr(name, AUTOLOAD_CHAR) == NULL;
|
|
|
073263 |
}
|
|
|
073263 |
|
|
|
073263 |
#if defined(FEAT_PROFILE) || defined(PROTO)
|
|
|
073263 |
--- 22514,22533 ----
|
|
|
073263 |
|
|
|
073263 |
/*
|
|
|
073263 |
* Return TRUE if "name" looks like a builtin function name: starts with a
|
|
|
073263 |
! * lower case letter and doesn't contain AUTOLOAD_CHAR.
|
|
|
073263 |
! * "len" is the length of "name", or -1 for NUL terminated.
|
|
|
073263 |
*/
|
|
|
073263 |
static int
|
|
|
073263 |
! builtin_function(name, len)
|
|
|
073263 |
char_u *name;
|
|
|
073263 |
+ int len;
|
|
|
073263 |
{
|
|
|
073263 |
! char_u *p;
|
|
|
073263 |
!
|
|
|
073263 |
! if (!ASCII_ISLOWER(name[0]))
|
|
|
073263 |
! return FALSE;
|
|
|
073263 |
! p = vim_strchr(name, AUTOLOAD_CHAR);
|
|
|
073263 |
! return p == NULL || (len > 0 && p > name + len);
|
|
|
073263 |
}
|
|
|
073263 |
|
|
|
073263 |
#if defined(FEAT_PROFILE) || defined(PROTO)
|
|
|
073263 |
*** ../vim-7.4.259/src/testdir/test_eval.in 2014-04-05 21:28:50.667174384 +0200
|
|
|
073263 |
--- src/testdir/test_eval.in 2014-04-23 17:35:12.086960858 +0200
|
|
|
073263 |
***************
|
|
|
073263 |
*** 144,149 ****
|
|
|
073263 |
--- 144,167 ----
|
|
|
073263 |
:delcommand AR
|
|
|
073263 |
:call garbagecollect(1)
|
|
|
073263 |
:"
|
|
|
073263 |
+ :" function name includes a colon
|
|
|
073263 |
+ :try
|
|
|
073263 |
+ :func! g:test()
|
|
|
073263 |
+ :echo "test"
|
|
|
073263 |
+ :endfunc
|
|
|
073263 |
+ :catch
|
|
|
073263 |
+ :$put =v:exception
|
|
|
073263 |
+ :endtry
|
|
|
073263 |
+ :"
|
|
|
073263 |
+ :" function name folowed by #
|
|
|
073263 |
+ :try
|
|
|
073263 |
+ :func! test2() "#
|
|
|
073263 |
+ :echo "test2"
|
|
|
073263 |
+ :endfunc
|
|
|
073263 |
+ :catch
|
|
|
073263 |
+ :$put =v:exception
|
|
|
073263 |
+ :endtry
|
|
|
073263 |
+ :"
|
|
|
073263 |
:/^start:/+1,$wq! test.out
|
|
|
073263 |
:" vim: et ts=4 isk-=\: fmr=???,???
|
|
|
073263 |
:call getchar()
|
|
|
073263 |
*** ../vim-7.4.259/src/testdir/test_eval.ok 2014-04-05 21:28:50.667174384 +0200
|
|
|
073263 |
--- src/testdir/test_eval.ok 2014-04-23 17:36:34.602958870 +0200
|
|
|
073263 |
***************
|
|
|
073263 |
*** 335,337 ****
|
|
|
073263 |
--- 335,339 ----
|
|
|
073263 |
Vim(call):E883: search pattern and expression register may not contain two or more lines
|
|
|
073263 |
Executing call setreg(1, ["", "", [], ""])
|
|
|
073263 |
Vim(call):E730: using List as a String
|
|
|
073263 |
+ Vim(function):E128: Function name must start with a capital or "s:": g:test()
|
|
|
073263 |
+ Vim(function):E128: Function name must start with a capital or "s:": test2() "#
|
|
|
073263 |
*** ../vim-7.4.259/src/version.c 2014-04-23 12:52:36.499369426 +0200
|
|
|
073263 |
--- src/version.c 2014-04-23 17:17:50.994985945 +0200
|
|
|
073263 |
***************
|
|
|
073263 |
*** 736,737 ****
|
|
|
073263 |
--- 736,739 ----
|
|
|
073263 |
{ /* Add new patch number below this line */
|
|
|
073263 |
+ /**/
|
|
|
073263 |
+ 260,
|
|
|
073263 |
/**/
|
|
|
073263 |
|
|
|
073263 |
--
|
|
|
073263 |
From "know your smileys":
|
|
|
073263 |
;-0 Can't find shift key
|
|
|
073263 |
,-9 Kann Umschalttaste nicht finden
|
|
|
073263 |
|
|
|
073263 |
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
|
|
|
073263 |
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
|
|
|
073263 |
\\\ an exciting new programming language -- http://www.Zimbu.org ///
|
|
|
073263 |
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|