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
This commit is contained in:
Björn Linse
2017-09-02 14:21:06 +02:00
parent f6faeea41c
commit 891ed14f13
5 changed files with 62 additions and 5 deletions

View File

@@ -955,6 +955,25 @@ void nvim_set_current_win(Window window, Error *err)
}
}
/// Create new empty buffer
///
/// @param listed whether the buffer should be listed
/// @param[out] err Error details, if any
/// @return the buffer handle or 0 when error
Buffer nvim_create_buf(Boolean listed, Error *err)
FUNC_API_SINCE(6)
{
try_start();
Buffer buffer = buflist_add(NULL,
BLN_NOOPT | BLN_NEW | (listed ? BLN_LISTED : 0));
if (!try_end(err) && buffer == 0) {
api_set_error(err,
kErrorTypeException,
"Failed to create buffer");
}
return buffer;
}
/// Gets the current list of tabpage handles.
///
/// @return List of tabpage handles