diff src/testdir/test_autocmd.vim @ 19836:c32b295af9c5 v8.2.0474

patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd Commit: https://github.com/vim/vim/commit/0fff44152d06e6b662ad4bef172af07a041d2f3f Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 29 16:06:29 2020 +0200 patch 8.2.0474: cannot use :write when using a plugin with BufWriteCmd Problem: Cannot use :write when using a plugin with BufWriteCmd. Solution: Reset BF_NOTEDITED after BufWriteCmd. (closes https://github.com/vim/vim/issues/5807)
author Bram Moolenaar <Bram@vim.org>
date Sun, 29 Mar 2020 16:15:03 +0200
parents 0927df746554
children 2c4d9ca33769
line wrap: on
line diff
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -1536,6 +1536,40 @@ func Test_Cmd_Autocmds()
   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 ]'