diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lua_interface.c | 114 | ||||
-rw-r--r-- | src/textadept.c | 32 |
2 files changed, 70 insertions, 76 deletions
diff --git a/src/lua_interface.c b/src/lua_interface.c index 1299d8ef..88fb802e 100644 --- a/src/lua_interface.c +++ b/src/lua_interface.c @@ -31,9 +31,7 @@ static int tVOID = 0, /*tINT = 1,*/ tLENGTH = 2, /*tPOSITION = 3,*/ tSTRINGRESULT = 8; static void clear_table(lua_State *lua, int index); -static void warn(const char *s) { - printf("Warning: %s\n", s); -} +static void warn(const char *s) { printf("Warning: %s\n", s); } static int l_buffer_mt_index(lua_State *), l_buffer_mt_newindex(lua_State *), l_bufferp_mt_index(lua_State *), l_bufferp_mt_newindex(lua_State *), @@ -85,24 +83,24 @@ int l_init(int argc, char **argv, int reinit) { luaL_openlibs(lua); lua_newtable(lua); - lua_newtable(lua); - l_cfunc(lua, l_cf_find_next, "find_next"); - l_cfunc(lua, l_cf_find_prev, "find_prev"); - l_cfunc(lua, l_cf_find_focus, "focus"); - l_cfunc(lua, l_cf_find_replace, "replace"); - l_cfunc(lua, l_cf_find_replace_all, "replace_all"); - l_mt(lua, "_find_mt", l_find_mt_index, l_find_mt_newindex); - lua_setfield(lua, -2, "find"); - lua_newtable(lua); - l_cfunc(lua, l_cf_ce_focus, "focus"); - l_cfunc(lua, l_cf_ce_show_completions, "show_completions"); - l_mt(lua, "_ce_mt", l_ce_mt_index, l_ce_mt_newindex); - lua_setfield(lua, -2, "command_entry"); - l_cfunc(lua, l_cf_gui_dialog, "dialog"); - l_cfunc(lua, l_cf_gui_get_split_table, "get_split_table"); - l_cfunc(lua, l_cf_gui_goto_view, "goto_view"); - l_cfunc(lua, l_cf_gui_gtkmenu, "gtkmenu"); - l_mt(lua, "_gui_mt", l_gui_mt_index, l_gui_mt_newindex); + lua_newtable(lua); + l_cfunc(lua, l_cf_find_next, "find_next"); + l_cfunc(lua, l_cf_find_prev, "find_prev"); + l_cfunc(lua, l_cf_find_focus, "focus"); + l_cfunc(lua, l_cf_find_replace, "replace"); + l_cfunc(lua, l_cf_find_replace_all, "replace_all"); + l_mt(lua, "_find_mt", l_find_mt_index, l_find_mt_newindex); + lua_setfield(lua, -2, "find"); + lua_newtable(lua); + l_cfunc(lua, l_cf_ce_focus, "focus"); + l_cfunc(lua, l_cf_ce_show_completions, "show_completions"); + l_mt(lua, "_ce_mt", l_ce_mt_index, l_ce_mt_newindex); + lua_setfield(lua, -2, "command_entry"); + l_cfunc(lua, l_cf_gui_dialog, "dialog"); + l_cfunc(lua, l_cf_gui_get_split_table, "get_split_table"); + l_cfunc(lua, l_cf_gui_goto_view, "goto_view"); + l_cfunc(lua, l_cf_gui_gtkmenu, "gtkmenu"); + l_mt(lua, "_gui_mt", l_gui_mt_index, l_gui_mt_newindex); lua_setglobal(lua, "gui"); lua_getglobal(lua, "_G"); @@ -185,46 +183,46 @@ static GtkWidget *l_checkview(lua_State *lua, int narg) { } /** - * Adds a Scintilla window to the global 'views' table with a metatable. + * Adds a Scintilla window to the global '_VIEWS' table with a metatable. * @param editor The Scintilla window to add. */ void l_add_scintilla_window(GtkWidget *editor) { lua_getfield(lua, LUA_REGISTRYINDEX, "views"); lua_newtable(lua); - lua_pushlightuserdata(lua, (GtkWidget *)editor); - lua_setfield(lua, -2, "widget_pointer"); - l_cfunc(lua, l_cf_view_split, "split"); - l_cfunc(lua, l_cf_view_unsplit, "unsplit"); - l_cfunc(lua, l_cf_view_goto_buffer, "goto_buffer"); - l_cfunc(lua, l_cf_view_focus, "focus"); - l_mt(lua, "_view_mt", l_view_mt_index, l_view_mt_newindex); + lua_pushlightuserdata(lua, (GtkWidget *)editor); + lua_setfield(lua, -2, "widget_pointer"); + l_cfunc(lua, l_cf_view_focus, "focus"); + l_cfunc(lua, l_cf_view_goto_buffer, "goto_buffer"); + l_cfunc(lua, l_cf_view_split, "split"); + l_cfunc(lua, l_cf_view_unsplit, "unsplit"); + l_mt(lua, "_view_mt", l_view_mt_index, l_view_mt_newindex); l_append(lua, -2); // pops table lua_pop(lua, 1); // views } /** - * Removes a Scintilla window from the global 'views' table. + * Removes a Scintilla window from the global '_VIEWS' table. * @param editor The Scintilla window to remove. */ void l_remove_scintilla_window(GtkWidget *editor) { lua_newtable(lua); - lua_getfield(lua, LUA_REGISTRYINDEX, "views"); - lua_pushnil(lua); - while (lua_next(lua, -2)) - (editor != l_checkview(lua, -1)) ? l_append(lua, -4) : lua_pop(lua, 1); - lua_pop(lua, 1); // views + lua_getfield(lua, LUA_REGISTRYINDEX, "views"); + lua_pushnil(lua); + while (lua_next(lua, -2)) + (editor != l_checkview(lua, -1)) ? l_append(lua, -4) : lua_pop(lua, 1); + lua_pop(lua, 1); // views lua_pushvalue(lua, -1); lua_setfield(lua, LUA_REGISTRYINDEX, "views"); lua_setglobal(lua, "_VIEWS"); } /** - * Changes focus a Scintilla window in the global 'views' table. + * Changes focus a Scintilla window in the global '_VIEWS' table. * @param editor The currently focused Scintilla window. - * @param n The index of the window in the 'views' table to focus. - * @param absolute Flag indicating whether or not the index specified in 'views' - * is absolute. If FALSE, focuses the window relative to the currently focused - * window for the given index. + * @param n The index of the window in the '_VIEWS' table to focus. + * @param absolute Flag indicating whether or not the index specified in + * '_VIEWS' is absolute. If FALSE, focuses the window relative to the + * currently focused window for the given index. * Throws an error if the view does not exist. */ void l_goto_scintilla_window(GtkWidget *editor, int n, int absolute) { @@ -290,18 +288,18 @@ static sptr_t l_checkdocpointer(lua_State *lua, int narg) { } /** - * Adds a Scintilla document to the global 'buffers' table with a metatable. + * Adds a Scintilla document to the global '_BUFFERS' table with a metatable. * @param doc The Scintilla document to add. * @return integer index of the new buffer in _BUFFERS. */ int l_add_scintilla_buffer(sptr_t doc) { lua_getfield(lua, LUA_REGISTRYINDEX, "buffers"); lua_newtable(lua); - lua_pushinteger(lua, doc); - lua_setfield(lua, -2, "doc_pointer"); - l_cfunc(lua, l_cf_buffer_text_range, "text_range"); - l_cfunc(lua, l_cf_buffer_delete, "delete"); - l_mt(lua, "_buffer_mt", l_buffer_mt_index, l_buffer_mt_newindex); + lua_pushinteger(lua, doc); + lua_setfield(lua, -2, "doc_pointer"); + l_cfunc(lua, l_cf_buffer_delete, "delete"); + l_cfunc(lua, l_cf_buffer_text_range, "text_range"); + l_mt(lua, "_buffer_mt", l_buffer_mt_index, l_buffer_mt_newindex); l_append(lua, -2); // pops table int index = lua_objlen(lua, -1); lua_pop(lua, 1); // buffers @@ -309,7 +307,7 @@ int l_add_scintilla_buffer(sptr_t doc) { } /** - * Removes a Scintilla document from the global 'buffers' table. + * Removes a Scintilla document from the global '_BUFFERS' table. * If any views currently show the document to be removed, change the documents * they show first. * @param doc The Scintilla buffer to remove. @@ -325,18 +323,18 @@ void l_remove_scintilla_buffer(sptr_t doc) { } lua_pop(lua, 1); // views lua_newtable(lua); - lua_getfield(lua, LUA_REGISTRYINDEX, "buffers"); - lua_pushnil(lua); - while (lua_next(lua, -2)) - (doc != l_checkdocpointer(lua, -1)) ? l_append(lua, -4) : lua_pop(lua, 1); - lua_pop(lua, 1); // buffers + lua_getfield(lua, LUA_REGISTRYINDEX, "buffers"); + lua_pushnil(lua); + while (lua_next(lua, -2)) + (doc != l_checkdocpointer(lua, -1)) ? l_append(lua, -4) : lua_pop(lua, 1); + lua_pop(lua, 1); // buffers lua_pushvalue(lua, -1); lua_setfield(lua, LUA_REGISTRYINDEX, "buffers"); lua_setglobal(lua, "_BUFFERS"); } /** - * Retrieves the index in the global 'buffers' table for a given Scintilla + * Retrieves the index in the global '_BUFFERS' table for a given Scintilla * document. * @param doc The Scintilla document to get the index of. */ @@ -355,15 +353,15 @@ unsigned int l_get_docpointer_index(sptr_t doc) { } /** - * Changes a Scintilla window's document to one in the global 'buffers' table. + * Changes a Scintilla window's document to one in the global '_BUFFERS' table. * Before doing so, it saves the scroll and caret positions in the current * Scintilla document. Then when the new document is shown, its scroll and caret * positions are restored. * @param editor The Scintilla window to change the document of. - * @param n The index of the document in 'buffers' to focus. - * @param absolute Flag indicating whether or not the index specified in 'views' - * is absolute. If FALSE, focuses the document relative to the currently - * focused document for the given index. + * @param n The index of the document in '_BUFFERS' to focus. + * @param absolute Flag indicating whether or not the index specified in + * '_BUFFERS' is absolute. If FALSE, focuses the document relative to the + * currently focused document for the given index. * Throws an error if the buffer does not exist. */ void l_goto_scintilla_buffer(GtkWidget *editor, int n, int absolute) { diff --git a/src/textadept.c b/src/textadept.c index c3948634..142ea4da 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -44,13 +44,13 @@ static void find_button_clicked(GtkWidget *, gpointer); // Command Entry GtkWidget *command_entry; -GtkListStore *cec_store; +GtkListStore *cc_store; GtkEntryCompletion *command_entry_completion; -static int cec_match_func(GtkEntryCompletion *, const char *, GtkTreeIter *, - gpointer); -static gbool cec_match_selected(GtkEntryCompletion *, GtkTreeModel *, - GtkTreeIter *, gpointer); +static int cc_match_func(GtkEntryCompletion *, const char *, GtkTreeIter *, + gpointer); +static gbool cc_match_selected(GtkEntryCompletion *, GtkTreeModel *, + GtkTreeIter *, gpointer); static void c_activated(GtkWidget *, gpointer); static gbool c_keypress(GtkWidget *, GdkEventKey *, gpointer); @@ -169,18 +169,17 @@ void create_ui() { gtk_widget_set_name(command_entry, "textadept-command-entry"); signal(command_entry, "activate", c_activated); signal(command_entry, "key-press-event", c_keypress); - g_object_set(G_OBJECT(command_entry), "width-request", 200, NULL); gtk_box_pack_start(GTK_BOX(hboxs), command_entry, TRUE, TRUE, 0); command_entry_completion = gtk_entry_completion_new(); - signal(command_entry_completion, "match-selected", cec_match_selected); - gtk_entry_completion_set_match_func(command_entry_completion, cec_match_func, + signal(command_entry_completion, "match-selected", cc_match_selected); + gtk_entry_completion_set_match_func(command_entry_completion, cc_match_func, NULL, NULL); gtk_entry_completion_set_popup_set_width(command_entry_completion, FALSE); gtk_entry_completion_set_text_column(command_entry_completion, 0); - cec_store = gtk_list_store_new(1, G_TYPE_STRING); + cc_store = gtk_list_store_new(1, G_TYPE_STRING); gtk_entry_completion_set_model(command_entry_completion, - GTK_TREE_MODEL(cec_store)); + GTK_TREE_MODEL(cc_store)); gtk_entry_set_completion(GTK_ENTRY(command_entry), command_entry_completion); docstatusbar = gtk_statusbar_new(); @@ -201,7 +200,6 @@ void create_ui() { /** * Creates a new Scintilla window. * The Scintilla window is the GTK widget that displays a Scintilla buffer. - * The window's default properties are set via 'set_default_editor_properties'. * Generates a 'view_new' event. * @param buffer_id A Scintilla buffer ID to load into the new window. If NULL, * creates a new Scintilla buffer and loads it into the new window. @@ -240,8 +238,6 @@ void remove_scintilla_window(GtkWidget *editor) { /** * Creates a new Scintilla buffer for a newly created Scintilla window. - * The buffer's default properties are set via 'set_default_buffer_properties', - * but the default style is set here. * Generates a 'buffer_new' event. * @param editor The Scintilla window to associate the buffer with. * @param create Flag indicating whether or not to create a buffer. If FALSE, @@ -364,7 +360,7 @@ int unsplit_window(GtkWidget *editor) { /** * Sets a user-defined GTK menubar and displays it. * @param new_menubar The GTK menubar. - * @see l_ta_mt_newindex + * @see l_gui_mt_newindex */ void set_menubar(GtkWidget *new_menubar) { GtkWidget *vbox = gtk_widget_get_parent(menubar); @@ -691,8 +687,8 @@ void ce_toggle_focus() { * results from a call to Lua to make a list of possible completions. Therefore, * every item in the list is valid. */ -static int cec_match_func(GtkEntryCompletion *entry, const char *key, - GtkTreeIter *iter, gpointer udata) { +static int cc_match_func(GtkEntryCompletion *entry, const char *key, + GtkTreeIter *iter, gpointer udata) { return 1; } @@ -701,7 +697,7 @@ static int cec_match_func(GtkEntryCompletion *entry, const char *key, * The last word at the cursor is replaced with the completion. A word consists * of any alphanumeric character or underscore. */ -static gbool cec_match_selected(GtkEntryCompletion *entry, GtkTreeModel *model, +static gbool cc_match_selected(GtkEntryCompletion *entry, GtkTreeModel *model, GtkTreeIter *iter, gpointer udata) { const char *entry_text = gtk_entry_get_text(GTK_ENTRY(command_entry)); const char *p = entry_text + strlen(entry_text) - 1; @@ -719,7 +715,7 @@ static gbool cec_match_selected(GtkEntryCompletion *entry, GtkTreeModel *model, g_signal_emit_by_name(G_OBJECT(command_entry), "insert-at-cursor", text, 0); g_free(text); - gtk_list_store_clear(cec_store); + gtk_list_store_clear(cc_store); return TRUE; } |