diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2017-09-02 14:21:06 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2019-02-09 11:48:45 +0100 |
commit | 891ed14f13c3ea99d3fb985371c69f769ee7ff57 (patch) | |
tree | 6e48660879a7f88178fd082d6c555fa64bec6102 /test/functional/api/vim_spec.lua | |
parent | f6faeea41c70015f6d9b63fecaf80d106cd2636d (diff) | |
download | rneovim-891ed14f13c3ea99d3fb985371c69f769ee7ff57.tar.gz rneovim-891ed14f13c3ea99d3fb985371c69f769ee7ff57.tar.bz2 rneovim-891ed14f13c3ea99d3fb985371c69f769ee7ff57.zip |
api: add nvim_create_buf to create a new empty buffer.
Loading existing files into a buffer is non-trivial and requires a window.
Creating an unnamed emtpy buffer is trivial and safe though, thus worth a
special case.
Change nvim_buf_set_option to use aucmd_prepbuf. This is necessary
to allow some options to be set on a not yet displayed buffer, such
as 'buftype' option.
vim-patch:7.4.1858: Add BLN_NEW to enforce buflist_new creating new buffer
Diffstat (limited to 'test/functional/api/vim_spec.lua')
-rw-r--r-- | test/functional/api/vim_spec.lua | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 415eaf3cbc..5c0fb8f88d 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1308,4 +1308,41 @@ describe('API', function() eq({["ns-1"]=1, ["ns-2"]=2}, meths.get_namespaces()) end) end) + + describe('nvim_create_buf', function() + it('works', function() + eq({id=2}, meths.create_buf(true)) + eq({id=3}, meths.create_buf(false)) + eq(' 1 %a "[No Name]" line 1\n'.. + ' 2 "[No Name]" line 0', + meths.command_output("ls")) + -- current buffer didn't change + eq({id=1}, meths.get_current_buf()) + + local screen = Screen.new(20, 4) + screen:attach() + meths.buf_set_lines(2, 0, -1, true, {"some text"}) + meths.set_current_buf(2) + screen:expect([[ + ^some text | + {1:~ }| + {1:~ }| + | + ]], { + [1] = {bold = true, foreground = Screen.colors.Blue1}, + }) + end) + + it('can change buftype before visiting', function() + meths.set_option("hidden", false) + eq({id=2}, meths.create_buf(true)) + meths.buf_set_option(2, "buftype", "nofile") + meths.buf_set_lines(2, 0, -1, true, {"test text"}) + command("split | buffer 2") + eq({id=2}, meths.get_current_buf()) + -- if the buf_set_option("buftype") didn't work, this would error out. + command("close") + eq({id=1}, meths.get_current_buf()) + end) + end) end) |