]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0574: ex: wrong handling of commands after bar v9.1.0574
authorMohamed Akram <mohd.akram@outlook.com>
Sat, 13 Jul 2024 16:49:55 +0000 (18:49 +0200)
committerChristian Brabandt <cb@256bit.org>
Sat, 13 Jul 2024 16:49:55 +0000 (18:49 +0200)
Problem:  ex: wrong handling of commands after bar
Solution: for :append, :insert and :change use the text after the bar
          as input for those commands. This is what POSIX requests.
          (Mohamed Akram)

See the POSIX Spec:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ex.html#tag_20_40_13_03
Section 12.c

closes: #15229

Signed-off-by: Mohamed Akram <mohd.akram@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/insert.txt
src/ex_cmds.c
src/ex_docmd.c
src/testdir/test_ex_mode.vim
src/version.c

index 08bf4f327e0e618ee6bb7063c43b5f517489c45e..d48018f584b814198064357c17466538224d04a4 100644 (file)
@@ -1,4 +1,4 @@
-*insert.txt*    For Vim version 9.1.  Last change: 2024 Jul 12
+*insert.txt*    For Vim version 9.1.  Last change: 2024 Jul 13
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -1995,6 +1995,16 @@ These two commands will keep on asking for lines, until you type a line
 containing only a ".".  Watch out for lines starting with a backslash, see
 |line-continuation|.
 
+Text typed after a "|" command separator is used first. So the following
+command in ex mode: >
+       :a|one
+       two
+       .
+       :visual
+<appends the following text, after the cursor line: >
+       one
+       two
+<
 NOTE: These commands cannot be used with |:global| or |:vglobal|.
 ":append" and ":insert" don't work properly in between ":if" and
 ":endif", ":for" and ":endfor", ":while" and ":endwhile".
index 8143c2406055d9856f4a8548ec6fac53ced7ed4c..c365937983667477c8e6664225cee61ba242fbbd 100644 (file)
@@ -3360,7 +3360,13 @@ ex_append(exarg_T *eap)
                indent = get_indent_lnum(lnum);
        }
        ex_keep_indent = FALSE;
-       if (eap->ea_getline == NULL)
+       if (*eap->arg == '|')
+       {
+           // Get the text after the trailing bar.
+           theline = vim_strsave(eap->arg + 1);
+           *eap->arg = NUL;
+       }
+       else if (eap->ea_getline == NULL)
        {
            // No getline() function, use the lines that follow. This ends
            // when there is no more.
index 7ab1c69e526c3a5ec2472db866be68fe298d1ae1..614ba20805a80a8003a8978f2817eb7e9827107d 100644 (file)
@@ -5401,7 +5401,11 @@ separate_nextcmd(exarg_T *eap, int keep_backslash)
                    && in_vim9script()
                    && !(eap->argt & EX_NOTRLCOM)
                    && p > eap->cmd && VIM_ISWHITE(p[-1]))
-               || *p == '|' || *p == '\n')
+               || (*p == '|'
+                   && eap->cmdidx != CMD_append
+                   && eap->cmdidx != CMD_change
+                   && eap->cmdidx != CMD_insert)
+               || *p == '\n')
        {
            /*
             * We remove the '\' before the '|', unless EX_CTRLV is used
index b0e5d81a82a6e3068372c7f4846bd34b3930bdbc..c4f82d33ce5e6b766a6eae91e7af4a41917c7816 100644 (file)
@@ -364,4 +364,12 @@ func Test_implicit_print()
   bw!
 endfunc
 
+" Test inserting text after the trailing bar
+func Test_insert_after_trailing_bar()
+  new
+  call feedkeys("Qi|\nfoo\n.\na|bar\nbar\n.\nc|baz\n.", "xt")
+  call assert_equal(['', 'foo', 'bar', 'baz'], getline(1, '$'))
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index a4ae10f20817139df23513307d741898357cd079..25e38ca55da4ff4b7f1efd1238c43a437e27c360 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    574,
 /**/
     573,
 /**/