aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-03-30 02:06:48 -0400
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2020-04-13 12:00:33 -0400
commit87334c00e0568226f0deeb6de90c759c8d1ec464 (patch)
treeb7a8f3ea7db9b13f773084521a00e088d87e556b
parentb8ddca6554c312026d2d8e480b0c0fb09a26a3f0 (diff)
downloadrneovim-87334c00e0568226f0deeb6de90c759c8d1ec464.tar.gz
rneovim-87334c00e0568226f0deeb6de90c759c8d1ec464.tar.bz2
rneovim-87334c00e0568226f0deeb6de90c759c8d1ec464.zip
vim-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 vim/vim#5807) https://github.com/vim/vim/commit/0fff44152d06e6b662ad4bef172af07a041d2f3f
-rw-r--r--src/nvim/fileio.c22
-rw-r--r--src/nvim/testdir/test_autocmd.vim34
2 files changed, 53 insertions, 3 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index e5845e0749..88e9390c65 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -407,11 +407,27 @@ readfile(
if (newfile) {
if (apply_autocmds_exarg(EVENT_BUFREADCMD, NULL, sfname,
- FALSE, curbuf, eap))
- return aborting() ? FAIL : OK;
+ false, curbuf, eap)) {
+ int status = OK;
+
+ if (aborting()) {
+ status = FAIL;
+ }
+
+ // 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))
+ false, NULL, eap)) {
return aborting() ? FAIL : OK;
+ }
curbuf->b_op_start = pos;
}
diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim
index e03a0b7de3..954e5d875f 100644
--- a/src/nvim/testdir/test_autocmd.vim
+++ b/src/nvim/testdir/test_autocmd.vim
@@ -1072,6 +1072,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 ]'