eval: Allow running next command after :endfunction

This will still error out on `:endfunction | next`, but defining many functions
in one `:execute` should be possible.
This commit is contained in:
ZyX 2017-06-20 17:36:56 +03:00
parent d5839770ee
commit 60c0252672

View File

@ -19765,10 +19765,12 @@ void ex_function(exarg_T *eap)
/* When there is a line break use what follows for the function body. /* When there is a line break use what follows for the function body.
* Makes 'exe "func Test()\n...\nendfunc"' work. */ * Makes 'exe "func Test()\n...\nendfunc"' work. */
if (*p == '\n') const char *const end = (const char *)p + STRLEN(p);
if (*p == '\n') {
line_arg = p + 1; line_arg = p + 1;
else if (*p != NUL && *p != '"' && !eap->skip && !did_emsg) } else if (*p != NUL && *p != '"' && !eap->skip && !did_emsg) {
EMSG(_(e_trailing)); emsgf(_(e_trailing));
}
/* /*
* Read the body of the function, until ":endfunction" is found. * Read the body of the function, until ":endfunction" is found.
@ -19845,12 +19847,26 @@ void ex_function(exarg_T *eap)
if (*p == '!') { if (*p == '!') {
p++; p++;
} }
p += strspn((const char *)p, " \t\r\n"); const char *const comment_start = strchr((const char *)p, '"');
if (*p != NUL && *p != '"') { const char *const endfunc_end = (comment_start
? strchr(comment_start, '\n')
: strpbrk((const char *)p, "\n|"));
p = (endfunc_end
? (char_u *)endfunc_end
: p + STRLEN(p));
if (*p == '|') {
emsgf(_(e_trailing2), p); emsgf(_(e_trailing2), p);
if (line_arg == NULL) {
xfree(theline);
}
goto erret;
} }
if (line_arg == NULL) { if (line_arg == NULL) {
xfree(theline); xfree(theline);
} else {
if ((const char *)p < end) {
eap->nextcmd = p + 1;
}
} }
break; break;
} }