aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/builtin.txt2
-rw-r--r--runtime/lua/vim/_meta/vimfn.lua2
-rw-r--r--src/nvim/buffer.c12
-rw-r--r--src/nvim/eval.lua2
-rw-r--r--src/nvim/eval/buffer.c1
-rw-r--r--src/nvim/ex_getln.c2
-rw-r--r--test/old/testdir/test_cmdwin.vim13
-rw-r--r--test/old/testdir/test_normal.vim13
8 files changed, 39 insertions, 8 deletions
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index ce12437c25..fc1c770de7 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -2079,6 +2079,8 @@ getbufinfo([{dict}]) *getbufinfo()*
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/runtime/lua/vim/_meta/vimfn.lua b/runtime/lua/vim/_meta/vimfn.lua
index 2280eec5c8..acf3750500 100644
--- a/runtime/lua/vim/_meta/vimfn.lua
+++ b/runtime/lua/vim/_meta/vimfn.lua
@@ -2562,6 +2562,8 @@ function vim.fn.getbufinfo(buf) end
--- 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/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) {
diff --git a/test/old/testdir/test_cmdwin.vim b/test/old/testdir/test_cmdwin.vim
index 14305155d8..9b1a45708e 100644
--- a/test/old/testdir/test_cmdwin.vim
+++ b/test/old/testdir/test_cmdwin.vim
@@ -192,4 +192,17 @@ func Test_cmdwin_interrupted()
delfunc CheckInterrupted
endfunc
+func Test_cmdwin_existing_bufname()
+ func CheckName()
+ call assert_equal(1, getbufinfo('')[0].command)
+ call assert_equal(0, getbufinfo('[Command Line]')[0].command)
+ call assert_match('#a\s*"\[Command Line\]"', execute('ls'))
+ call assert_match('%a\s*"\[Command Line\]"', execute('ls'))
+ endfunc
+ file [Command Line]
+ call feedkeys("q::call CheckName()\<CR>:q\<CR>", 'ntx')
+ 0file
+ delfunc CheckName
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/test/old/testdir/test_normal.vim b/test/old/testdir/test_normal.vim
index c72d83fa52..b98547061e 100644
--- a/test/old/testdir/test_normal.vim
+++ b/test/old/testdir/test_normal.vim
@@ -3167,15 +3167,18 @@ endfunc
func Test_normal50_commandline()
CheckFeature timers
CheckFeature cmdline_hist
+
func! DoTimerWork(id)
- call assert_equal('[Command Line]', bufname(''))
+ call assert_equal(1, getbufinfo('')[0].command)
+
" should fail, with E11, but does fail with E23?
"call feedkeys("\<c-^>", 'tm')
- " should also fail with E11
+ " should fail with E11 - "Invalid in command-line window"
call assert_fails(":wincmd p", 'E11')
- " return from commandline window
- call feedkeys("\<cr>")
+
+ " Return from commandline window.
+ call feedkeys("\<CR>", 't')
endfunc
let oldlang=v:lang
@@ -3188,7 +3191,9 @@ func Test_normal50_commandline()
catch /E23/
" no-op
endtry
+
" clean up
+ delfunc DoTimerWork
set updatetime=4000
exe "lang" oldlang
bw!