Merge #8702 from janlazo/nvim-8.0.0654

This commit is contained in:
Justin M. Keyes 2018-07-08 00:08:21 +02:00 committed by GitHub
commit 57fafcea23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 36 deletions

View File

@ -19584,6 +19584,7 @@ static const char *find_option_end(const char **const arg, int *const opt_flags)
void ex_function(exarg_T *eap) void ex_function(exarg_T *eap)
{ {
char_u *theline; char_u *theline;
char_u *line_to_free = NULL;
int c; int c;
int saved_did_emsg; int saved_did_emsg;
int saved_wait_return = need_wait_return; int saved_wait_return = need_wait_return;
@ -19815,7 +19816,6 @@ 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. */
const char *const end = (const char *)p + STRLEN(p);
if (*p == '\n') { 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) {
@ -19865,12 +19865,18 @@ void ex_function(exarg_T *eap)
*p = NUL; *p = NUL;
line_arg = p + 1; line_arg = p + 1;
} }
} else if (eap->getline == NULL) } else {
theline = getcmdline(':', 0L, indent); xfree(line_to_free);
else if (eap->getline == NULL) {
theline = eap->getline(':', eap->cookie, indent); theline = getcmdline(':', 0L, indent);
if (KeyTyped) } else {
theline = eap->getline(':', eap->cookie, indent);
}
line_to_free = theline;
}
if (KeyTyped) {
lines_left = Rows - 1; lines_left = Rows - 1;
}
if (theline == NULL) { if (theline == NULL) {
EMSG(_("E126: Missing :endfunction")); EMSG(_("E126: Missing :endfunction"));
goto erret; goto erret;
@ -19902,25 +19908,24 @@ void ex_function(exarg_T *eap)
if (*p == '!') { if (*p == '!') {
p++; p++;
} }
const char *const comment_start = strchr((const char *)p, '"'); char_u *nextcmd = NULL;
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 == '|') { if (*p == '|') {
emsgf(_(e_trailing2), p); nextcmd = p + 1;
if (line_arg == NULL) { } else if (line_arg != NULL && *skipwhite(line_arg) != NUL) {
xfree(theline); nextcmd = line_arg;
} } else if (*p != NUL && *p != '"' && p_verbose > 0) {
goto erret; give_warning2((char_u *)_("W22: Text found after :endfunction: %s"),
p, true);
} }
if (line_arg == NULL) { if (nextcmd != NULL) {
xfree(theline); // Another command follows. If the line came from "eap" we
} else { // can simply point into it, otherwise we need to change
if ((const char *)p < end) { // "eap->cmdlinep".
eap->nextcmd = p + 1; eap->nextcmd = nextcmd;
if (line_to_free != NULL) {
xfree(*eap->cmdlinep);
*eap->cmdlinep = line_to_free;
line_to_free = NULL;
} }
} }
break; break;
@ -19997,11 +20002,7 @@ void ex_function(exarg_T *eap)
* allocates 250 bytes per line, this saves 80% on average. The cost * allocates 250 bytes per line, this saves 80% on average. The cost
* is an extra alloc/free. */ * is an extra alloc/free. */
p = vim_strsave(theline); p = vim_strsave(theline);
if (line_arg == NULL) ((char_u **)(newlines.ga_data))[newlines.ga_len++] = p;
xfree(theline);
theline = p;
((char_u **)(newlines.ga_data))[newlines.ga_len++] = theline;
/* Add NULL lines for continuation lines, so that the line count is /* Add NULL lines for continuation lines, so that the line count is
* equal to the index in the growarray. */ * equal to the index in the growarray. */
@ -20166,6 +20167,7 @@ errret_2:
ga_clear_strings(&newlines); ga_clear_strings(&newlines);
ret_free: ret_free:
xfree(skip_until); xfree(skip_until);
xfree(line_to_free);
xfree(fudi.fd_newkey); xfree(fudi.fd_newkey);
xfree(name); xfree(name);
did_emsg |= saved_did_emsg; did_emsg |= saved_did_emsg;

View File

@ -2763,6 +2763,12 @@ void give_warning(char_u *message, bool hl) FUNC_ATTR_NONNULL_ARG(1)
--no_wait_return; --no_wait_return;
} }
void give_warning2(char_u *const message, char_u *const a1, bool hl)
{
vim_snprintf((char *)IObuff, IOSIZE, (char *)message, a1);
give_warning(IObuff, hl);
}
/* /*
* Advance msg cursor to column "col". * Advance msg cursor to column "col".
*/ */

View File

@ -1061,6 +1061,7 @@ func Test_echo_and_string()
let l = split(result, "\n") let l = split(result, "\n")
call assert_equal(["{'a': [], 'b': []}", call assert_equal(["{'a': [], 'b': []}",
\ "{'a': [], 'b': []}"], l) \ "{'a': [], 'b': []}"], l)
endfunc
"------------------------------------------------------------------------------- "-------------------------------------------------------------------------------
" Test 94: 64-bit Numbers {{{1 " Test 94: 64-bit Numbers {{{1

View File

@ -2,16 +2,11 @@ local helpers = require('test.functional.helpers')(after_each)
local eq = helpers.eq local eq = helpers.eq
local clear = helpers.clear local clear = helpers.clear
local funcs = helpers.funcs
local dedent = helpers.dedent local dedent = helpers.dedent
local redir_exec = helpers.redir_exec local redir_exec = helpers.redir_exec
before_each(clear) before_each(clear)
local function check_nofunc(fname)
eq(0, funcs.exists('*' .. fname))
end
local function check_func(fname, body, indent) local function check_func(fname, body, indent)
if type(body) == 'number' then if type(body) == 'number' then
body = ('return %i'):format(body) body = ('return %i'):format(body)
@ -141,12 +136,12 @@ describe(':endfunction', function()
]])) ]]))
check_func('F1', 42) check_func('F1', 42)
end) end)
it('errors out on an uncommented bar', function() it('accepts uncommented bar', function()
eq('\nE488: Trailing characters: | echo 42', redir_exec([[ eq('\n42', redir_exec([[
function F1() function F1()
endfunction | echo 42 endfunction | echo 42
]])) ]]))
check_nofunc('F1') check_func('F1')
end) end)
it('allows running multiple commands', function() it('allows running multiple commands', function()
eq('\n2', redir_exec([[ eq('\n2', redir_exec([[