aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lua_interface.c52
-rw-r--r--src/textadept.c49
-rw-r--r--src/textadept.h4
3 files changed, 50 insertions, 55 deletions
diff --git a/src/lua_interface.c b/src/lua_interface.c
index 9bc8aff9..c3bf55b6 100644
--- a/src/lua_interface.c
+++ b/src/lua_interface.c
@@ -241,9 +241,9 @@ void l_goto_scintilla_window(GtkWidget *editor, int n, int absolute) {
lua_rawgeti(lua, -1, n);
}
editor = l_checkview(lua, -1);
- if (!closing) l_handle_event("view_before_switch", -1);
+ if (!closing) l_emit_event("view_before_switch", -1);
gtk_widget_grab_focus(editor);
- if (!closing) l_handle_event("view_after_switch", -1);
+ if (!closing) l_emit_event("view_after_switch", -1);
lua_pop(lua, 2); // view table and views
}
@@ -372,10 +372,10 @@ void l_goto_scintilla_buffer(GtkWidget *editor, int n, int absolute) {
lua_rawgeti(lua, -1, n);
}
sptr_t doc = l_checkdocpointer(lua, -1);
- if (!closing) l_handle_event("buffer_before_switch", -1);
+ if (!closing) l_emit_event("buffer_before_switch", -1);
SS(editor, SCI_SETDOCPOINTER, 0, doc);
l_set_buffer_global(editor);
- if (!closing) l_handle_event("buffer_after_switch", -1);
+ if (!closing) l_emit_event("buffer_after_switch", -1);
lua_pop(lua, 2); // buffer table and buffers
}
@@ -436,23 +436,19 @@ static void clear_table(lua_State *lua, int abs_index) {
}
/**
- * Returns whether or not the value of the key of the given table in the global
- * 'textadept' table is a function.
- * @param table The table in 'textadept' to check for key in.
+ * Returns whether or not the value of the key of the given global table is a
+ * function.
+ * @param table The table to check for key in.
* @param key String key to check for in table.
*/
-int l_ista2function(const char *table, const char *key) {
- lua_getglobal(lua, "textadept");
+int l_is2function(const char *table, const char *key) {
+ lua_getglobal(lua, table);
if (lua_istable(lua, -1)) {
- lua_getfield(lua, -1, table);
- lua_remove(lua, -2); // textadept
- if (lua_istable(lua, -1)) {
- lua_getfield(lua, -1, key);
- lua_remove(lua, -2); // table
- if (lua_isfunction(lua, -1)) return TRUE;
- lua_pop(lua, 1); // non-function
- } else lua_pop(lua, 1); // non-table
- } else lua_pop(lua, 1); // textadept
+ lua_getfield(lua, -1, key);
+ lua_remove(lua, -2); // table
+ if (lua_isfunction(lua, -1)) return TRUE;
+ lua_pop(lua, 1); // non-function
+ } else lua_pop(lua, 1); // non-table
return FALSE;
}
@@ -475,7 +471,7 @@ static int l_call_function(int nargs, int retn, int keep_return) {
return result;
} else {
if (focused_editor)
- l_handle_event("error", LUA_TSTRING, lua_tostring(lua, -1), -1);
+ l_emit_event("error", LUA_TSTRING, lua_tostring(lua, -1), -1);
else
printf("Lua Error: %s\n", lua_tostring(lua, -1));
lua_settop(lua, 0);
@@ -606,8 +602,8 @@ static void l_check_focused_buffer(lua_State *lua, int narg) {
* list should contain Lua types followed by the data of that type to pass.
* The list is terminated by a -1.
*/
-int l_handle_event(const char *s, ...) {
- if (!l_ista2function("events", "handle")) return FALSE;
+int l_emit_event(const char *s, ...) {
+ if (!l_is2function("events", "emit")) return FALSE;
lua_pushstring(lua, s);
int n = 1;
va_list ap;
@@ -627,7 +623,7 @@ int l_handle_event(const char *s, ...) {
long ref = (long)arg;
lua_rawgeti(lua, LUA_REGISTRYINDEX, ref);
luaL_unref(lua, LUA_REGISTRYINDEX, ref);
- } else warn("events.handle: ignored invalid argument type");
+ } else warn("events.emit: ignored invalid argument type");
n++;
type = va_arg(ap, int);
}
@@ -644,8 +640,8 @@ int l_handle_event(const char *s, ...) {
* Handles a Scintilla notification.
* @param n The Scintilla notification struct.
*/
-void l_handle_scnnotification(struct SCNotification *n) {
- if (!l_ista2function("events", "notification")) return;
+void l_emit_scnnotification(struct SCNotification *n) {
+ if (!l_is2function("events", "notification")) return;
lua_newtable(lua);
l_pushscninteger(n->nmhdr.code, "code");
l_pushscninteger(n->position, "position");
@@ -1011,7 +1007,7 @@ static int l_cf_buffer_delete(lua_State *lua) {
else
new_scintilla_buffer(focused_editor, TRUE, TRUE);
remove_scintilla_buffer(doc);
- l_handle_event("buffer_deleted", -1);
+ l_emit_event("buffer_deleted", -1);
return 0;
}
@@ -1136,7 +1132,7 @@ static int l_cf_ta_goto_window(lua_State *lua) {
}
static void t_menu_activate(GtkWidget *menu, gpointer id) {
- l_handle_event("menu_clicked", LUA_TNUMBER, GPOINTER_TO_INT(id), -1);
+ l_emit_event("menu_clicked", LUA_TNUMBER, GPOINTER_TO_INT(id), -1);
}
static int l_cf_ta_gtkmenu(lua_State *lua) {
@@ -1169,7 +1165,7 @@ static int l_cf_ta_quit(lua_State *lua) {
}
static int l_cf_ta_reset(lua_State *lua) {
- l_handle_event("reset_before", -1);
+ l_emit_event("reset_before", -1);
l_init(0, NULL, TRUE);
lua_pushboolean(lua, TRUE);
lua_setglobal(lua, "RESETTING");
@@ -1178,7 +1174,7 @@ static int l_cf_ta_reset(lua_State *lua) {
lua_setglobal(lua, "RESETTING");
l_set_view_global(focused_editor);
l_set_buffer_global(focused_editor);
- l_handle_event("reset_after", -1);
+ l_emit_event("reset_after", -1);
return 0;
}
diff --git a/src/textadept.c b/src/textadept.c
index 4f8333a5..f0fa79f6 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -224,7 +224,7 @@ GtkWidget *new_scintilla_window(sptr_t buffer_id) {
new_scintilla_buffer(editor, FALSE, FALSE);
} else new_scintilla_buffer(editor, FALSE, TRUE);
l_set_view_global(editor);
- l_handle_event("view_new", -1);
+ l_emit_event("view_new", -1);
return editor;
}
@@ -266,8 +266,8 @@ void new_scintilla_buffer(GtkWidget *editor, int create, int addref) {
SS(editor, SCI_ADDREFDOCUMENT, 0, doc);
}
l_set_buffer_global(editor);
- l_handle_event("buffer_new", -1);
- l_handle_event("update_ui", -1); // update document status
+ l_emit_event("buffer_new", -1);
+ l_emit_event("update_ui", -1); // update document status
}
/**
@@ -401,11 +401,11 @@ void set_statusbar_text(const char *text, int docbar) {
* @see s_command
*/
static void switch_to_view(GtkWidget *editor) {
- l_handle_event("view_before_switch", -1);
+ l_emit_event("view_before_switch", -1);
focused_editor = editor;
l_set_view_global(editor);
l_set_buffer_global(editor);
- l_handle_event("view_after_switch", -1);
+ l_emit_event("view_after_switch", -1);
}
/**
@@ -417,7 +417,7 @@ static void s_notification(GtkWidget *editor, gint wParam, gpointer lParam,
if (focused_editor != editor &&
(n->nmhdr.code == SCN_URIDROPPED || n->nmhdr.code == SCN_SAVEPOINTLEFT))
switch_to_view(editor);
- l_handle_scnnotification(n);
+ l_emit_scnnotification(n);
}
/**
@@ -434,16 +434,16 @@ static void s_command(GtkWidget *editor, gint wParam, gpointer lParam,
* Collects the modifier states as flags and calls Lua to handle the keypress.
*/
static gbool s_keypress(GtkWidget *editor, GdkEventKey *event, gpointer udata) {
- return l_handle_event("keypress",
- LUA_TNUMBER, event->keyval,
- LUA_TBOOLEAN, event->state & GDK_SHIFT_MASK,
- LUA_TBOOLEAN, event->state & GDK_CONTROL_MASK,
+ return l_emit_event("keypress",
+ LUA_TNUMBER, event->keyval,
+ LUA_TBOOLEAN, event->state & GDK_SHIFT_MASK,
+ LUA_TBOOLEAN, event->state & GDK_CONTROL_MASK,
#if !MAC
- LUA_TBOOLEAN, event->state & GDK_MOD1_MASK,
+ LUA_TBOOLEAN, event->state & GDK_MOD1_MASK,
#else
- LUA_TBOOLEAN, event->state & GDK_META_MASK,
+ LUA_TBOOLEAN, event->state & GDK_META_MASK,
#endif
- -1) ? TRUE : FALSE;
+ -1) ? TRUE : FALSE;
}
/**
@@ -488,7 +488,7 @@ static gbool w_keypress(GtkWidget *window, GdkEventKey *event, gpointer udata) {
* @see l_close
*/
static gbool w_exit(GtkWidget *window, GdkEventAny *event, gpointer udata) {
- if (!l_handle_event("quit", -1)) return TRUE;
+ if (!l_emit_event("quit", -1)) return TRUE;
l_close();
scintilla_release_resources();
gtk_main_quit();
@@ -511,7 +511,7 @@ static OSErr w_ae_open(const AppleEvent *event, AppleEvent *reply, long ref) {
NULL);
CFURLRef url = CFURLCreateFromFSRef(kCFAllocatorDefault, &fsref);
if (url) {
- l_handle_event("appleevent_odoc", LUA_TSTRING, CFURL_TO_STR(url), -1);
+ l_emit_event("appleevent_odoc", LUA_TSTRING, CFURL_TO_STR(url), -1);
CFRelease(url);
}
}
@@ -652,16 +652,16 @@ static void find_button_clicked(GtkWidget *button, gpointer udata) {
if (strlen(find_text) == 0) return;
if (button == fnext_button || button == fprev_button) {
find_add_to_history(find_text, find_store);
- l_handle_event("find", LUA_TSTRING, find_text, LUA_TBOOLEAN,
- button == fnext_button, -1);
+ l_emit_event("find", LUA_TSTRING, find_text, LUA_TBOOLEAN,
+ button == fnext_button, -1);
} else {
find_add_to_history(repl_text, repl_store);
if (button == r_button) {
- l_handle_event("replace", LUA_TSTRING, repl_text, -1);
- l_handle_event("find", LUA_TSTRING, find_text, LUA_TBOOLEAN, 1, -1);
+ l_emit_event("replace", LUA_TSTRING, repl_text, -1);
+ l_emit_event("find", LUA_TSTRING, find_text, LUA_TBOOLEAN, 1, -1);
} else
- l_handle_event("replace_all", LUA_TSTRING, find_text, LUA_TSTRING,
- repl_text, -1);
+ l_emit_event("replace_all", LUA_TSTRING, find_text, LUA_TSTRING,
+ repl_text, -1);
}
}
@@ -729,14 +729,13 @@ static gbool cec_match_selected(GtkEntryCompletion *entry, GtkTreeModel *model,
* Signal for the 'enter' key being pressed in the Command Entry.
*/
static void c_activated(GtkWidget *entry, gpointer udata) {
- l_handle_event("command_entry_command", LUA_TSTRING,
- gtk_entry_get_text(GTK_ENTRY(entry)), -1);
+ l_emit_event("command_entry_command", LUA_TSTRING,
+ gtk_entry_get_text(GTK_ENTRY(entry)), -1);
}
/**
* Signal for a keypress inside the Command Entry.
*/
static gbool c_keypress(GtkWidget *entry, GdkEventKey *event, gpointer udata) {
- return l_handle_event("command_entry_keypress", LUA_TNUMBER, event->keyval,
- -1);
+ return l_emit_event("command_entry_keypress", LUA_TNUMBER, event->keyval, -1);
}
diff --git a/src/textadept.h b/src/textadept.h
index 0ec59dff..74db23d0 100644
--- a/src/textadept.h
+++ b/src/textadept.h
@@ -54,8 +54,8 @@ void l_remove_scintilla_buffer(sptr_t);
void l_goto_scintilla_buffer(GtkWidget *, int, int);
void l_set_buffer_global(GtkWidget *);
-int l_handle_event(const char *, ...);
-void l_handle_scnnotification(struct SCNotification *);
+int l_emit_event(const char *, ...);
+void l_emit_scnnotification(struct SCNotification *);
void l_ta_popup_context_menu(GdkEventButton *);
#endif