aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/private/helpers.c9
-rw-r--r--src/nvim/api/vim.c19
-rw-r--r--src/nvim/api/window.c7
-rw-r--r--src/nvim/window.c40
4 files changed, 25 insertions, 50 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index 8ddaecc58e..5bf66a092f 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -101,9 +101,9 @@ bool try_leave(const TryState *const tstate, Error *const err)
return ret;
}
-/// Start block that may cause vimscript exceptions
+/// Starts a block that may cause Vimscript exceptions; must be mirrored by `try_end()` call.
///
-/// Each try_start() call should be mirrored by try_end() call.
+/// Note: use `TRY_WRAP` instead (except in `FUNC_API_FAST` functions such as nvim_get_runtime_file).
///
/// To be used as a replacement of `:try … catch … endtry` in C code, in cases
/// when error flag could not already be set. If there may be pending error
@@ -114,8 +114,9 @@ void try_start(void)
trylevel++;
}
-/// End try block, set the error message if any and return true if an error
-/// occurred.
+/// Ends a `try_start` block; sets error message if any and returns true if an error occurred.
+///
+/// Note: use `TRY_WRAP` instead (except in `FUNC_API_FAST` functions such as nvim_get_runtime_file).
///
/// @param err Pointer to the stack-allocated error object
/// @return true if an error occurred
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 42fc21deac..1acfa0d34b 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -596,6 +596,7 @@ ArrayOf(String) nvim_get_runtime_file(String name, Boolean all, Arena *arena, Er
int flags = DIP_DIRFILE | (all ? DIP_ALL : 0);
TryState tstate;
+ // XXX: intentionally not using `TRY_WRAP`, to avoid `did_emsg=false` in `try_end`.
try_enter(&tstate);
do_in_runtimepath((name.size ? name.data : ""), flags, find_runtime_cb, &cookie);
vim_ignored = try_leave(&tstate, err);
@@ -888,23 +889,13 @@ void nvim_set_current_buf(Buffer buffer, Error *err)
{
buf_T *buf = find_buffer_by_handle(buffer, err);
- if (!buf || curwin->w_buffer == buf) {
- return;
- }
-
- if (curwin->w_p_wfb) {
- api_set_error(err, kErrorTypeException, "%s", e_winfixbuf_cannot_go_to_buffer);
+ if (!buf) {
return;
}
- 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 switch to buffer %d",
- buffer);
- }
+ TRY_WRAP(err, {
+ do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0);
+ });
}
/// Gets the current list of window handles.
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c
index f415415fa7..170d5c6cdb 100644
--- a/src/nvim/api/window.c
+++ b/src/nvim/api/window.c
@@ -59,12 +59,7 @@ void nvim_win_set_buf(Window window, Buffer buffer, Error *err)
{
win_T *win = find_window_by_handle(window, err);
buf_T *buf = find_buffer_by_handle(buffer, err);
- if (!win || !buf || win->w_buffer == buf) {
- return;
- }
-
- if (win->w_p_wfb) {
- api_set_error(err, kErrorTypeException, "%s", e_winfixbuf_cannot_go_to_buffer);
+ if (!win || !buf) {
return;
}
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 938d9d7618..1430b2efb2 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -746,40 +746,28 @@ void win_set_buf(win_T *win, buf_T *buf, Error *err)
RedrawingDisabled++;
switchwin_T switchwin;
- if (switch_win_noblock(&switchwin, win, tab, true) == FAIL) {
- api_set_error(err,
- kErrorTypeException,
- "Failed to switch to window %d",
- win->handle);
- goto cleanup;
- }
-
- try_start();
- const int save_acd = p_acd;
- if (!switchwin.sw_same_win) {
- // Temporarily disable 'autochdir' when setting buffer in another window.
- p_acd = false;
- }
+ TRY_WRAP(err, {
+ int win_result = switch_win_noblock(&switchwin, win, tab, true);
+ if (win_result != FAIL) {
+ const int save_acd = p_acd;
+ if (!switchwin.sw_same_win) {
+ // Temporarily disable 'autochdir' when setting buffer in another window.
+ p_acd = false;
+ }
- int result = do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0);
+ do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0);
- if (!switchwin.sw_same_win) {
- p_acd = save_acd;
- }
-
- if (!try_end(err) && result == FAIL) {
- api_set_error(err,
- kErrorTypeException,
- "Failed to set buffer %d",
- buf->handle);
- }
+ if (!switchwin.sw_same_win) {
+ p_acd = save_acd;
+ }
+ }
+ });
// If window is not current, state logic will not validate its cursor. So do it now.
// Still needed if do_buffer returns FAIL (e.g: autocmds abort script after buffer was set).
validate_cursor(curwin);
-cleanup:
restore_win_noblock(&switchwin, true);
RedrawingDisabled--;
}