diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2023-08-15 19:38:52 +0100 |
---|---|---|
committer | Sean Dewar <seandewar@users.noreply.github.com> | 2024-01-28 12:29:42 +0000 |
commit | d85f180f26c0570c2510c899a0bf0023ec55a692 (patch) | |
tree | dd8e365576a87aaa20bef6848f4b31a52163d582 /src | |
parent | 7bb0dd08dbcd8cfeeaea725e2c00e9e5cfcae2bd (diff) | |
download | rneovim-d85f180f26c0570c2510c899a0bf0023ec55a692.tar.gz rneovim-d85f180f26c0570c2510c899a0bf0023ec55a692.tar.bz2 rneovim-d85f180f26c0570c2510c899a0bf0023ec55a692.zip |
vim-patch:9.1.0049: Make "[Command Line]" a special buffer name
Problem: E95 is possible if a buffer called "[Command Line]" already
exists when opening the cmdwin. This can also happen if the
cmdwin's buffer could not be deleted when closing.
Solution: Un-name the cmdwin buffer, and give it a special name instead,
similar to what's done for quickfix buffers and for unnamed
prompt and scratch buffers. As a result, BufFilePre/Post are
no longer fired when opening the cmdwin. Add a "command" key
to the dictionary returned by getbufinfo() to differentiate
the cmdwin buffer instead. (Sean Dewar)
Cherry-pick test_normal changes from v9.0.0954.
https://github.com/vim/vim/commit/1fb41032060df09ca2640dc49541f11062f6dfaa
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/buffer.c | 12 | ||||
-rw-r--r-- | src/nvim/eval.lua | 2 | ||||
-rw-r--r-- | src/nvim/eval/buffer.c | 1 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 2 |
4 files changed, 13 insertions, 4 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index da1e27aebf..d597d82ee2 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -4012,6 +4012,9 @@ char *buf_spname(buf_T *buf) if (buf->b_fname != NULL) { return buf->b_fname; } + if (buf == cmdwin_buf) { + return _("[Command Line]"); + } if (bt_prompt(buf)) { return _("[Prompt]"); } @@ -4129,6 +4132,7 @@ void wipe_buffer(buf_T *buf, bool aucmd) /// - Always considered 'nomodified' /// /// @param bufnr Buffer to switch to, or 0 to create a new buffer. +/// @param bufname Buffer name, or NULL. /// /// @see curbufIsChanged() /// @@ -4138,9 +4142,11 @@ int buf_open_scratch(handle_T bufnr, char *bufname) if (do_ecmd((int)bufnr, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL) == FAIL) { return FAIL; } - apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, false, curbuf); - setfname(curbuf, bufname, NULL, true); - apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, false, curbuf); + if (bufname != NULL) { + apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, false, curbuf); + setfname(curbuf, bufname, NULL, true); + apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, false, curbuf); + } set_option_value_give_err(kOptBufhidden, STATIC_CSTR_AS_OPTVAL("hide"), OPT_LOCAL); set_option_value_give_err(kOptBuftype, STATIC_CSTR_AS_OPTVAL("nofile"), OPT_LOCAL); set_option_value_give_err(kOptSwapfile, BOOLEAN_OPTVAL(false), OPT_LOCAL); diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 9f50fd1758..bc976eaa58 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -3219,6 +3219,8 @@ M.funcs = { bufnr Buffer number. changed TRUE if the buffer is modified. changedtick Number of changes made to the buffer. + command TRUE if the buffer belongs to the + command-line window |cmdwin|. hidden TRUE if the buffer is hidden. lastused Timestamp in seconds, like |localtime()|, when the buffer was diff --git a/src/nvim/eval/buffer.c b/src/nvim/eval/buffer.c index c43ef50410..7b8f71ef3f 100644 --- a/src/nvim/eval/buffer.c +++ b/src/nvim/eval/buffer.c @@ -494,6 +494,7 @@ static dict_T *get_buffer_info(buf_T *buf) tv_dict_add_nr(dict, S_LEN("changed"), bufIsChanged(buf)); tv_dict_add_nr(dict, S_LEN("changedtick"), buf_get_changedtick(buf)); tv_dict_add_nr(dict, S_LEN("hidden"), buf->b_ml.ml_mfp != NULL && buf->b_nwindows == 0); + tv_dict_add_nr(dict, S_LEN("command"), buf == cmdwin_buf); // Get a reference to buffer variables tv_dict_add_dict(dict, S_LEN("variables"), buf->b_vars); diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 9b56fffeda..307fd480cc 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4345,7 +4345,7 @@ static int open_cmdwin(void) // Create empty command-line buffer. Be especially cautious of BufLeave // autocommands from do_ecmd(), as cmdwin restrictions do not apply to them! - const int newbuf_status = buf_open_scratch(0, _("[Command Line]")); + const int newbuf_status = buf_open_scratch(0, NULL); const bool cmdwin_valid = win_valid(cmdwin_win); if (newbuf_status == FAIL || !cmdwin_valid || curwin != cmdwin_win || !win_valid(old_curwin) || !bufref_valid(&old_curbuf) || old_curwin->w_buffer != old_curbuf.br_buf) { |