diff src/scriptfile.c @ 23392:517fca70e084 v8.2.2239

patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient Commit: https://github.com/vim/vim/commit/dcc58e031ded8b846a39146112b9b075cbb977d9 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Dec 28 20:53:21 2020 +0100 patch 8.2.2239: Vim9: concatenating lines with backslash is inconvenient Problem: Vim9: concatenating lines with backslash is inconvenient. Solution: Support concatenating lines starting with '|', useful for :autocmd, :command, etc. (closes #6702)
author Bram Moolenaar <Bram@vim.org>
date Mon, 28 Dec 2020 21:00:04 +0100
parents 9a5f12b36273
children 40f824f5c7c7
line wrap: on
line diff
--- a/src/scriptfile.c
+++ b/src/scriptfile.c
@@ -1739,6 +1739,10 @@ getsourceline(
     struct source_cookie *sp = (struct source_cookie *)cookie;
     char_u		*line;
     char_u		*p;
+    int			do_vim9_all = in_vim9script()
+					      && options == GETLINE_CONCAT_ALL;
+    int			do_vim9_cont = do_vim9_all
+					 || options == GETLINE_CONCAT_CONTDEF;
 
 #ifdef FEAT_EVAL
     // If breakpoints have been added/deleted need to check for it.
@@ -1785,17 +1789,15 @@ getsourceline(
 	// backslash. We always need to read the next line, keep it in
 	// sp->nextline.
 	/* Also check for a comment in between continuation lines: "\ */
-	// Also check for a Vim9 comment and empty line.
+	// Also check for a Vim9 comment, empty line, line starting with '|',
+	// but not "||".
 	sp->nextline = get_one_sourceline(sp);
 	if (sp->nextline != NULL
 		&& (*(p = skipwhite(sp->nextline)) == '\\'
 			      || (p[0] == '"' && p[1] == '\\' && p[2] == ' ')
-#ifdef FEAT_EVAL
-			      || (in_vim9script()
-				      && options == GETLINE_CONCAT_ALL
-				      && (*p == NUL || vim9_comment_start(p)))
-#endif
-			      ))
+			      || (do_vim9_all && (*p == NUL
+						     || vim9_comment_start(p)))
+			      || (do_vim9_cont && p[0] == '|' && p[1] != '|')))
 	{
 	    garray_T    ga;
 
@@ -1803,6 +1805,11 @@ getsourceline(
 	    ga_concat(&ga, line);
 	    if (*p == '\\')
 		ga_concat(&ga, p + 1);
+	    else if (*p == '|')
+	    {
+		ga_concat(&ga, (char_u *)" ");
+		ga_concat(&ga, p);
+	    }
 	    for (;;)
 	    {
 		vim_free(sp->nextline);
@@ -1810,7 +1817,7 @@ getsourceline(
 		if (sp->nextline == NULL)
 		    break;
 		p = skipwhite(sp->nextline);
-		if (*p == '\\')
+		if (*p == '\\' || (do_vim9_cont && p[0] == '|' && p[1] != '|'))
 		{
 		    // Adjust the growsize to the current length to speed up
 		    // concatenating many lines.
@@ -1821,15 +1828,16 @@ getsourceline(
 			else
 			    ga.ga_growsize = ga.ga_len;
 		    }
-		    ga_concat(&ga, p + 1);
+		    if (*p == '\\')
+			ga_concat(&ga, p + 1);
+		    else
+		    {
+			ga_concat(&ga, (char_u *)" ");
+			ga_concat(&ga, p);
+		    }
 		}
 		else if (!(p[0] == '"' && p[1] == '\\' && p[2] == ' ')
-#ifdef FEAT_EVAL
-			&& !(in_vim9script()
-				&& options == GETLINE_CONCAT_ALL
-				&& (*p == NUL || vim9_comment_start(p)))
-#endif
-			)
+		     && !(do_vim9_all && (*p == NUL || vim9_comment_start(p))))
 		    break;
 		/* drop a # comment or "\ comment line */
 	    }