refactor: unify context-switching concepts

This commit is contained in:
Justin M. Keyes
2026-07-09 19:50:16 +02:00
parent 982d2f2531
commit 6bb1aa74e6
25 changed files with 691 additions and 633 deletions

View File

@@ -22,6 +22,7 @@
#include "nvim/buffer_defs.h"
#include "nvim/buffer_updates.h"
#include "nvim/change.h"
#include "nvim/context.h"
#include "nvim/cursor.h"
#include "nvim/ex_cmds.h"
#include "nvim/extmark.h"
@@ -1221,13 +1222,13 @@ Object nvim_buf_call(Buffer buf, LuaRef fn, lua_State *lstate, Error *err)
}
TRY_WRAP(err, {
aco_save_T aco = { 0 };
aucmd_prepbuf(&aco, b);
CtxSwitch cs;
ctx_switch(&cs, NULL, NULL, b, 0);
Array args = ARRAY_DICT_INIT;
nlua_call_ref(fn, NULL, args, kRetMultiStack, NULL, err);
aucmd_restbuf(&aco);
ctx_restore(&cs);
});
return NIL; // kRetMultiStack: values are already on the lua stack

View File

@@ -1567,7 +1567,7 @@ Object nvim_load_context(Dict dict, Error *err)
ctx_from_dict(dict, &ctx, err);
if (!ERROR_SET(err)) {
ctx_restore(&ctx, kCtxAll);
ctx_load(&ctx, kCtxAll);
}
ctx_free(&ctx);

View File

@@ -16,6 +16,7 @@
#include "nvim/buffer.h"
#include "nvim/buffer_defs.h"
#include "nvim/charset.h"
#include "nvim/context.h"
#include "nvim/decoration_defs.h"
#include "nvim/drawscreen.h"
#include "nvim/errors.h"
@@ -403,7 +404,7 @@ static bool win_can_move_tp(win_T *wp, tabpage_T *tp, Error *err)
api_set_error(err, kErrorTypeException, "%s", e_textlock);
return false;
}
if (is_aucmd_win(wp)) {
if (is_ctx_win(wp)) {
api_set_error(err, kErrorTypeException, "Cannot move autocmd window to another tabpage");
return false;
}

View File

@@ -11,6 +11,7 @@
#include "nvim/api/window.h"
#include "nvim/autocmd.h"
#include "nvim/buffer_defs.h"
#include "nvim/context.h"
#include "nvim/cursor.h"
#include "nvim/drawscreen.h"
#include "nvim/errors.h"
@@ -321,7 +322,7 @@ void nvim_win_hide(Window win, Error *err)
tabpage_T *tabpage = win_find_tabpage(w);
TRY_WRAP(err, {
// Never close the autocommand window.
if (is_aucmd_win(w)) {
if (is_ctx_win(w)) {
emsg(_(e_autocmd_close));
} else if (tabpage == curtab) {
win_close(w, false, false);
@@ -374,12 +375,12 @@ Object nvim_win_call(Window win, LuaRef fn, lua_State *lstate, Error *err)
tabpage_T *tabpage = win_find_tabpage(w);
TRY_WRAP(err, {
win_execute_T win_execute_args;
if (win_execute_before(&win_execute_args, w, tabpage)) {
CtxSwitch cs;
if (ctx_switch(&cs, w, tabpage, NULL, kCtxNoDisplay | kCtxKeepCwd | kCtxValidate)) {
Array args = ARRAY_DICT_INIT;
nlua_call_ref(fn, NULL, args, kRetMultiStack, NULL, err);
}
win_execute_after(&win_execute_args);
ctx_restore(&cs);
});
return NIL; // kRetMultiStack: values are already on the lua stack
}