aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-07-15 17:39:06 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-07-15 18:27:21 +0800
commit0cf5cd1ac9c8ec31c1d2f1b1a6585153a45fc4e9 (patch)
tree783afc0e6f1cc54610b20fe27aeb26625158b5af
parent4a64cdafd64198d3607fabaed8fc54e473614269 (diff)
downloadrneovim-0cf5cd1ac9c8ec31c1d2f1b1a6585153a45fc4e9.tar.gz
rneovim-0cf5cd1ac9c8ec31c1d2f1b1a6585153a45fc4e9.tar.bz2
rneovim-0cf5cd1ac9c8ec31c1d2f1b1a6585153a45fc4e9.zip
vim-patch:8.2.0403: when 'buftype' is "nofile" there is no overwrite check
Problem: When 'buftype' is "nofile" there is no overwrite check. Solution: Also check for existing file when 'buftype' is set. (closes vim/vim#5807) https://github.com/vim/vim/commit/a3a9c8ef697bbf6f640cde99710b6f534f29f77d Nvim doesn't have buftype=popup and doesn't allow buftype=terminal for non-terminal buffer.
-rw-r--r--src/nvim/ex_cmds.c7
-rw-r--r--src/nvim/testdir/test_options.vim11
2 files changed, 12 insertions, 6 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 28665136fc..28e1893b31 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -1980,17 +1980,14 @@ theend:
/// @return OK if it's OK, FAIL if it is not.
int check_overwrite(exarg_T *eap, buf_T *buf, char *fname, char *ffname, int other)
{
- /*
- * write to other file or b_flags set or not writing the whole file:
- * overwriting only allowed with '!'
- */
+ // Write to another file or b_flags set or not writing the whole file:
+ // overwriting only allowed with '!'
if ((other
|| (buf->b_flags & BF_NOTEDITED)
|| ((buf->b_flags & BF_NEW)
&& vim_strchr(p_cpo, CPO_OVERNEW) == NULL)
|| (buf->b_flags & BF_READERR))
&& !p_wa
- && !bt_nofilename(buf)
&& os_path_exists((char_u *)ffname)) {
if (!eap->forceit && !eap->append) {
#ifdef UNIX
diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim
index 9f89d47758..3de84d2ae9 100644
--- a/src/nvim/testdir/test_options.vim
+++ b/src/nvim/testdir/test_options.vim
@@ -741,7 +741,16 @@ func Test_buftype()
call setline(1, ['L1'])
set buftype=nowrite
call assert_fails('write', 'E382:')
- close!
+
+ " for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
+ for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'prompt']
+ exe 'set buftype=' .. val
+ call writefile(['something'], 'XBuftype')
+ call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
+ endfor
+
+ call delete('XBuftype')
+ bwipe!
endfunc
" Test for the 'shellquote' option