diff options
author | Jan Edmund Lazo <janedmundlazo@hotmail.com> | 2018-07-07 08:16:07 -0400 |
---|---|---|
committer | Jan Edmund Lazo <janedmundlazo@hotmail.com> | 2018-07-07 10:17:13 -0400 |
commit | 0ac67853b90deaf9726e5cc035fc639f04677eb7 (patch) | |
tree | 7cd01f06311aafdfee71e00517a66cbf96c5a505 | |
parent | b5c0031d4eab3a8721904bbbf85c199c9c8d2bce (diff) | |
download | rneovim-0ac67853b90deaf9726e5cc035fc639f04677eb7.tar.gz rneovim-0ac67853b90deaf9726e5cc035fc639f04677eb7.tar.bz2 rneovim-0ac67853b90deaf9726e5cc035fc639f04677eb7.zip |
vim-patch: finish port of 8.0.0{654,663,667}
Fix ex_function so that :endfunction passes the test.
Remove variables, added in 60c025267265ba4bfc2abd34ea02b13bd5c0e63f.
-rw-r--r-- | src/nvim/eval.c | 58 | ||||
-rw-r--r-- | src/nvim/message.c | 6 |
2 files changed, 36 insertions, 28 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 2ea0c0116b..e6880f58e7 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -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) - theline = getcmdline(':', 0L, indent); - else - theline = eap->getline(':', eap->cookie, indent); - if (KeyTyped) + } else { + xfree(line_to_free); + if (eap->getline == NULL) { + theline = getcmdline(':', 0L, indent); + } else { + theline = eap->getline(':', eap->cookie, indent); + } + 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); - } - goto erret; + 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); } - 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; diff --git a/src/nvim/message.c b/src/nvim/message.c index 097c8b16e4..9d4d421941 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -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". */ |