]> granicus.if.org Git - vim/commitdiff
patch 8.2.1129: Vim9: bar not recognized after not compiled command v8.2.1129
authorBram Moolenaar <Bram@vim.org>
Sun, 5 Jul 2020 12:57:51 +0000 (14:57 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 5 Jul 2020 12:57:51 +0000 (14:57 +0200)
Problem:    Vim9: bar not recognized after not compiled command.
Solution:   Check for bar for commands where this is possible. (closes #6391)

src/testdir/test_vim9_cmd.vim
src/version.c
src/vim9compile.c

index 27d2b3a7cd9915396292ed1f7d4726ef6662b3d3..53d964fa8b4fe589f4edbc4b0c25a3d6dd8400ad 100644 (file)
@@ -2,6 +2,7 @@
 
 source check.vim
 source vim9.vim
+source view_util.vim
 
 def Test_edit_wildcards()
   let filename = 'Xtest'
@@ -207,5 +208,38 @@ def Test_method_call_linebreak()
   CheckScriptSuccess(lines)
 enddef
 
+def Test_bar_after_command()
+  def RedrawAndEcho()
+    let x = 'did redraw'
+    redraw | echo x
+  enddef
+  RedrawAndEcho()
+  assert_match('did redraw', Screenline(&lines))
+
+  if has('unix')
+    # bar in filter write command does not start new command
+    def WriteToShell()
+      new
+      setline(1, 'some text')
+      w !cat | cat > Xoutfile
+      bwipe!
+    enddef
+    WriteToShell()
+    assert_equal(['some text'], readfile('Xoutfile'))
+    delete('Xoutfile')
+
+    # bar in filter read command does not start new command
+    def ReadFromShell()
+      new
+      r! echo hello there | cat > Xoutfile
+      r !echo again | cat >> Xoutfile
+      bwipe!
+    enddef
+    ReadFromShell()
+    assert_equal(['hello there', 'again'], readfile('Xoutfile'))
+    delete('Xoutfile')
+  endif
+enddef
+
 
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
index 880051efa6069c5ef19db4ae5829fc8dd806c88b..d079d290960203e05bef8b453b2609e708745a1d 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1129,
 /**/
     1128,
 /**/
index 9c2eaf43292347d004bc5c180946e4a653ad00fa..5c3d08d30f707660f35843de3795d907f27848ae 100644 (file)
@@ -6562,12 +6562,33 @@ compile_exec(char_u *line, exarg_T *eap, cctx_T *cctx)
 {
     char_u  *p;
     int            has_expr = FALSE;
+    char_u  *nextcmd = (char_u *)"";
 
     if (cctx->ctx_skip == SKIP_YES)
        goto theend;
 
     if (eap->cmdidx >= 0 && eap->cmdidx < CMD_SIZE)
-       has_expr = (excmd_get_argt(eap->cmdidx) & (EX_XFILE | EX_EXPAND));
+    {
+       long    argt = excmd_get_argt(eap->cmdidx);
+       int     usefilter = FALSE;
+
+       has_expr = argt & (EX_XFILE | EX_EXPAND);
+
+       // If the command can be followed by a bar, find the bar and truncate
+       // it, so that the following command can be compiled.
+       // The '|' is overwritten with a NUL, it is put back below.
+       if ((eap->cmdidx == CMD_write || eap->cmdidx == CMD_read)
+                                                          && *eap->arg == '!')
+           // :w !filter or :r !filter or :r! filter
+           usefilter = TRUE;
+       if ((argt & EX_TRLBAR) && !usefilter)
+       {
+           separate_nextcmd(eap);
+           if (eap->nextcmd != NULL)
+               nextcmd = eap->nextcmd;
+       }
+    }
+
     if (eap->cmdidx == CMD_syntax && STRNCMP(eap->arg, "include ", 8) == 0)
     {
        // expand filename in "syntax include [@group] filename"
@@ -6626,7 +6647,14 @@ compile_exec(char_u *line, exarg_T *eap, cctx_T *cctx)
        generate_EXEC(cctx, line);
 
 theend:
-    return (char_u *)"";
+    if (*nextcmd != NUL)
+    {
+       // the parser expects a pointer to the bar, put it back
+       --nextcmd;
+       *nextcmd = '|';
+    }
+
+    return nextcmd;
 }
 
 /*