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 #3391) Add tests for 'autowrite'.
}
/*
- * 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)
return;
FOR_ALL_BUFFERS(buf)
- if (bufIsChanged(buf) && !buf->b_p_ro)
+ if (bufIsChanged(buf) && !buf->b_p_ro && !bt_dontwrite(buf))
{
bufref_T bufref;
throw 'Skipped: /dev/stdout is not writable'
endif
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
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 334,
/**/
333,
/**/