Re: why does :save not work with -stdin-

2007-06-06 Thread Bram Moolenaar

Edward L. Fox wrote:

 On 6/6/07, Mohsin [EMAIL PROTECTED] wrote:
  I usually do search like this:
 
  $ grep  Word *.* | vim -u myvimrc -
 
  $ cat myvimrc
 
 :autocmd StdinReadPost * :sav! /tmp/x
 
  but when I quit :q, vim always asks me to save the file again,
  why is the file marked as modified?
 
  I tried all combinations of flags, but can't get vim to
  mark the file as saved,
 
 It's a bug. Here is the patch. Please test it carefully, thanks very
 much for reporting this to me. I'll ask Bram to add it to the official
 release soon.
 
 Index: buffer.c
 ===
 --- buffer.c(revision 296)
 +++ buffer.c(working copy)
 @@ -171,14 +171,6 @@
 /* Put the cursor on the first line. */
 curwin-w_cursor.lnum = 1;
 curwin-w_cursor.col = 0;
 -#ifdef FEAT_AUTOCMD
 -# ifdef FEAT_EVAL
 -   apply_autocmds_retval(EVENT_STDINREADPOST, NULL, NULL, FALSE,
 -   curbuf, retval);
 -# else
 -   apply_autocmds(EVENT_STDINREADPOST, NULL, NULL, FALSE, curbuf);
 -# endif
 -#endif
 }
  }
 
 @@ -207,6 +199,18 @@
 unchanged(curbuf, FALSE);
  save_file_ff(curbuf);  /* keep this fileformat */
 
 +#ifdef FEAT_AUTOCMD
 +if (read_stdin)
 +{
 +# ifdef FEAT_EVAL
 +apply_autocmds_retval(EVENT_STDINREADPOST, NULL, NULL, FALSE,
 +   curbuf, retval);
 +# else
 +apply_autocmds(EVENT_STDINREADPOST, NULL, NULL, FALSE, curbuf);
 +# endif
 +}
 +#endif
 +
  /* require ! to overwrite the file, because it wasn't read completely 
 */
  #ifdef FEAT_EVAL
  if (aborting())

Instead of moving the autocommands, it might be better to move the call
to changed() to before the autocommands (with the if that checks for
read_stdin).  The readfile() call also invokes the ReadPost
autocommands, this keeps it consistent.

-- 
hundred-and-one symptoms of being an internet addict:
162. You go outside and look for a brightness knob to turn down the sun.

 /// 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///


why does :save not work with -stdin-

2007-06-05 Thread Mohsin

I usually do search like this:

$ grep  Word *.* | vim -u myvimrc -

$ cat myvimrc

  :autocmd StdinReadPost * :sav! /tmp/x

but when I quit :q, vim always asks me to save the file again,
why is the file marked as modified?

I tried all combinations of flags, but can't get vim to
mark the file as saved,

any insights appreciated,
mosh.


Re: why does :save not work with -stdin-

2007-06-05 Thread Edward L. Fox

Hi Mohsin,

On 6/6/07, Mohsin [EMAIL PROTECTED] wrote:

I usually do search like this:

$ grep  Word *.* | vim -u myvimrc -

$ cat myvimrc

   :autocmd StdinReadPost * :sav! /tmp/x

but when I quit :q, vim always asks me to save the file again,
why is the file marked as modified?

I tried all combinations of flags, but can't get vim to
mark the file as saved,


It's a bug. Here is the patch. Please test it carefully, thanks very
much for reporting this to me. I'll ask Bram to add it to the official
release soon.

Index: buffer.c
===
--- buffer.c(revision 296)
+++ buffer.c(working copy)
@@ -171,14 +171,6 @@
   /* Put the cursor on the first line. */
   curwin-w_cursor.lnum = 1;
   curwin-w_cursor.col = 0;
-#ifdef FEAT_AUTOCMD
-# ifdef FEAT_EVAL
-   apply_autocmds_retval(EVENT_STDINREADPOST, NULL, NULL, FALSE,
-   curbuf, retval);
-# else
-   apply_autocmds(EVENT_STDINREADPOST, NULL, NULL, FALSE, curbuf);
-# endif
-#endif
   }
}

@@ -207,6 +199,18 @@
   unchanged(curbuf, FALSE);
save_file_ff(curbuf);  /* keep this fileformat */

+#ifdef FEAT_AUTOCMD
+if (read_stdin)
+{
+# ifdef FEAT_EVAL
+apply_autocmds_retval(EVENT_STDINREADPOST, NULL, NULL, FALSE,
+   curbuf, retval);
+# else
+apply_autocmds(EVENT_STDINREADPOST, NULL, NULL, FALSE, curbuf);
+# endif
+}
+#endif
+
/* require ! to overwrite the file, because it wasn't read completely */
#ifdef FEAT_EVAL
if (aborting())



any insights appreciated,
mosh.



Regards,

Edward L. Fox