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

View File

@ -1061,6 +1061,7 @@ func Test_echo_and_string()
let l = split(result, "\n")
call assert_equal(["{'a': [], 'b': []}",
\ "{'a': [], 'b': []}"], l)
endfunc
"-------------------------------------------------------------------------------
" 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 clear = helpers.clear
local funcs = helpers.funcs
local dedent = helpers.dedent
local redir_exec = helpers.redir_exec
before_each(clear)
local function check_nofunc(fname)
eq(0, funcs.exists('*' .. fname))
end
local function check_func(fname, body, indent)
if type(body) == 'number' then
body = ('return %i'):format(body)
@ -141,12 +136,12 @@ describe(':endfunction', function()
]]))
check_func('F1', 42)
end)
it('errors out on an uncommented bar', function()
eq('\nE488: Trailing characters: | echo 42', redir_exec([[
it('accepts uncommented bar', function()
eq('\n42', redir_exec([[
function F1()
endfunction | echo 42
]]))
check_nofunc('F1')
check_func('F1')
end)
it('allows running multiple commands', function()
eq('\n2', redir_exec([[