On Tue, Aug 30, 2011 at 4:56 AM, Bram Moolenaar <[email protected]> wrote:
>
> 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))

It fixes the problem.  Thank you.

-- 
Yukihiro Nakadaira - [email protected]

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

Raspunde prin e-mail lui