diff options
author | 2010-06-11 00:24:35 -0400 | |
---|---|---|
committer | 2010-06-11 00:24:35 -0400 | |
commit | 7a4800f05f26067a1cef77e5431256aab4c3d675 (patch) | |
tree | c20a86c11384fd8adb88af3acdd7d7757ebd0555 | |
parent | c83387e378f72b303d692d951da841b581b3d453 (diff) | |
download | textadept-7a4800f05f26067a1cef77e5431256aab4c3d675.tar.gz textadept-7a4800f05f26067a1cef77e5431256aab4c3d675.zip |
Renamed textadept.events to events, renamed 'handle' and 'add_handler'.
-rw-r--r-- | core/events.lua | 56 | ||||
-rw-r--r-- | core/ext/command_entry.lua | 6 | ||||
-rw-r--r-- | core/ext/find.lua | 15 | ||||
-rw-r--r-- | core/ext/key_commands.lua | 13 | ||||
-rw-r--r-- | core/ext/menu.lua | 11 | ||||
-rw-r--r-- | core/file_io.lua | 17 | ||||
-rw-r--r-- | core/init.lua | 2 | ||||
-rw-r--r-- | modules/textadept/bookmarks.lua | 2 | ||||
-rw-r--r-- | modules/textadept/editing.lua | 11 | ||||
-rw-r--r-- | modules/textadept/mime_types.lua | 15 | ||||
-rw-r--r-- | modules/textadept/run.lua | 2 | ||||
-rw-r--r-- | modules/textadept/session.lua | 5 | ||||
-rw-r--r-- | src/lua_interface.c | 52 | ||||
-rw-r--r-- | src/textadept.c | 49 | ||||
-rw-r--r-- | src/textadept.h | 4 |
15 files changed, 130 insertions, 130 deletions
diff --git a/core/events.lua b/core/events.lua index 0ef56b58..900ccbb3 100644 --- a/core/events.lua +++ b/core/events.lua @@ -5,7 +5,7 @@ local locale = _G.locale --- -- Textadept's core event structure and handlers. -module('textadept.events', package.seeall) +module('events', package.seeall) -- Markdown: -- ## Overview @@ -143,10 +143,10 @@ module('textadept.events', package.seeall) -- textadept.print(message) -- end -- --- textadept.events.add_handler('my_event', my_event_handler) --- textadept.events.handle('my_event', 'my message') +-- events.connect('my_event', my_event_handler) +-- events.emit('my_event', 'my message') -local events = textadept.events +local events = events --- -- Adds a handler function to an event. @@ -154,7 +154,7 @@ local events = textadept.events -- anywhere. -- @param f The Lua function to add. -- @param index Optional index to insert the handler into. -function add_handler(event, f, index) +function connect(event, f, index) local plural = event..'s' if not events[plural] then events[plural] = {} end local handlers = events[plural] @@ -173,7 +173,7 @@ end -- @param event The string event name. -- @param ... Arguments passed to the handler. -- @return true or false if any handler explicitly returned such; nil otherwise. -function handle(event, ...) +function emit(event, ...) local plural = event..'s' local handlers = events[plural] if not handlers then return end @@ -183,6 +183,9 @@ function handle(event, ...) end end +local connect = connect +local emit = emit + --- Map of Scintilla notifications to their handlers. local c = textadept.constants local scnnotifications = { @@ -207,13 +210,13 @@ function notification(n) if f then local args = { unpack(f, 2) } for k, v in ipairs(args) do args[k] = n[v] end - return handle(f[1], unpack(args)) + return emit(f[1], unpack(args)) end end -- Default handlers to follow. -add_handler('view_new', +connect('view_new', function() -- sets default properties for a Scintilla window local buffer = buffer local c = textadept.constants @@ -239,7 +242,7 @@ add_handler('view_new', end end) -add_handler('buffer_new', +connect('buffer_new', function() -- sets default properties for a Scintilla document local function run() local buffer = buffer @@ -284,19 +287,19 @@ local function set_title(buffer) filename) end -add_handler('save_point_reached', +connect('save_point_reached', function() -- changes Textadept title to show 'clean' buffer buffer.dirty = false set_title(buffer) end) -add_handler('save_point_left', +connect('save_point_left', function() -- changes Textadept title to show 'dirty' buffer buffer.dirty = true set_title(buffer) end) -add_handler('uri_dropped', +connect('uri_dropped', function(utf8_uris) local lfs = require 'lfs' for utf8_uri in utf8_uris:gmatch('[^\r\n\f]+') do @@ -318,7 +321,7 @@ local EOLs = { locale.STATUS_CR, locale.STATUS_LF } -add_handler('update_ui', +connect('update_ui', function() -- sets docstatusbar text local buffer = buffer local pos = buffer.current_pos @@ -333,15 +336,15 @@ add_handler('update_ui', locale.DOCSTATUSBAR_TEXT:format(line, max, col, lexer, eol, tabs, enc) end) -add_handler('margin_click', +connect('margin_click', function(margin, modifiers, position) -- toggles folding local line = buffer:line_from_position(position) buffer:toggle_fold(line) end) -add_handler('buffer_new', function() set_title(buffer) end) +connect('buffer_new', function() set_title(buffer) end) -add_handler('buffer_before_switch', +connect('buffer_before_switch', function() -- save buffer properties local buffer = buffer -- Save view state. @@ -361,7 +364,7 @@ add_handler('buffer_before_switch', end end) -add_handler('buffer_after_switch', +connect('buffer_after_switch', function() -- restore buffer properties local buffer = buffer if not buffer._folds then return end @@ -374,19 +377,19 @@ add_handler('buffer_after_switch', buffer.first_visible_line) end) -add_handler('buffer_after_switch', +connect('buffer_after_switch', function() -- updates titlebar and statusbar set_title(buffer) - handle('update_ui') + emit('update_ui') end) -add_handler('view_after_switch', +connect('view_after_switch', function() -- updates titlebar and statusbar set_title(buffer) - handle('update_ui') + emit('update_ui') end) -add_handler('quit', +connect('quit', function() -- prompts for confirmation if any buffers are dirty local any = false local list = {} @@ -411,10 +414,10 @@ add_handler('quit', end) if MAC then - add_handler('appleevent_odoc', - function(uri) return handle('uri_dropped', 'file://'..uri) end) + connect('appleevent_odoc', + function(uri) return emit('uri_dropped', 'file://'..uri) end) - textadept.events.add_handler('buffer_new', + connect('buffer_new', function() buffer.paste = function() local clipboard_text = textadept.clipboard_text @@ -423,5 +426,4 @@ if MAC then end) end -add_handler('error', - function(...) textadept._print(locale.ERROR_BUFFER, ...) end) +connect('error', function(...) textadept._print(locale.ERROR_BUFFER, ...) end) diff --git a/core/ext/command_entry.lua b/core/ext/command_entry.lua index 34dfbe13..c29a2180 100644 --- a/core/ext/command_entry.lua +++ b/core/ext/command_entry.lua @@ -3,7 +3,7 @@ local textadept = _G.textadept local locale = _G.locale -textadept.events.add_handler('command_entry_command', +events.connect('command_entry_command', function(command) -- execute a Lua command local f, err = loadstring(command) if err then error(err) end @@ -11,10 +11,10 @@ textadept.events.add_handler('command_entry_command', f() end) -textadept.events.add_handler('command_entry_keypress', +events.connect('command_entry_keypress', function(code) local ce = textadept.command_entry - local KEYSYMS = textadept.keys.KEYSYMS + local KEYSYMS = keys.KEYSYMS if KEYSYMS[code] == 'esc' then ce.focus() -- toggle focus to hide return true diff --git a/core/ext/find.lua b/core/ext/find.lua index f8cf27c8..9aebaaee 100644 --- a/core/ext/find.lua +++ b/core/ext/find.lua @@ -2,6 +2,7 @@ local textadept = _G.textadept local locale = _G.locale +local events = _G.events local find = textadept.find local lfs = require 'lfs' @@ -150,7 +151,7 @@ local function find_(text, next, flags, nowrap, wrapped) return result end -textadept.events.add_handler('find', find_) +events.connect('find', find_) -- Finds and selects text incrementally in the current buffer from a start -- point. @@ -172,7 +173,7 @@ function find.find_incremental() textadept.command_entry.focus() end -textadept.events.add_handler('command_entry_keypress', +events.connect('command_entry_keypress', function(code) if find.incremental then if code == 0xff1b then -- escape @@ -188,7 +189,7 @@ textadept.events.add_handler('command_entry_keypress', end end, 1) -- place before command_entry.lua's handler (if necessary) -textadept.events.add_handler('command_entry_command', +events.connect('command_entry_command', function(text) -- 'find next' for incremental search if find.incremental then find.incremental_start = buffer.current_pos + 1 @@ -240,7 +241,7 @@ local function replace(rtext) buffer:goto_pos(buffer.current_pos) end end -textadept.events.add_handler('replace', replace) +events.connect('replace', replace) -- Replaces all found text. -- If any text is selected, all found text in that selection is replaced. @@ -288,7 +289,7 @@ local function replace_all(ftext, rtext, flags) string.format(locale.FIND_REPLACEMENTS_MADE, tostring(count)) buffer:end_undo_action() end -textadept.events.add_handler('replace_all', replace_all) +events.connect('replace_all', replace_all) -- When the user double-clicks a found file, go to the line in the file the text -- was found at. @@ -326,7 +327,7 @@ local function goto_file(pos, line_num) end end end -textadept.events.add_handler('double_click', goto_file) +events.connect('double_click', goto_file) -- LuaDoc is in core/.find.lua. function find.goto_file_in_list(next) @@ -359,5 +360,5 @@ function find.goto_file_in_list(next) end if buffer then buffer:marker_set_back(MARK_FIND, MARK_FIND_COLOR) end -textadept.events.add_handler('view_new', +events.connect('view_new', function() buffer:marker_set_back(MARK_FIND, MARK_FIND_COLOR) end) diff --git a/core/ext/key_commands.lua b/core/ext/key_commands.lua index 297cb3a8..93f02713 100644 --- a/core/ext/key_commands.lua +++ b/core/ext/key_commands.lua @@ -2,6 +2,7 @@ local textadept = _G.textadept local locale = _G.locale +local events = _G.events --- -- Manages and defines key commands in Textadept. @@ -246,7 +247,7 @@ if not MAC then elseif type(state) == 'number' then buffer[setting] = buffer[setting] == 0 and 1 or 0 end - t.events.handle('update_ui') -- for updating statusbar + events.emit('update_ui') -- for updating statusbar end keys.ct.v = { e = { toggle_setting, 'view_eol' }, @@ -274,7 +275,7 @@ if not MAC then -- Miscellaneous not in standard menu. -- Recent files. local RECENT_FILES = 1 - t.events.add_handler('user_list_selection', + events.connect('user_list_selection', function(type, text) if type == RECENT_FILES then io.open_file(text) end end) @@ -408,7 +409,7 @@ else elseif type(state) == 'number' then buffer[setting] = buffer[setting] == 0 and 1 or 0 end - t.events.handle('update_ui') -- for updating statusbar + events.emit('update_ui') -- for updating statusbar end keys.at.v = { e = { toggle_setting, 'view_eol' }, @@ -436,7 +437,7 @@ else -- Miscellaneous not in standard menu. -- Recent files. local RECENT_FILES = 1 - t.events.add_handler('user_list_selection', + events.connect('user_list_selection', function(type, text) if type == RECENT_FILES then io.open_file(text) end end) @@ -589,7 +590,7 @@ local function keypress(code, shift, control, alt) if ch:find('[%p%d]') and #keychain == 0 then if buffer.anchor ~= buffer.current_pos then buffer:delete_back() end buffer:add_text(ch) - textadept.events.handle('char_added', code) + events.emit('char_added', code) return true end end @@ -649,4 +650,4 @@ local function keypress(code, shift, control, alt) end end end -textadept.events.add_handler('keypress', keypress, 1) +events.connect('keypress', keypress, 1) diff --git a/core/ext/menu.lua b/core/ext/menu.lua index 7fede4da..ee60bc60 100644 --- a/core/ext/menu.lua +++ b/core/ext/menu.lua @@ -2,6 +2,7 @@ local textadept = _G.textadept local locale = _G.locale +local events = _G.events --- -- Provides dynamic menus for Textadept. @@ -291,7 +292,7 @@ local m_run = _m.textadept.run local function set_encoding(encoding) buffer:set_encoding(encoding) - t.events.handle('update_ui') -- for updating statusbar + events.emit('update_ui') -- for updating statusbar end local function toggle_setting(setting) local state = buffer[setting] @@ -300,17 +301,17 @@ local function toggle_setting(setting) elseif type(state) == 'number' then buffer[setting] = buffer[setting] == 0 and 1 or 0 end - t.events.handle('update_ui') -- for updating statusbar + events.emit('update_ui') -- for updating statusbar end local function set_eol_mode(mode) buffer.eol_mode = mode buffer:convert_eo_ls(mode) - t.events.handle('update_ui') -- for updating statusbar + events.emit('update_ui') -- for updating statusbar end local function set_lexer(lexer) buffer:set_lexer(lexer) buffer:colourise(0, -1) - t.events.handle('update_ui') -- for updating statusbar + events.emit('update_ui') -- for updating statusbar end local function open_webpage(url) local cmd @@ -475,7 +476,7 @@ local actions = { } -- Most of this handling code comes from keys.lua. -t.events.add_handler('menu_clicked', +events.connect('menu_clicked', function(menu_id) local active_table = actions[menu_id] if menu_id >= ID.LEXER_START and menu_id < ID.LEXER_START + 99 then diff --git a/core/file_io.lua b/core/file_io.lua index d08907f5..a994b34a 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -2,6 +2,7 @@ local textadept = _G.textadept local locale = _G.locale +local events = _G.events --- -- Extends Lua's io package to provide file input/output routines for Textadept. @@ -30,7 +31,7 @@ module('io', package.seeall) -- -- Example: -- --- textadept.events.add_handler('file_opened', +-- events.connect('file_opened', -- function(utf8_filename) -- local filename = textadept.iconv(utf8_filename, _CHARSET, 'UTF-8') -- local f = io.open(filename, 'rb') @@ -170,7 +171,7 @@ local function open_helper(utf8_filename) end buffer.filename = utf8_filename buffer:set_save_point() - textadept.events.handle('file_opened', utf8_filename) + events.emit('file_opened', utf8_filename) for index, file in ipairs(recent_files) do if file == utf8_filename then @@ -242,7 +243,7 @@ end local function save(buffer) textadept.check_focused_buffer(buffer) if not buffer.filename then return buffer:save_as() end - textadept.events.handle('file_before_save', buffer.filename) + events.emit('file_before_save', buffer.filename) local text = buffer:get_text(buffer.length) if buffer.encoding then local bom = buffer.encoding_bom or '' @@ -277,7 +278,7 @@ local function save_as(buffer, utf8_filename) if #utf8_filename > 0 then buffer.filename = utf8_filename buffer:save() - textadept.events.handle('file_saved_as', utf8_filename) + events.emit('file_saved_as', utf8_filename) end end @@ -351,10 +352,10 @@ local function update_modified_file() end end end -textadept.events.add_handler('buffer_after_switch', update_modified_file) -textadept.events.add_handler('view_after_switch', update_modified_file) +events.connect('buffer_after_switch', update_modified_file) +events.connect('view_after_switch', update_modified_file) -textadept.events.add_handler('buffer_new', +events.connect('buffer_new', function() -- set additional buffer functions local buffer = buffer buffer.reload = reload @@ -365,7 +366,7 @@ textadept.events.add_handler('buffer_new', buffer.encoding = 'UTF-8' end) -textadept.events.add_handler('file_opened', +events.connect('file_opened', function(utf8_filename) -- close initial 'Untitled' buffer local b = textadept.buffers[1] if #textadept.buffers == 2 and not (b.filename or b._type or b.dirty) then diff --git a/core/init.lua b/core/init.lua index f1468202..fcf8e354 100644 --- a/core/init.lua +++ b/core/init.lua @@ -64,7 +64,7 @@ function textadept._print(buffer_type, ...) if not message_buffer then message_buffer = textadept.new_buffer() message_buffer._type = buffer_type - textadept.events.handle('file_opened') + events.emit('file_opened') else message_view:goto_buffer(message_buffer_index, true) end diff --git a/modules/textadept/bookmarks.lua b/modules/textadept/bookmarks.lua index c94fb256..2b95df1d 100644 --- a/modules/textadept/bookmarks.lua +++ b/modules/textadept/bookmarks.lua @@ -78,5 +78,5 @@ function goto_prev() end if buffer then buffer:marker_set_back(MARK_BOOKMARK, MARK_BOOKMARK_COLOR) end -textadept.events.add_handler('view_new', +events.connect('view_new', function() buffer:marker_set_back(MARK_BOOKMARK, MARK_BOOKMARK_COLOR) end) diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index bb53b3ad..2d1586a2 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -2,6 +2,7 @@ local textadept = _G.textadept local locale = _G.locale +local events = _G.events --- -- Editing commands for the textadept module. @@ -73,14 +74,14 @@ local braces = { -- () [] {} <> -- Used for displaying call tips. local current_call_tip = {} -textadept.events.add_handler('char_added', +events.connect('char_added', function(c) -- matches characters specified in char_matches if AUTOPAIR and char_matches[c] and buffer.selections == 1 then buffer:insert_text(-1, char_matches[c]) end end) -textadept.events.add_handler('keypress', +events.connect('keypress', function(code, shift, control, alt) -- removes matched chars on backspace if AUTOPAIR and code == 0xff08 and buffer.selections == 1 then local buffer = buffer @@ -93,7 +94,7 @@ textadept.events.add_handler('keypress', end end) -textadept.events.add_handler('update_ui', +events.connect('update_ui', function() -- highlights matching braces local buffer = buffer local current_pos = buffer.current_pos @@ -110,7 +111,7 @@ textadept.events.add_handler('update_ui', end end) -textadept.events.add_handler('char_added', +events.connect('char_added', function(char) -- auto-indent on return if not AUTOINDENT or char ~= 10 then return end local buffer = buffer @@ -270,7 +271,7 @@ function prepare_for_save() buffer:convert_eo_ls(buffer.eol_mode) buffer:end_undo_action() end -textadept.events.add_handler('file_before_save', prepare_for_save) +events.connect('file_before_save', prepare_for_save) --- -- Cuts or copies text ranges intelligently. (Behaves like Emacs.) diff --git a/modules/textadept/mime_types.lua b/modules/textadept/mime_types.lua index ba7a33c3..f3265b53 100644 --- a/modules/textadept/mime_types.lua +++ b/modules/textadept/mime_types.lua @@ -2,6 +2,7 @@ local textadept = _G.textadept local locale = _G.locale +local events = _G.events --- -- Handles file-specific settings. @@ -204,8 +205,7 @@ local function set_lexer(buffer, lang) end buffer:colourise(0, -1) end -textadept.events.add_handler('buffer_new', - function() buffer.set_lexer = set_lexer end) +events.connect('buffer_new', function() buffer.set_lexer = set_lexer end) -- Scintilla's first buffer doesn't have this if not RESETTING then buffer.set_lexer = set_lexer end @@ -242,12 +242,11 @@ local function restore_lexer() buffer:set_lexer_language(buffer._lexer or 'container') end -textadept.events.add_handler('file_opened', handle_new) -textadept.events.add_handler('file_saved_as', handle_new) -textadept.events.add_handler('buffer_after_switch', restore_lexer) -textadept.events.add_handler('view_new', restore_lexer) -textadept.events.add_handler('reset_after', - function() buffer:set_lexer(buffer._lexer) end) +events.connect('file_opened', handle_new) +events.connect('file_saved_as', handle_new) +events.connect('buffer_after_switch', restore_lexer) +events.connect('view_new', restore_lexer) +events.connect('reset_after', function() buffer:set_lexer(buffer._lexer) end) --- -- Prompts the user to select a lexer from a filtered list for the current diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua index c14e8e2d..a576ff27 100644 --- a/modules/textadept/run.lua +++ b/modules/textadept/run.lua @@ -130,4 +130,4 @@ function goto_error(pos, line_num) end end end -textadept.events.add_handler('double_click', goto_error) +events.connect('double_click', goto_error) diff --git a/modules/textadept/session.lua b/modules/textadept/session.lua index 30d9e823..3535bca1 100644 --- a/modules/textadept/session.lua +++ b/modules/textadept/session.lua @@ -51,7 +51,7 @@ function load(filename) else textadept.new_buffer() buffer._type = filename - textadept.events.handle('file_opened', filename) + events.handle('file_opened', filename) end -- Restore saved buffer selection and view. local anchor = tonumber(anchor) or 0 @@ -168,5 +168,4 @@ function save(filename) end end -textadept.events.add_handler('quit', - function() if SAVE_ON_QUIT then save() end end, 1) +events.connect('quit', function() if SAVE_ON_QUIT then save() end end, 1) 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 |