mirror of
https://github.com/neovim/neovim.git
synced 2025-10-05 17:36:29 +00:00
api(nvim_open_win): add "noautocmd" option
This option, when set, stops nvim_open_win() from potentially firing buffer-related autocmd events (BufEnter, BufLeave and BufWinEnter in the case of nvim_open_win()).
This commit is contained in:
@@ -1645,7 +1645,7 @@ bool api_object_to_bool(Object obj, const char *what,
|
||||
} else if (obj.type == kObjectTypeNil) {
|
||||
return nil_value; // caller decides what NIL (missing retval in lua) means
|
||||
} else {
|
||||
api_set_error(err, kErrorTypeValidation, "%s is not an boolean", what);
|
||||
api_set_error(err, kErrorTypeValidation, "%s is not a boolean", what);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1868,7 +1868,7 @@ static void parse_border_style(Object style, FloatConfig *fconfig, Error *err)
|
||||
}
|
||||
|
||||
bool parse_float_config(Dictionary config, FloatConfig *fconfig, bool reconf,
|
||||
Error *err)
|
||||
bool new_win, Error *err)
|
||||
{
|
||||
// TODO(bfredl): use a get/has_key interface instead and get rid of extra
|
||||
// flags
|
||||
@@ -2015,6 +2015,12 @@ bool parse_float_config(Dictionary config, FloatConfig *fconfig, bool reconf,
|
||||
api_set_error(err, kErrorTypeValidation,
|
||||
"Invalid value of 'style' key");
|
||||
}
|
||||
} else if (strequal(key, "noautocmd") && new_win) {
|
||||
fconfig->noautocmd
|
||||
= api_object_to_bool(val, "'noautocmd' key", false, err);
|
||||
if (ERROR_SET(err)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
api_set_error(err, kErrorTypeValidation,
|
||||
"Invalid key '%s'", key);
|
||||
|
@@ -1459,6 +1459,9 @@ void nvim_chan_send(Integer chan, String data, Error *err)
|
||||
/// By default `FloatBorder` highlight is used which links to `VertSplit`
|
||||
/// when not defined. It could also be specified by character:
|
||||
/// [ {"+", "MyCorner"}, {"x", "MyBorder"} ]
|
||||
/// - `noautocmd`: If true then no buffer-related autocommand events such as
|
||||
/// |BufEnter|, |BufLeave| or |BufWinEnter| may fire from
|
||||
/// calling this function.
|
||||
///
|
||||
/// @param[out] err Error details, if any
|
||||
///
|
||||
@@ -1469,7 +1472,7 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dictionary config,
|
||||
FUNC_API_CHECK_TEXTLOCK
|
||||
{
|
||||
FloatConfig fconfig = FLOAT_CONFIG_INIT;
|
||||
if (!parse_float_config(config, &fconfig, false, err)) {
|
||||
if (!parse_float_config(config, &fconfig, false, true, err)) {
|
||||
return 0;
|
||||
}
|
||||
win_T *wp = win_new_float(NULL, fconfig, err);
|
||||
@@ -1484,7 +1487,7 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dictionary config,
|
||||
return 0;
|
||||
}
|
||||
if (buffer > 0) {
|
||||
nvim_win_set_buf(wp->handle, buffer, err);
|
||||
win_set_buf(wp->handle, buffer, fconfig.noautocmd, err);
|
||||
}
|
||||
|
||||
if (fconfig.style == kWinStyleMinimal) {
|
||||
|
@@ -46,35 +46,7 @@ void nvim_win_set_buf(Window window, Buffer buffer, Error *err)
|
||||
FUNC_API_SINCE(5)
|
||||
FUNC_API_CHECK_TEXTLOCK
|
||||
{
|
||||
win_T *win = find_window_by_handle(window, err), *save_curwin = curwin;
|
||||
buf_T *buf = find_buffer_by_handle(buffer, err);
|
||||
tabpage_T *tab = win_find_tabpage(win), *save_curtab = curtab;
|
||||
|
||||
if (!win || !buf) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (switch_win(&save_curwin, &save_curtab, win, tab, false) == FAIL) {
|
||||
api_set_error(err,
|
||||
kErrorTypeException,
|
||||
"Failed to switch to window %d",
|
||||
window);
|
||||
}
|
||||
|
||||
try_start();
|
||||
int result = do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0);
|
||||
if (!try_end(err) && result == FAIL) {
|
||||
api_set_error(err,
|
||||
kErrorTypeException,
|
||||
"Failed to set buffer %d",
|
||||
buffer);
|
||||
}
|
||||
|
||||
// If window is not current, state logic will not validate its cursor.
|
||||
// So do it now.
|
||||
validate_cursor();
|
||||
|
||||
restore_win(save_curwin, save_curtab, false);
|
||||
win_set_buf(window, buffer, false, err);
|
||||
}
|
||||
|
||||
/// Gets the (1,0)-indexed cursor position in the window. |api-indexing|
|
||||
@@ -423,7 +395,7 @@ void nvim_win_set_config(Window window, Dictionary config, Error *err)
|
||||
// reuse old values, if not overriden
|
||||
FloatConfig fconfig = new_float ? FLOAT_CONFIG_INIT : win->w_float_config;
|
||||
|
||||
if (!parse_float_config(config, &fconfig, !new_float, err)) {
|
||||
if (!parse_float_config(config, &fconfig, !new_float, false, err)) {
|
||||
return;
|
||||
}
|
||||
if (new_float) {
|
||||
|
Reference in New Issue
Block a user