diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-08-30 18:17:15 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-08-30 18:17:15 +0100 |
commit | 9c8f94636b3610b898ffbbd07f6b75866d16cbca (patch) | |
tree | a169b57ddfe9c6605272da81183f1041437e0140 | |
parent | 3e518a8ec74065aedd67d352c93d6ae6be550316 (diff) | |
download | vim-git-9c8f94636b3610b898ffbbd07f6b75866d16cbca.tar.gz |
patch 9.0.0332: overwrite check may block BufWriteCmdv9.0.0332
Problem: Overwrite check may block BufWriteCmd.
Solution: Do not use overwrite check when 'buftype' is "acwrite".
(closes #11011)
-rw-r--r-- | src/ex_cmds.c | 13 | ||||
-rw-r--r-- | src/testdir/test_autocmd.vim | 15 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 26 insertions, 4 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c index d9f1c993d..1cf090cd8 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -2094,12 +2094,17 @@ check_overwrite( /* * Write to another file or b_flags set or not writing the whole file: * overwriting only allowed with '!'. + * If "other" is FALSE and bt_nofilename(buf) is TRUE, this must be + * writing an "acwrite" buffer to the same file as its b_ffname, and + * buf_write() will only allow writing with BufWriteCmd autocommands, + * so there is no need for an overwrite check. */ if ( (other - || (buf->b_flags & BF_NOTEDITED) - || ((buf->b_flags & BF_NEW) - && vim_strchr(p_cpo, CPO_OVERNEW) == NULL) - || (buf->b_flags & BF_READERR)) + || (!bt_nofilename(buf) + && ((buf->b_flags & BF_NOTEDITED) + || ((buf->b_flags & BF_NEW) + && vim_strchr(p_cpo, CPO_OVERNEW) == NULL) + || (buf->b_flags & BF_READERR)))) && !p_wa && vim_fexists(ffname)) { diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim index e4b76dba5..b3b4ec5a6 100644 --- a/src/testdir/test_autocmd.vim +++ b/src/testdir/test_autocmd.vim @@ -1922,6 +1922,21 @@ func Test_BufReadCmd() au! BufWriteCmd endfunc +func Test_BufWriteCmd() + autocmd BufWriteCmd Xbufwritecmd let g:written = 1 + new + file Xbufwritecmd + set buftype=acwrite + call mkdir('Xbufwritecmd') + write + " BufWriteCmd should be triggered even if a directory has the same name + call assert_equal(1, g:written) + call delete('Xbufwritecmd', 'd') + unlet g:written + au! BufWriteCmd + bwipe! +endfunc + func SetChangeMarks(start, end) exe a:start .. 'mark [' exe a:end .. 'mark ]' diff --git a/src/version.c b/src/version.c index 2f409cf5a..68d0e791a 100644 --- a/src/version.c +++ b/src/version.c @@ -708,6 +708,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 332, +/**/ 331, /**/ 330, |