diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-07-15 19:26:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-15 19:26:32 +0800 |
commit | b9f15caf5ca879841afe582f68838af208b86142 (patch) | |
tree | 783afc0e6f1cc54610b20fe27aeb26625158b5af | |
parent | 564d99c89a3d9a236df758d320cc38abc50215ec (diff) | |
parent | 0cf5cd1ac9c8ec31c1d2f1b1a6585153a45fc4e9 (diff) | |
download | rneovim-b9f15caf5ca879841afe582f68838af208b86142.tar.gz rneovim-b9f15caf5ca879841afe582f68838af208b86142.tar.bz2 rneovim-b9f15caf5ca879841afe582f68838af208b86142.zip |
Merge pull request #19375 from zeertzjq/vim-8.2.0403
vim-patch:8.1.1547,8.2.0403: when 'buftype' is "nofile" there is no overwrite check
-rw-r--r-- | src/nvim/buffer.c | 13 | ||||
-rw-r--r-- | src/nvim/eval/funcs.c | 2 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 7 | ||||
-rw-r--r-- | src/nvim/ex_session.c | 6 | ||||
-rw-r--r-- | src/nvim/fileio.c | 30 | ||||
-rw-r--r-- | src/nvim/popupmnu.c | 3 | ||||
-rw-r--r-- | src/nvim/testdir/test_options.vim | 11 |
7 files changed, 42 insertions, 30 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 09f5ebe217..f937450107 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -5271,9 +5271,9 @@ bool bt_terminal(const buf_T *const buf) return buf != NULL && buf->b_p_bt[0] == 't'; } -/// @return true if "buf" is a "nofile", "acwrite", "terminal" or "prompt" / +/// @return true if "buf" is a "nofile", "acwrite", "terminal" or "prompt" /// buffer. This means the buffer name is not a file name. -bool bt_nofile(const buf_T *const buf) +bool bt_nofilename(const buf_T *const buf) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { return buf != NULL && ((buf->b_p_bt[0] == 'n' && buf->b_p_bt[2] == 'f') @@ -5282,6 +5282,13 @@ bool bt_nofile(const buf_T *const buf) || buf->b_p_bt[0] == 'p'); } +/// @return true if "buf" has 'buftype' set to "nofile". +bool bt_nofile(const buf_T *const buf) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT +{ + return buf != NULL && buf->b_p_bt[0] == 'n' && buf->b_p_bt[2] == 'f'; +} + /// @return true if "buf" is a "nowrite", "nofile", "terminal" or "prompt" /// buffer. bool bt_dontwrite(const buf_T *const buf) @@ -5333,7 +5340,7 @@ char *buf_spname(buf_T *buf) } // There is no _file_ when 'buftype' is "nofile", b_sfname // contains the name as specified by the user. - if (bt_nofile(buf)) { + if (bt_nofilename(buf)) { if (buf->b_fname != NULL) { return buf->b_fname; } diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 63c25fe815..f231146d7c 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -482,7 +482,7 @@ static buf_T *find_buffer(typval_T *avar) * buffer, these don't use the full path. */ FOR_ALL_BUFFERS(bp) { if (bp->b_fname != NULL - && (path_with_url(bp->b_fname) || bt_nofile(bp)) + && (path_with_url(bp->b_fname) || bt_nofilename(bp)) && STRCMP(bp->b_fname, avar->vval.v_string) == 0) { buf = bp; break; diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 9a5cf9f50f..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_nofile(buf) && os_path_exists((char_u *)ffname)) { if (!eap->forceit && !eap->append) { #ifdef UNIX diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c index a7f4080b22..6ca6da9cd0 100644 --- a/src/nvim/ex_session.c +++ b/src/nvim/ex_session.c @@ -187,7 +187,7 @@ static int ses_do_win(win_T *wp) } if (wp->w_buffer->b_fname == NULL // When 'buftype' is "nofile" can't restore the window contents. - || (!wp->w_buffer->terminal && bt_nofile(wp->w_buffer))) { + || (!wp->w_buffer->terminal && bt_nofilename(wp->w_buffer))) { return ssop_flags & SSOP_BLANK; } if (bt_help(wp->w_buffer)) { @@ -363,7 +363,7 @@ static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int curr return FAIL; } } else if (wp->w_buffer->b_ffname != NULL - && (!bt_nofile(wp->w_buffer) || wp->w_buffer->terminal)) { + && (!bt_nofilename(wp->w_buffer) || wp->w_buffer->terminal)) { // Load the file. // Editing a file in this buffer: use ":edit file". @@ -706,7 +706,7 @@ static int makeopens(FILE *fd, char_u *dirnow) if (ses_do_win(wp) && wp->w_buffer->b_ffname != NULL && !bt_help(wp->w_buffer) - && !bt_nofile(wp->w_buffer)) { + && !bt_nofilename(wp->w_buffer)) { if (need_tabnext && put_line(fd, "tabnext") == FAIL) { return FAIL; } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index febde53ce2..6782465ef1 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -2286,7 +2286,7 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en && reset_changed && whole && buf == curbuf - && !bt_nofile(buf) + && !bt_nofilename(buf) && !filtering && (!append || vim_strchr(p_cpo, CPO_FNAMEAPP) != NULL) && vim_strchr(p_cpo, CPO_FNAMEW) != NULL) { @@ -2360,22 +2360,22 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en if (append) { if (!(did_cmd = apply_autocmds_exarg(EVENT_FILEAPPENDCMD, - sfname, sfname, FALSE, curbuf, eap))) { - if (overwriting && bt_nofile(curbuf)) { - nofile_err = TRUE; + sfname, sfname, false, curbuf, eap))) { + if (overwriting && bt_nofilename(curbuf)) { + nofile_err = true; } else { apply_autocmds_exarg(EVENT_FILEAPPENDPRE, - sfname, sfname, FALSE, curbuf, eap); + sfname, sfname, false, curbuf, eap); } } } else if (filtering) { apply_autocmds_exarg(EVENT_FILTERWRITEPRE, - NULL, sfname, FALSE, curbuf, eap); + NULL, sfname, false, curbuf, eap); } else if (reset_changed && whole) { int was_changed = curbufIsChanged(); did_cmd = apply_autocmds_exarg(EVENT_BUFWRITECMD, - sfname, sfname, FALSE, curbuf, eap); + sfname, sfname, false, curbuf, eap); if (did_cmd) { if (was_changed && !curbufIsChanged()) { /* Written everything correctly and BufWriteCmd has reset @@ -2385,21 +2385,21 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en u_update_save_nr(curbuf); } } else { - if (overwriting && bt_nofile(curbuf)) { - nofile_err = TRUE; + if (overwriting && bt_nofilename(curbuf)) { + nofile_err = true; } else { apply_autocmds_exarg(EVENT_BUFWRITEPRE, - sfname, sfname, FALSE, curbuf, eap); + sfname, sfname, false, curbuf, eap); } } } else { if (!(did_cmd = apply_autocmds_exarg(EVENT_FILEWRITECMD, - sfname, sfname, FALSE, curbuf, eap))) { - if (overwriting && bt_nofile(curbuf)) { - nofile_err = TRUE; + sfname, sfname, false, curbuf, eap))) { + if (overwriting && bt_nofilename(curbuf)) { + nofile_err = true; } else { apply_autocmds_exarg(EVENT_FILEWRITEPRE, - sfname, sfname, FALSE, curbuf, eap); + sfname, sfname, false, curbuf, eap); } } } @@ -4306,7 +4306,7 @@ void shorten_buf_fname(buf_T *buf, char_u *dirname, int force) char *p; if (buf->b_fname != NULL - && !bt_nofile(buf) + && !bt_nofilename(buf) && !path_with_url(buf->b_fname) && (force || buf->b_sfname == NULL diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index ba151b5ce2..90c0b6f5c6 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -726,8 +726,7 @@ static int pum_set_selected(int n, int repeat) if (!resized && (curbuf->b_nwindows == 1) && (curbuf->b_fname == NULL) - && (curbuf->b_p_bt[0] == 'n') - && (curbuf->b_p_bt[2] == 'f') + && bt_nofile(curbuf) && (curbuf->b_p_bh[0] == 'w')) { // Already a "wipeout" buffer, make it empty. while (!buf_is_empty(curbuf)) { 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 |