]> granicus.if.org Git - vim/commitdiff
patch 8.2.2242: Vim9: bar line continuation does not work at script level v8.2.2242
authorBram Moolenaar <Bram@vim.org>
Tue, 29 Dec 2020 10:15:01 +0000 (11:15 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 29 Dec 2020 10:15:01 +0000 (11:15 +0100)
Problem:    Vim9: line continuation with bar does not work at script level.
Solution:   Check for Vim9 script.

src/ex_docmd.c
src/scriptfile.c
src/structs.h
src/testdir/test_vim9_cmd.vim
src/userfunc.c
src/version.c

index 91d56d71ffdfbb8cccdbc3a56036f5f303b67d53..dc9ea165f953b80d9d16c80bd8bda95d68ddaa0e 100644 (file)
@@ -889,7 +889,8 @@ do_cmdline(
 #else
                    0
 #endif
-                   , TRUE)) == NULL)
+                   , in_vim9script() ? GETLINE_CONCAT_CONTBAR
+                                              : GETLINE_CONCAT_CONT)) == NULL)
            {
                // Don't call wait_return for aborted command line.  The NULL
                // returned for the end of a sourced file or executed function
index eceefd729b65352b2bba6cbaae6962f021e78d6b..adc5caffc9ffe666f6731db58c5c748ee56c34c6 100644 (file)
@@ -1741,8 +1741,8 @@ getsourceline(
     char_u             *p;
     int                        do_vim9_all = in_vim9script()
                                              && options == GETLINE_CONCAT_ALL;
-    int                        do_vim9_cont = do_vim9_all
-                                        || options == GETLINE_CONCAT_CONTDEF;
+    int                        do_bar_cont = do_vim9_all
+                                        || options == GETLINE_CONCAT_CONTBAR;
 
 #ifdef FEAT_EVAL
     // If breakpoints have been added/deleted need to check for it.
@@ -1797,7 +1797,7 @@ getsourceline(
                              || (p[0] == '"' && p[1] == '\\' && p[2] == ' ')
                              || (do_vim9_all && (*p == NUL
                                                     || vim9_comment_start(p)))
-                             || (do_vim9_cont && p[0] == '|' && p[1] != '|')))
+                             || (do_bar_cont && p[0] == '|' && p[1] != '|')))
        {
            garray_T    ga;
 
@@ -1817,7 +1817,7 @@ getsourceline(
                if (sp->nextline == NULL)
                    break;
                p = skipwhite(sp->nextline);
-               if (*p == '\\' || (do_vim9_cont && p[0] == '|' && p[1] != '|'))
+               if (*p == '\\' || (do_bar_cont && p[0] == '|' && p[1] != '|'))
                {
                    // Adjust the growsize to the current length to speed up
                    // concatenating many lines.
index ba42e331ba5cbb2b839709cb83b3dc6d5ec77566..102be0eaaf3450fc78c338f15c1c7a8d939b49de 100644 (file)
@@ -1565,8 +1565,8 @@ typedef void (*cfunc_free_T)(void *state);
 // type of getline() last argument
 typedef enum {
     GETLINE_NONE,          // do not concatenate any lines
-    GETLINE_CONCAT_CONT,    // concatenate continuation lines in Vim9 script
-    GETLINE_CONCAT_CONTDEF, // concatenate continuation lines always
+    GETLINE_CONCAT_CONT,    // concatenate continuation lines with backslash
+    GETLINE_CONCAT_CONTBAR, // concatenate continuation lines with \ and |
     GETLINE_CONCAT_ALL     // concatenate continuation and Vim9 # comment lines
 } getline_opt_T;
 
index 710af413c58e1728be75e10a3023c346e8b3edcc..ed0c7dda30380f269e7e22b1c64b97abee5b311b 100644 (file)
@@ -536,6 +536,37 @@ def Test_command_modifiers_keep()
   quit!
 enddef
 
+def Test_bar_line_continuation()
+  var lines =<< trim END
+      au BufNewFile Xfile g:readFile = 1
+          | g:readExtra = 2
+      g:readFile = 0
+      g:readExtra = 0
+      edit Xfile
+      assert_equal(1, g:readFile)
+      assert_equal(2, g:readExtra)
+      bwipe!
+      au! BufNewFile
+
+      au BufNewFile Xfile g:readFile = 1
+          | g:readExtra = 2
+          | g:readMore = 3
+      g:readFile = 0
+      g:readExtra = 0
+      g:readMore = 0
+      edit Xfile
+      assert_equal(1, g:readFile)
+      assert_equal(2, g:readExtra)
+      assert_equal(3, g:readMore)
+      bwipe!
+      au! BufNewFile
+      unlet g:readFile
+      unlet g:readExtra
+      unlet g:readMore
+  END
+  CheckDefAndScriptSuccess(lines)
+enddef
+
 def Test_command_modifier_other()
   new Xsomefile
   setline(1, 'changed')
@@ -548,33 +579,15 @@ def Test_command_modifier_other()
   bwipe!
 
   au BufNewFile Xfile g:readFile = 1
-      | g:readExtra = 2
   g:readFile = 0
-  g:readExtra = 0
   edit Xfile
   assert_equal(1, g:readFile)
-  assert_equal(2, g:readExtra)
   bwipe!
   g:readFile = 0
   noautocmd edit Xfile
   assert_equal(0, g:readFile)
   au! BufNewFile
-
-  au BufNewFile Xfile g:readFile = 1
-      | g:readExtra = 2
-      | g:readMore = 3
-  g:readFile = 0
-  g:readExtra = 0
-  g:readMore = 0
-  edit Xfile
-  assert_equal(1, g:readFile)
-  assert_equal(2, g:readExtra)
-  assert_equal(3, g:readMore)
-  bwipe!
-  au! BufNewFile
   unlet g:readFile
-  unlet g:readExtra
-  unlet g:readMore
 
   noswapfile edit XnoSwap
   assert_equal(0, &l:swapfile)
index 85941d1ea1fe16324b4b4393ea6b9cd988ce45a8..9393b62cc1210aba0740b33bf1864d0daa32ca11 100644 (file)
@@ -3292,7 +3292,7 @@ define_function(exarg_T *eap, char_u *name_arg)
     nesting = 0;
     nesting_def[nesting] = (eap->cmdidx == CMD_def);
     getline_options = eap->cmdidx == CMD_def
-                               ? GETLINE_CONCAT_CONTDEF : GETLINE_CONCAT_CONT;
+                               ? GETLINE_CONCAT_CONTBAR : GETLINE_CONCAT_CONT;
     for (;;)
     {
        if (KeyTyped)
@@ -3368,7 +3368,7 @@ define_function(exarg_T *eap, char_u *name_arg)
                    VIM_CLEAR(skip_until);
                    VIM_CLEAR(heredoc_trimmed);
                    getline_options = eap->cmdidx == CMD_def
-                               ? GETLINE_CONCAT_CONTDEF : GETLINE_CONCAT_CONT;
+                               ? GETLINE_CONCAT_CONTBAR : GETLINE_CONCAT_CONT;
                    is_heredoc = FALSE;
                }
            }
index e9327f19b02e1fa40240b1e80cabeb881d56c829..ee0d9878caf574c1e70a0976b03e1fca39815842 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2242,
 /**/
     2241,
 /**/