Ben Fritz wrote:

> On Oct 17, 10:07 am, Ben Fritz <[email protected]> wrote:
> >
> > I can verify this using Vim 7.2.79 (latest from the package manager on
> > Ubuntu Jaunty). I'll check in the latest patched version I have on
> > Windows sometime later.
> >
> > The really interesting thing is, if you uncomment the :w but not
> > the :q, you can see that the original buffer gets modified as
> > expected, but the written file only modifies the first line, as shown.
> >
> > A slightly more intuitive script does the same:
> > 1
> > let @c = ':s/\(.*\)/\11/|a^Mhello^M.^M|+|@c'
> > @c
> > w! new.txt- Hide quoted text -
> >
> 
> One last iteration to allow copy and paste, used to verify the
> behavior in gvim 7.2.264 on MS Windows:
> 
> 1
> let @c = ":s/\\(.*\\)/\\11/|a\<CR>hello\<CR>.\<CR>|+|@c"
> @c
> w! new.txt
> 
> Sourcing this script in gvim -N -u NONE with buffer contents:
> 
> a
> b
> c
> d
> 
> Results in a buffer:
> 
> a1
> hello
> b1
> hello
> c1
> hello
> d1
> hello
> 
> But results in a file new.txt with contents:
> 
> a1
> hello
> b
> c
> d
> 
> I'm completely stumped. Somehow the :w! command seems to occur before
> the recursive call of the @c macro.

The @c command puts the command to be executed in the typeahead buffer.
The problem is the CR in the command, combined with the "|" character.
You can make it work by changing it to:

   let @c = ":s/\\(.*\\)/\\11/|a\<CR>hello\<CR>.\<CR>:+|@c"

You get an "invalid range" error, because it reaches end of file.

It should actually work like this:

   let @c = ":s/\\(.*\\)/\\11/|a\<CR>hello\<CR>.\<CR>+\<CR>@c"

After fixing the use of typeahead it then recurses until it breaks,
since there is no check for being in the last line of the file.

This is the patch:

*** ../vim-7.2.267/src/ex_docmd.c       2009-09-30 13:23:57.000000000 +0200
--- src/ex_docmd.c      2009-10-28 12:06:54.000000000 +0100
***************
*** 8358,8363 ****
--- 8358,8364 ----
      exarg_T   *eap;
  {
      int               c;
+     int               prev_len = typebuf.tb_len;
  
      curwin->w_cursor.lnum = eap->line2;
  
***************
*** 8383,8393 ****
  
        /*
         * Execute from the typeahead buffer.
!        * Originally this didn't check for the typeahead buffer to be empty,
!        * thus could read more Ex commands from stdin.  It's not clear why,
!        * it is certainly unexpected.
         */
!       while ((!stuff_empty() || typebuf.tb_len > 0) && vpeekc() == ':')
            (void)do_cmdline(NULL, getexline, NULL, DOCMD_NOWAIT|DOCMD_VERBOSE);
  
        exec_from_reg = save_efr;
--- 8384,8393 ----
  
        /*
         * Execute from the typeahead buffer.
!        * Continue until the stuff buffer is empty and all added characters
!        * have been consumed.
         */
!       while (!stuff_empty() || typebuf.tb_len > prev_len)
            (void)do_cmdline(NULL, getexline, NULL, DOCMD_NOWAIT|DOCMD_VERBOSE);
  
        exec_from_reg = save_efr;


-- 
If your life is a hard drive,
Christ can be your backup.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to