refactor(api): always use TRY_WRAP #31600

Problem:  Two separate try/end wrappers, that only marginally differ by
          restoring a few variables. Wrappers that don't restore
          previous state are dangerous to use in "api-fast" functions.
Solution: Remove wrappers that don't restore the previous state.
          Always use TRY_WRAP.
This commit is contained in:
luukvbaal
2024-12-17 13:12:22 +01:00
committed by GitHub
parent b03e790cdd
commit 6bf2a6fc5b
10 changed files with 377 additions and 427 deletions

View File

@@ -368,19 +368,16 @@ void nvim_win_hide(Window window, Error *err)
}
tabpage_T *tabpage = win_find_tabpage(win);
TryState tstate;
try_enter(&tstate);
// Never close the autocommand window.
if (is_aucmd_win(win)) {
emsg(_(e_autocmd_close));
} else if (tabpage == curtab) {
win_close(win, false, false);
} else {
win_close_othertab(win, false, tabpage);
}
vim_ignored = try_leave(&tstate, err);
TRY_WRAP(err, {
// Never close the autocommand window.
if (is_aucmd_win(win)) {
emsg(_(e_autocmd_close));
} else if (tabpage == curtab) {
win_close(win, false, false);
} else {
win_close_othertab(win, false, tabpage);
}
});
}
/// Closes the window (like |:close| with a |window-ID|).
@@ -400,10 +397,9 @@ void nvim_win_close(Window window, Boolean force, Error *err)
}
tabpage_T *tabpage = win_find_tabpage(win);
TryState tstate;
try_enter(&tstate);
ex_win_close(force, win, tabpage == curtab ? NULL : tabpage);
vim_ignored = try_leave(&tstate, err);
TRY_WRAP(err, {
ex_win_close(force, win, tabpage == curtab ? NULL : tabpage);
});
}
/// Calls a function with window as temporary current window.