]> granicus.if.org Git - vim/commitdiff
patch 8.1.0334: 'autowrite' takes effect when buffer is not to be written v8.1.0334
authorBram Moolenaar <Bram@vim.org>
Thu, 30 Aug 2018 11:07:17 +0000 (13:07 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 30 Aug 2018 11:07:17 +0000 (13:07 +0200)
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'.

src/ex_cmds2.c
src/testdir/test_writefile.vim
src/version.c

index cb046357dbb5a2c49333cff619dc82c35d903c83..89effa1417e494b5b863bbd32f3053dcfcb121f1 100644 (file)
@@ -2041,7 +2041,7 @@ autowrite(buf_T *buf, int forceit)
 }
 
 /*
- * 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)
@@ -2051,7 +2051,7 @@ 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;
 
index 672ddd3a74706f48501f2826c4f66d62073d446e..8e621b3cb2a7cd32afeabdc46f0d0e69989ca2b1 100644 (file)
@@ -112,3 +112,41 @@ func Test_writefile_sync_dev_stdout()
     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
index c2f64d37ab84de67762d606d59eb60c985ae4d8d..db1f8e2c811a4d817cb4a6631679e6d059802b24 100644 (file)
@@ -794,6 +794,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    334,
 /**/
     333,
 /**/