To:
[email protected]
Subject: Patch 5.6a.003
Fcc: outbox
From: Bram Moolenaar <
[email protected]>
------------
Patch 5.6a.003
Problem: Defining a function inside a function didn't give an error
message. A missing ":endfunction" doesn't give an error message.
Solution: Allow defining a function inside a function.
Files: src/eval.c, runtime/doc/eval.txt
*** ../vim-5.6a.2/src/eval.c Mon Dec 20 09:59:08 1999
--- src/eval.c Tue Dec 21 12:32:17 1999
***************
*** 4737,4742 ****
--- 4782,4788 ----
int flags = 0;
struct ufunc *fp;
int indent;
+ int nesting;
/*
* ":function" without argument: list functions.
***************
*** 4881,4886 ****
--- 4927,4933 ----
cmdline_row = msg_row;
}
indent = 2;
+ nesting = 0;
for (;;)
{
msg_scroll = TRUE;
***************
*** 4891,4901 ****
theline = getline(':', cookie, indent);
lines_left = Rows - 1;
if (theline == NULL)
goto erret;
for (p = theline; vim_iswhite(*p) || *p == ':'; ++p)
;
! if (STRNCMP(p, "endf", 4) == 0)
{
vim_free(theline);
break;
--- 4938,4951 ----
theline = getline(':', cookie, indent);
lines_left = Rows - 1;
if (theline == NULL)
+ {
+ EMSG("Missing :endfunction");
goto erret;
+ }
for (p = theline; vim_iswhite(*p) || *p == ':'; ++p)
;
! if (STRNCMP(p, "endf", 4) == 0 && nesting-- == 0)
{
vim_free(theline);
break;
***************
*** 4904,4909 ****
--- 4954,4974 ----
indent -= 2;
else if (STRNCMP(p, "if", 2) == 0 || STRNCMP(p, "wh", 2) == 0)
indent += 2;
+ /* Check for defining a function inside this function. */
+ if (STRNCMP(p, "fu", 2) == 0)
+ {
+ p = skipwhite(skiptowhite(p));
+ if (isupper(*p))
+ {
+ while (isalpha(*p) || isdigit(*p) || *p == '_')
+ ++p;
+ if (*skipwhite(p) == '(')
+ {
+ ++nesting;
+ indent += 2;
+ }
+ }
+ }
if (ga_grow(&newlines, 1) == FAIL)
goto erret;
((char_u **)(newlines.ga_data))[newlines.ga_len] = theline;
*** ../vim-5.6a.2/runtime/doc/eval.txt Mon Dec 20 09:59:29 1999
--- runtime/doc/eval.txt Tue Dec 21 12:20:00 1999
***************
*** 1,4 ****
! *eval.txt* For Vim version 5.6a. Last change: 1999 Dec 04
VIM REFERENCE MANUAL by Bram Moolenaar
--- 1,4 ----
! *eval.txt* For Vim version 5.6a. Last change: 1999 Dec 21
VIM REFERENCE MANUAL by Bram Moolenaar
***************
*** 195,201 ****
results in the mathematical difference (comparing byte values), not
necessarily the alphabetical difference in the local language.
! When using the opreators with a trailing '#", or the short version and
'ignorecase' is off, the comparing is done with strcmp().
When using the operators with a trailing '?', or the short version and
--- 195,201 ----
results in the mathematical difference (comparing byte values), not
necessarily the alphabetical difference in the local language.
! When using the operators with a trailing '#", or the short version and
'ignorecase' is off, the comparing is done with strcmp().
When using the operators with a trailing '?', or the short version and
***************
*** 1432,1440 ****
==============================================================================
5. Defining functions *user-functions*
! New functions can be defined. These can be called with "Name()", just like
! builtin functions. The name must start with an uppercase letter, to avoid
! confusion with builtin functions.
*:fu* *:function*
:fu[nction] List all functions and their arguments.
--- 1432,1444 ----
==============================================================================
5. Defining functions *user-functions*
! New functions can be defined. These can be called just like builtin
! functions.
!
! The function name must start with an uppercase letter, to avoid confusion with
! builtin functions. To prevent from using the same name in different scripts
! avoid obvious, short names. A good habit is to start the function name with
! the name of the script, e.g., "HTMLcolor()".
*:fu* *:function*
:fu[nction] List all functions and their arguments.
***************
*** 1461,1467 ****
It is also possible to define a function without any
arguments. You must still supply the () then.
The body of the function follows in the next lines,
! until ":endfunction".
When a function by this name already exists and [!] is
not used an error message is given. When [!] is used,
an existing function is silently replaced.
--- 1465,1472 ----
It is also possible to define a function without any
arguments. You must still supply the () then.
The body of the function follows in the next lines,
! until the matching |:endfunction|. It is allowed to
! define another function inside a function body.
When a function by this name already exists and [!] is
not used an error message is given. When [!] is used,
an existing function is silently replaced.
*** ../vim-5.6a.2/src/version.c Tue Dec 21 12:21:20 1999
--- src/version.c Tue Dec 21 12:21:44 1999
***************
*** 420,421 ****
--- 420,423 ----
{ /* Add new patch number below this line */
+ /**/
+ 3,
/**/
--
So when I saw the post to comp.editors, I rushed over to the FTP site to
grab it. So I yank apart the tarball, light x candles, where x= the
vim version multiplied by the md5sum of the source divided by the MAC of
my NIC (8A3FA78155A8A1D346C3C4A), put on black robes, dim the lights,
wave a dead chicken over the hard drive, and summon the power of GNU GCC
with the magic words "make config ; make!".
[Jason Spence, compiling Vim 5.0]
--/-/---- Bram Moolenaar ----
[email protected] ----
[email protected] ---\-\--
\ \ www.vim.org/iccf www.moolenaar.net www.vim.org / /