diff options
Diffstat (limited to 'src/nvim/api')
-rw-r--r-- | src/nvim/api/private/helpers.c | 10 | ||||
-rw-r--r-- | src/nvim/api/vim.c | 7 | ||||
-rw-r--r-- | src/nvim/api/window.c | 32 |
3 files changed, 15 insertions, 34 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 5abdc33709..8b881762e8 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -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); diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index a76cefe294..99a41f4f6f 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -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) { diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index f942d6b19f..a26213af98 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -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) { |