Patch 8.2.0474 (after 8.2.0403)
Problem:    Cannot use :write when using a plugin with BufWriteCmd.
Solution:   Reset BF_NOTEDITED after BufWriteCmd. (closes #5807)
Files:      src/fileio.c, src/testdir/test_autocmd.vim


*** ../vim-8.2.0473/src/fileio.c        2020-02-26 16:15:31.068386966 +0100
--- src/fileio.c        2020-03-29 16:00:15.562716595 +0200
***************
*** 261,271 ****
        {
            if (apply_autocmds_exarg(EVENT_BUFREADCMD, NULL, sfname,
                                                          FALSE, curbuf, eap))
  #ifdef FEAT_EVAL
!               return aborting() ? FAIL : OK;
! #else
!               return OK;
  #endif
        }
        else if (apply_autocmds_exarg(EVENT_FILEREADCMD, sfname, sfname,
                                                            FALSE, NULL, eap))
--- 261,281 ----
        {
            if (apply_autocmds_exarg(EVENT_BUFREADCMD, NULL, sfname,
                                                          FALSE, curbuf, eap))
+           {
+               int status = OK;
  #ifdef FEAT_EVAL
!               if (aborting())
!                   status = FAIL;
  #endif
+               // The BufReadCmd code usually uses ":read" to get the text and
+               // perhaps ":file" to change the buffer name. But we should
+               // consider this to work like ":edit", thus reset the
+               // BF_NOTEDITED flag.  Then ":write" will work to overwrite the
+               // same file.
+               if (status == OK)
+                   curbuf->b_flags &= ~BF_NOTEDITED;
+               return status;
+           }
        }
        else if (apply_autocmds_exarg(EVENT_FILEREADCMD, sfname, sfname,
                                                            FALSE, NULL, eap))
*** ../vim-8.2.0473/src/testdir/test_autocmd.vim        2020-03-23 
19:28:40.599056151 +0100
--- src/testdir/test_autocmd.vim        2020-03-29 15:59:32.154874410 +0200
***************
*** 1536,1541 ****
--- 1536,1575 ----
    enew!
  endfunc
  
+ func s:ReadFile()
+   setl noswapfile nomodified
+   let filename = resolve(expand("<afile>:p"))
+   execute 'read' fnameescape(filename)
+   1d_
+   exe 'file' fnameescape(filename)
+   setl buftype=acwrite
+ endfunc
+ 
+ func s:WriteFile()
+   let filename = resolve(expand("<afile>:p"))
+   setl buftype=
+   noautocmd execute 'write' fnameescape(filename)
+   setl buftype=acwrite
+   setl nomodified
+ endfunc
+ 
+ func Test_BufReadCmd()
+   autocmd BufReadCmd *.test call s:ReadFile()
+   autocmd BufWriteCmd *.test call s:WriteFile()
+ 
+   call writefile(['one', 'two', 'three'], 'Xcmd.test')
+   edit Xcmd.test
+   call assert_match('Xcmd.test" line 1 of 3', execute('file'))
+   normal! Gofour
+   write
+   call assert_equal(['one', 'two', 'three', 'four'], readfile('Xcmd.test'))
+ 
+   bwipe!
+   call delete('Xcmd.test')
+   au! BufReadCmd
+   au! BufWriteCmd
+ endfunc
+ 
  func SetChangeMarks(start, end)
    exe a:start. 'mark ['
    exe a:end. 'mark ]'
*** ../vim-8.2.0473/src/version.c       2020-03-29 15:12:11.937482074 +0200
--- src/version.c       2020-03-29 15:45:54.537965770 +0200
***************
*** 740,741 ****
--- 740,743 ----
  {   /* Add new patch number below this line */
+ /**/
+     474,
  /**/

-- 
It's not hard to meet expenses, they're everywhere.

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

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202003291407.02TE705v009288%40masaka.moolenaar.net.

Raspunde prin e-mail lui