Re: BufReadPost: surprising behavior?
- Alan G Isaac wrote:
> I'm going to try again to get some help on this byThe reason is that reloading the file is done by reading the new file
> showing that e! does not produce the same effect as
> Vim loading a file.
> Save the following five lines as temp.vim
> function! Protect()
> %s@^\s*save\s\+.\+@save\ from\ old\ file@e
> g/save/co 0
> au BufReadPost temp9.txt call Protect()
> Save the following single line of text as temp9.txt
> Source your file temp.vim.
> :so temp.vim
> Go to the buffer for temp9.txt and
> i. change the single line to
> save me
> ii. do *not* save this buffer
> Give the command
> As expected the buffer now contains the single line:
> Now for my problem.
> Change this single line in the buffer back to
> save me
> but again do *not* save this buffer.
> This time open another instance of Vim (or any other editor).
> In a new buffer put in the single line
> and then save this as temp9.txt
> (Ignore the resulting warnings.)
> Now return to the first instance of Vim.
> It notices that temp9.txt has been changed and offers to load it.
> Load it.
> Note the unexpected result!
> This time there are two lines in the buffer instead of one.
> The function operates on the text that
> was in the buffer *before* the load (as well as on the
> new text that is loaded).
contents into the existing buffer and then deleting the old lines. This
avoids that the current buffer contents is lost when reading the file
fails for some reason.
Obviously your BufRead autocommands change the old text unexpectedly.
The code isn't prepared for this. I'll think about a solution to avoid
From "know your smileys":
/// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
/// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\
\\\ Project leader for A-A-P -- http://www.a-a-p.org ///
\\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///
- On Sun, 02 Jun 2002 20:25:29 +0200 Bram Moolenaar <Bram@...> wrote:
> The reason is that reloading the file is done by reading the new fileThanks!
> contents into the existing buffer and then deleting the old lines. This
> avoids that the current buffer contents is lost when reading the file
> fails for some reason.
> Obviously your BufRead autocommands change the old text unexpectedly.
> The code isn't prepared for this. I'll think about a solution to avoid
> this problem.