diff src/userfunc.c @ 26792:30d8377ea1b1 v8.2.3924

patch 8.2.3924: Vim9: no error if something follows :enddef Commit: https://github.com/vim/vim/commit/7473a84cf935f64ddd4ea7fe7eee0f9c51c50b60 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Dec 28 17:55:26 2021 +0000 patch 8.2.3924: Vim9: no error if something follows :enddef Problem: Vim9: no error if something follows :enddef in a nested function. Solution: Give an error. Move common code to a function.
author Bram Moolenaar <Bram@vim.org>
date Tue, 28 Dec 2021 19:00:05 +0100
parents 83b35c75c21a
children f40798bc2a50
line wrap: on
line diff
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -166,6 +166,35 @@ one_function_arg(
 }
 
 /*
+ * Handle line continuation in function arguments or body.
+ * Get a next line, store it in "eap" if appropriate and use "line_to_free" to
+ * handle freeing the line later.
+ */
+    static char_u *
+get_function_line(
+	exarg_T		*eap,
+	char_u		**line_to_free,
+	getline_opt_T	getline_options,
+	int		indent)
+{
+    char_u *theline;
+
+    if (eap->getline == NULL)
+	theline = getcmdline(':', 0L, indent, getline_options);
+    else
+	theline = eap->getline(':', eap->cookie, indent, getline_options);
+    if (theline != NULL)
+    {
+	if (*eap->cmdlinep == *line_to_free)
+	    *eap->cmdlinep = theline;
+	vim_free(*line_to_free);
+	*line_to_free = theline;
+    }
+
+    return theline;
+}
+
+/*
  * Get function arguments.
  * "argp" should point to just after the "(", possibly to white space.
  * "argp" is advanced just after "endchar".
@@ -212,16 +241,11 @@ get_function_args(
 	while (eap != NULL && eap->getline != NULL
 			 && (*p == NUL || (VIM_ISWHITE(*whitep) && *p == '#')))
 	{
-	    char_u *theline;
-
 	    // End of the line, get the next one.
-	    theline = eap->getline(':', eap->cookie, 0, TRUE);
+	    char_u *theline = get_function_line(eap, line_to_free, 0, TRUE);
+
 	    if (theline == NULL)
 		break;
-	    vim_free(*line_to_free);
-	    if (*eap->cmdlinep == *line_to_free)
-		*eap->cmdlinep = theline;
-	    *line_to_free = theline;
 	    whitep = (char_u *)" ";
 	    p = skipwhite(theline);
 	}
@@ -720,15 +744,8 @@ get_function_body(
 	}
 	else
 	{
-	    if (eap->getline == NULL)
-		theline = getcmdline(':', 0L, indent, getline_options);
-	    else
-		theline = eap->getline(':', eap->cookie, indent,
+	    theline = get_function_line(eap, line_to_free, indent,
 							      getline_options);
-	    if (*eap->cmdlinep == *line_to_free)
-		*eap->cmdlinep = theline;
-	    vim_free(*line_to_free);
-	    *line_to_free = theline;
 	}
 	if (KeyTyped)
 	    lines_left = Rows - 1;
@@ -827,7 +844,7 @@ get_function_body(
 			SOURCING_LNUM = sourcing_lnum_top
 							+ newlines->ga_len + 1;
 			if (eap->cmdidx == CMD_def)
-			    semsg(_(e_text_found_after_enddef_str), p);
+			    semsg(_(e_text_found_after_str_str), "enddef", p);
 			else
 			    give_warning2((char_u *)
 				   _("W22: Text found after :endfunction: %s"),