aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/api')
-rw-r--r--src/nvim/api/win_config.c33
-rw-r--r--src/nvim/api/window.c2
2 files changed, 22 insertions, 13 deletions
diff --git a/src/nvim/api/win_config.c b/src/nvim/api/win_config.c
index feb4271b5f..11b6b17516 100644
--- a/src/nvim/api/win_config.c
+++ b/src/nvim/api/win_config.c
@@ -199,9 +199,8 @@
/// - footer_pos: Footer position. Must be set with `footer` option.
/// Value can be one of "left", "center", or "right".
/// Default is `"left"`.
-/// - noautocmd: If true then autocommands triggered from setting the
-/// `buffer` to display are blocked (e.g: |BufEnter|, |BufLeave|,
-/// |BufWinEnter|).
+/// - noautocmd: If true then all autocommands are blocked for the duration of
+/// the call.
/// - fixed: If true when anchor is NW or SW, the float window
/// would be kept fixed even if the window would be truncated.
/// - hide: If true the floating window will be hidden.
@@ -230,6 +229,10 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(win_config) *config, Err
}
bool is_split = HAS_KEY_X(config, split) || HAS_KEY_X(config, vertical);
+ Window rv = 0;
+ if (fconfig.noautocmd) {
+ block_autocmds();
+ }
win_T *wp = NULL;
tabpage_T *tp = curtab;
@@ -239,15 +242,15 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(win_config) *config, Err
parent = find_window_by_handle(fconfig.window, err);
if (!parent) {
// find_window_by_handle has already set the error
- return 0;
+ goto cleanup;
} else if (parent->w_floating) {
api_set_error(err, kErrorTypeException, "Cannot split a floating window");
- return 0;
+ goto cleanup;
}
}
if (!check_split_disallowed_err(parent ? parent : curwin, err)) {
- return 0; // error already set
+ goto cleanup; // error already set
}
if (HAS_KEY_X(config, vertical) && !HAS_KEY_X(config, split)) {
@@ -283,7 +286,7 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(win_config) *config, Err
if (!ERROR_SET(err)) {
api_set_error(err, kErrorTypeException, "Failed to create window");
}
- return 0;
+ goto cleanup;
}
// Autocommands may close `wp` or move it to another tabpage, so update and check `tp` after each
@@ -291,8 +294,8 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(win_config) *config, Err
// Also, autocommands may free the `buf` to switch to, so store a bufref to check.
bufref_T bufref;
set_bufref(&bufref, buf);
- switchwin_T switchwin;
- {
+ if (!fconfig.noautocmd) {
+ switchwin_T switchwin;
const int result = switch_win_noblock(&switchwin, wp, tp, true);
assert(result == OK);
(void)result;
@@ -313,7 +316,7 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(win_config) *config, Err
autocmd_no_enter++;
autocmd_no_leave++;
}
- win_set_buf(wp, buf, fconfig.noautocmd, err);
+ win_set_buf(wp, buf, err);
if (!fconfig.noautocmd) {
tp = win_find_tabpage(wp);
}
@@ -324,14 +327,20 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(win_config) *config, Err
}
if (!tp) {
api_set_error(err, kErrorTypeException, "Window was closed immediately");
- return 0;
+ goto cleanup;
}
if (fconfig.style == kWinStyleMinimal) {
win_set_minimal_style(wp);
didset_window_options(wp, true);
}
- return wp->handle;
+ rv = wp->handle;
+
+cleanup:
+ if (fconfig.noautocmd) {
+ unblock_autocmds();
+ }
+ return rv;
#undef HAS_KEY_X
}
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c
index 30f77c7248..08ecca1380 100644
--- a/src/nvim/api/window.c
+++ b/src/nvim/api/window.c
@@ -71,7 +71,7 @@ void nvim_win_set_buf(Window window, Buffer buffer, Error *err)
api_set_error(err, kErrorTypeException, "%s", e_cmdwin);
return;
}
- win_set_buf(win, buf, false, err);
+ win_set_buf(win, buf, err);
}
/// Gets the (1,0)-indexed, buffer-relative cursor position for a given window