Yukihiro Nakadaira wrote:
> When using BufWriteCmd, :undo command doesn't set 'modified' flag properly.
>
> Steps to reproduce:
>
> $ vim -u NONE -N
> :edit sample
> :autocmd BufWriteCmd <buffer> setlocal nomodified
> :put ='1st' " The 1st change of buffer.
> :write
> :put ='2nd' " The 2nd change of buffer.
> :put ='3rd' " The 3rd change of buffer.
> :write
> :set modified? " => nomodified
> :undo
> :set modified? " => modified
> :undo
> :set modified? " => nomodified (I expected "modified")
>
> For instance, editing remote file with netrw has same problem.
Yeah, ":set nomodifed" only changes the flag for the current buffer
state. ":write" actually also changes older buffer states to be marked
as 'modified', since the reference point, the file, has changed.
I think we can nearly do it correctly to check the 'modified' state
before and after the BufWriteCmd. If it went from 'modified' to
'nomodified' then we can do the same correction for undo info as
":write" does.
Here is a patch to try out:
*** ../vim-7.3.289/src/fileio.c 2011-07-20 18:29:33.000000000 +0200
--- src/fileio.c 2011-08-29 21:49:27.000000000 +0200
***************
*** 3342,3349 ****
}
else if (reset_changed && whole)
{
! if (!(did_cmd = apply_autocmds_exarg(EVENT_BUFWRITECMD,
! sfname, sfname, FALSE, curbuf, eap)))
{
#ifdef FEAT_QUICKFIX
if (overwriting && bt_nofile(curbuf))
--- 3342,3363 ----
}
else if (reset_changed && whole)
{
! int was_changed = curbufIsChanged();
!
! did_cmd = apply_autocmds_exarg(EVENT_BUFWRITECMD,
! sfname, sfname, FALSE, curbuf, eap);
! if (did_cmd)
! {
! if (was_changed && !curbufIsChanged())
! {
! /* Written everything correctly and BufWriteCmd has reset
! * 'modified': Correct the undo information so that an
! * undo now sets 'modified'. */
! u_unchanged(curbuf);
! u_update_save_nr(curbuf);
! }
! }
! else
{
#ifdef FEAT_QUICKFIX
if (overwriting && bt_nofile(curbuf))
--
BODY: I'm not dead!
CART DRIVER: 'Ere. He says he's not dead.
LARGE MAN: Yes he is.
BODY: I'm not!
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php