aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/events.lua8
-rw-r--r--core/ui.lua6
-rw-r--r--src/textadept.c6
3 files changed, 18 insertions, 2 deletions
diff --git a/core/events.lua b/core/events.lua
index b5996baa..98a3475b 100644
--- a/core/events.lua
+++ b/core/events.lua
@@ -217,9 +217,17 @@ local M = {}
-- @field RESET_AFTER (string)
-- Emitted after resetting the Lua state.
-- Emitted by [`reset()`]().
+-- Arguments:
+--
+-- * _`persist`_: Table of data persisted by `events.RESET_BEFORE`. All
+-- handlers will have access to this same table.
-- @field RESET_BEFORE (string)
-- Emitted before resetting the Lua state.
-- Emitted by [`reset()`]().
+-- Arguments:
+--
+-- * _`persist`_: Table to store persistent data in for use by
+-- `events.RESET_AFTER`. All handlers will have access to this same table.
-- @field RESUME (string)
-- Emitted when resuming Textadept from a suspended state.
-- This event is only emitted by the terminal version.
diff --git a/core/ui.lua b/core/ui.lua
index 87e88ffb..be5d637b 100644
--- a/core/ui.lua
+++ b/core/ui.lua
@@ -187,6 +187,12 @@ events.connect(events.BUFFER_AFTER_SWITCH, function()
table.insert(buffers_zorder, 1, buffer)
end)
+-- Saves and restores buffer zorder data during a reset.
+events.connect(events.RESET_BEFORE,
+ function(persist) persist.buffers_zorder = buffers_zorder end)
+events.connect(events.RESET_AFTER,
+ function(persist) buffers_zorder = persist.buffers_zorder end)
+
---
-- Prompts the user to select a buffer to switch to.
-- Buffers are listed in the order they were opened unless `zorder` is `true`,
diff --git a/src/textadept.c b/src/textadept.c
index afbb7ee7..f40ab00f 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -1395,14 +1395,16 @@ static int lL_dofile(lua_State *L, const char *filename) {
/** `_G.reset()` Lua function. */
static int lreset(lua_State *L) {
- lL_event(L, "reset_before", -1);
+ int persist_ref = (lua_newtable(L), luaL_ref(L, LUA_REGISTRYINDEX));
+ lua_rawgeti(L, LUA_REGISTRYINDEX, persist_ref); // lL_event will unref
+ lL_event(L, "reset_before", LUA_TTABLE, luaL_ref(L, LUA_REGISTRYINDEX), -1);
lL_init(L, 0, NULL, TRUE);
l_setglobalview(L, focused_view);
l_setglobaldoc(L, SS(focused_view, SCI_GETDOCPOINTER, 0, 0));
lua_pushnil(L), lua_setglobal(L, "arg");
lL_dofile(L, "init.lua"), lL_event(L, "initialized", -1);
lua_getfield(L, LUA_REGISTRYINDEX, "ta_arg"), lua_setglobal(L, "arg");
- lL_event(L, "reset_after", -1);
+ lL_event(L, "reset_after", LUA_TTABLE, persist_ref, -1);
return 0;
}