diff options
author | 2010-12-07 16:59:13 -0500 | |
---|---|---|
committer | 2010-12-07 16:59:13 -0500 | |
commit | eff79c94b8366831cb2a31651f677fb85de70ea8 (patch) | |
tree | 725fd8b665b550cbdae3941c32641abffb4d9ffc | |
parent | e572c0c30f53caa46e87167f7609ee9f8e7727da (diff) | |
download | textadept-eff79c94b8366831cb2a31651f677fb85de70ea8.tar.gz textadept-eff79c94b8366831cb2a31651f677fb85de70ea8.zip |
Fix infinite recursion errors caused in events.
-rw-r--r-- | core/events.lua | 13 | ||||
-rw-r--r-- | src/textadept.c | 6 |
2 files changed, 16 insertions, 3 deletions
diff --git a/core/events.lua b/core/events.lua index a0cc2bdd..80003bf9 100644 --- a/core/events.lua +++ b/core/events.lua @@ -154,6 +154,8 @@ function disconnect(event, index) table.remove(handlers, index) end +local error_emitted = false + --- -- Calls all handlers for the given event in sequence (effectively "generating" -- the event). @@ -167,7 +169,16 @@ function emit(event, ...) local handlers = _M[plural] if not handlers then return end for _, f in ipairs(handlers) do - local result = f(unpack{...}) + local ok, result = pcall(f, unpack{...}) + if not ok then + if not error_emitted then + error_emitted = true + emit('error', result) + error_emitted = false + else + io.stderr:write(result) + end + end if type(result) == 'boolean' then return result end end end diff --git a/src/textadept.c b/src/textadept.c index fa2fa6de..3fbf46d7 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -338,6 +338,7 @@ void new_buffer(GtkWidget *editor, int create, int addref) { doc = SS(editor, SCI_GETDOCPOINTER, 0, 0); if (create) { // create the new document doc = SS(editor, SCI_CREATEDOCUMENT, 0, 0); + l_emit_event("buffer_before_switch", -1); l_goto_buffer(focused_editor, l_add_buffer(doc), TRUE); } else if (addref) { l_add_buffer(doc); @@ -1171,10 +1172,8 @@ void l_goto_buffer(GtkWidget *editor, int n, int absolute) { lua_rawgeti(lua, -1, n); } sptr_t doc = l_checkdocpointer(lua, -1); - if (!closing) l_emit_event("buffer_before_switch", -1); SS(editor, SCI_SETDOCPOINTER, 0, doc); l_set_buffer_global(editor); - if (!closing) l_emit_event("buffer_after_switch", -1); lua_pop(lua, 2); // buffer table and buffers } @@ -1834,6 +1833,7 @@ static int l_cf_buffer_delete(lua_State *lua) { new_buffer(focused_editor, TRUE, TRUE); remove_buffer(doc); l_emit_event("buffer_deleted", -1); + l_emit_event("buffer_after_switch", -1); return 0; } @@ -1933,7 +1933,9 @@ static int l_cf_view_goto_buffer(lua_State *lua) { GtkWidget *orig_focused_editor = focused_editor; if (switch_focus) SS(editor, SCI_SETFOCUS, TRUE, 0); lua_remove(lua, 1); // view table + l_emit_event("buffer_before_switch", -1); l_cf_gui_goto_(lua, editor, TRUE); + l_emit_event("buffer_after_switch", -1); if (switch_focus) { SS(editor, SCI_SETFOCUS, FALSE, 0); gtk_widget_grab_focus(orig_focused_editor); |