diff options
author | ZyX <kp-pav@yandex.ru> | 2017-06-20 17:36:56 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-06-20 18:36:17 +0300 |
commit | 60c025267265ba4bfc2abd34ea02b13bd5c0e63f (patch) | |
tree | 896a6ea37c2d76266374fe620b7e74bd1c5e4763 | |
parent | d5839770eee97a6f41c3b165a34a97127c7a6169 (diff) | |
download | rneovim-60c025267265ba4bfc2abd34ea02b13bd5c0e63f.tar.gz rneovim-60c025267265ba4bfc2abd34ea02b13bd5c0e63f.tar.bz2 rneovim-60c025267265ba4bfc2abd34ea02b13bd5c0e63f.zip |
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.
-rw-r--r-- | src/nvim/eval.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index c424cfcd80..18aa5bf763 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -19765,10 +19765,12 @@ 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. */ - if (*p == '\n') + 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) - EMSG(_(e_trailing)); + } else if (*p != NUL && *p != '"' && !eap->skip && !did_emsg) { + emsgf(_(e_trailing)); + } /* * Read the body of the function, until ":endfunction" is found. @@ -19845,12 +19847,26 @@ void ex_function(exarg_T *eap) if (*p == '!') { p++; } - p += strspn((const char *)p, " \t\r\n"); - if (*p != NUL && *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)); + if (*p == '|') { emsgf(_(e_trailing2), p); + if (line_arg == NULL) { + xfree(theline); + } + goto erret; } if (line_arg == NULL) { xfree(theline); + } else { + if ((const char *)p < end) { + eap->nextcmd = p + 1; + } } break; } |