aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/events.lua10
-rw-r--r--core/gui.lua12
-rw-r--r--core/init.lua6
-rw-r--r--init.lua7
-rw-r--r--modules/textadept/editing.lua2
-rw-r--r--modules/textadept/keys.lua3
-rw-r--r--modules/textadept/session.lua8
-rw-r--r--src/lua_interface.c114
-rw-r--r--src/textadept.c32
9 files changed, 92 insertions, 102 deletions
diff --git a/core/events.lua b/core/events.lua
index 3313d919..15c6f77c 100644
--- a/core/events.lua
+++ b/core/events.lua
@@ -143,8 +143,6 @@ module('events', package.seeall)
-- events.connect('my_event', my_event_handler)
-- events.emit('my_event', 'my message')
-local events = events
-
---
-- Adds a handler function to an event.
-- @param event The string event name. It is arbitrary and need not be defined
@@ -155,8 +153,8 @@ local events = events
-- @see disconnect
function connect(event, f, index)
local plural = event..'s'
- if not events[plural] then events[plural] = {} end
- local handlers = events[plural]
+ if not _M[plural] then _M[plural] = {} end
+ local handlers = _M[plural]
if index then
table.insert(handlers, index, f)
else
@@ -187,7 +185,7 @@ end
-- @return true or false if any handler explicitly returned such; nil otherwise.
function emit(event, ...)
local plural = event..'s'
- local handlers = events[plural]
+ local handlers = _M[plural]
if not handlers then return end
for _, f in ipairs(handlers) do
local result = f(unpack{...})
@@ -430,7 +428,7 @@ if MAC then
function(uri) return emit('uri_dropped', 'file://'..uri) end)
connect('buffer_new',
- function()
+ function() -- GTK-OSX has clipboard problems
buffer.paste = function()
local clipboard_text = gui.clipboard_text
if #clipboard_text > 0 then buffer:replace_sel(clipboard_text) end
diff --git a/core/gui.lua b/core/gui.lua
index e317ecd6..9f49be19 100644
--- a/core/gui.lua
+++ b/core/gui.lua
@@ -61,12 +61,12 @@ function gui.switch_buffer()
end
local out =
gui.dialog('filteredlist',
- '--title', locale.SWITCH_BUFFERS,
- '--button1', 'gtk-ok',
- '--button2', 'gtk-cancel',
- '--no-newline',
- '--columns', 'Name', 'File',
- '--items', unpack(items))
+ '--title', locale.SWITCH_BUFFERS,
+ '--button1', 'gtk-ok',
+ '--button2', 'gtk-cancel',
+ '--no-newline',
+ '--columns', 'Name', 'File',
+ '--items', unpack(items))
local i = tonumber(out:match('%-?%d+$'))
if i and i >= 0 then view:goto_buffer(i + 1, true) end
end
diff --git a/core/init.lua b/core/init.lua
index cb880579..dda18806 100644
--- a/core/init.lua
+++ b/core/init.lua
@@ -26,8 +26,8 @@ if f then
end
if not _THEME:find('[/\\]') then
local theme = _THEME
- _THEME = _HOME..'/themes/'..theme
- if not lfs.attributes(_THEME) then _THEME = _USERHOME..'/themes/'..theme end
+ _THEME = _USERHOME..'/themes/'..theme
+ if not lfs.attributes(_THEME) then _THEME = _HOME..'/themes/'..theme end
end
require 'iface'
@@ -36,8 +36,6 @@ require 'events'
require 'file_io'
require 'gui'
-rawset = nil -- do not allow modifications which could compromise stability
-
-- LuaDoc is in core/._G.lua.
function _G.user_dofile(filename)
if lfs.attributes(_USERHOME..'/'..filename) then
diff --git a/init.lua b/init.lua
index 46e3db83..effeb987 100644
--- a/init.lua
+++ b/init.lua
@@ -19,7 +19,7 @@ if not RESETTING then
local P, C = lpeg.P, lpeg.C
local param = P('"') * C((1 - P('"'))^0) * '"' + C((1 - P(' '))^1)
local args = lpeg.match(lpeg.Ct(param * (P(' ') * param)^0), arg[0])
- for _, a in ipairs(args) do arg[#arg + 1] = a end
+ for i = 1, #args do arg[#arg + 1] = args[i] end
end
-- process command line arguments
@@ -28,7 +28,8 @@ if not RESETTING then
_m.textadept.session.load()
else
-- process command line switches
- for i, switch in ipairs(arg) do
+ for i = 1, #arg do
+ local switch = arg[i]
if switch == '-ns' or switch == '--no-session' then
_m.textadept.session.SAVE_ON_QUIT = false
table.remove(arg, i)
@@ -36,6 +37,6 @@ if not RESETTING then
end
-- open files
- for _, filename in ipairs(arg) do io.open_file(filename) end
+ for i = 1, #arg do io.open_file(arg[i]) end
end
end
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index 6c8cd680..8de26f08 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -321,7 +321,7 @@ end
---
-- Reduces multiple characters occurances to just one.
--- If char is not given, the character to be squeezed is the one under the
+-- If char is not given, the character to be squeezed is the one behind the
-- caret.
-- @param char The character (integer) to be used for squeezing.
function squeeze(char)
diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua
index 0d65f76a..f5cd0914 100644
--- a/modules/textadept/keys.lua
+++ b/modules/textadept/keys.lua
@@ -489,7 +489,6 @@ local string = _G.string
local string_char = string.char
local string_format = string.format
local pcall = _G.pcall
-local ipairs = _G.ipairs
local next = _G.next
local type = _G.type
local unpack = _G.unpack
@@ -537,7 +536,7 @@ end
-- of -1. This way, pcall will return false and -1, where the -1 can easily and
-- efficiently be checked rather than using a string error message.
local function try_get_cmd(active_table)
- for _, key_seq in ipairs(keychain) do active_table = active_table[key_seq] end
+ for i = 1, #keychain do active_table = active_table[keychain[i]] end
if #active_table == 0 and next(active_table) then
gui.statusbar_text = locale.KEYCHAIN..table.concat(keychain, ' ')
error(-1, 0)
diff --git a/modules/textadept/session.lua b/modules/textadept/session.lua
index ce347d24..0ddfa2f9 100644
--- a/modules/textadept/session.lua
+++ b/modules/textadept/session.lua
@@ -50,7 +50,7 @@ function load(filename)
else
new_buffer()
buffer._type = filename
- events.handle('file_opened', filename)
+ events.emit('file_opened', filename)
end
-- Restore saved buffer selection and view.
local anchor = tonumber(anchor) or 0
@@ -148,9 +148,9 @@ function save(filename)
end
-- Write out the current focused view.
local current_view = view
- for index, view in ipairs(_VIEWS) do
- if view == current_view then
- current_view = index
+ for i = 1, #_VIEWS do
+ if _VIEWS[i] == current_view then
+ current_view = i
break
end
end
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;
}