From b6e83ba28469345ee145ab6da2c4ef7f3285d726 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Mon, 3 Sep 2018 21:06:59 -0400 Subject: [PATCH] vim-patch:8.1.0334: 'autowrite' takes effect when buffer is not to be written Problem: 'autowrite' takes effect when buffer is not to be written. Solution: Don't write buffers that are not supposed to be written. (Even Q Jones, closes vim/vim#3391) Add tests for 'autowrite'. https://github.com/vim/vim/commit/8c9e7b00f6566dc41e794ef11c93d93b034c7134 --- src/nvim/ex_cmds2.c | 4 +-- src/nvim/testdir/test_writefile.vim | 38 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index f5822535ba..6e695a8897 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -1209,7 +1209,7 @@ int autowrite(buf_T *buf, int forceit) return r; } -/// flush all buffers, except the ones that are readonly +/// Flush all buffers, except the ones that are readonly or are never written. void autowrite_all(void) { if (!(p_aw || p_awa) || !p_write) { @@ -1217,7 +1217,7 @@ void autowrite_all(void) } FOR_ALL_BUFFERS(buf) { - if (bufIsChanged(buf) && !buf->b_p_ro) { + if (bufIsChanged(buf) && !buf->b_p_ro && !bt_dontwrite(buf)) { bufref_T bufref; set_bufref(&bufref, buf); (void)buf_write_all(buf, false); diff --git a/src/nvim/testdir/test_writefile.vim b/src/nvim/testdir/test_writefile.vim index f297f8eb2f..06f9d03554 100644 --- a/src/nvim/testdir/test_writefile.vim +++ b/src/nvim/testdir/test_writefile.vim @@ -75,3 +75,41 @@ func Test_nowrite_quit_split() endif bwipe Xfile endfunc + +func Test_writefile_autowrite() + set autowrite + new + next Xa Xb Xc + call setline(1, 'aaa') + next + call assert_equal(['aaa'], readfile('Xa')) + call setline(1, 'bbb') + call assert_fails('edit XX') + call assert_false(filereadable('Xb')) + + set autowriteall + edit XX + call assert_equal(['bbb'], readfile('Xb')) + + bwipe! + call delete('Xa') + call delete('Xb') + set noautowrite +endfunc + +func Test_writefile_autowrite_nowrite() + set autowrite + new + next Xa Xb Xc + set buftype=nowrite + call setline(1, 'aaa') + let buf = bufnr('%') + " buffer contents silently lost + edit XX + call assert_false(filereadable('Xa')) + rewind + call assert_equal('', getline(1)) + + bwipe! + set noautowrite +endfunc