diff options
author | mitchell <70453897+667e-11@users.noreply.github.com> | 2011-06-23 22:35:20 -0400 |
---|---|---|
committer | mitchell <70453897+667e-11@users.noreply.github.com> | 2011-06-23 22:35:20 -0400 |
commit | e22d2bf663a4cc4fbeed5730c8f0ec7a446e43c8 (patch) | |
tree | 76df894b4f5468c3d85d990129e1e13b890e4ea9 | |
parent | 79a37f07e3f57694a436db9a25e296c8d177041a (diff) |
Use string constants for event names.
-rw-r--r-- | core/.command_entry.luadoc | 17 | ||||
-rw-r--r-- | core/.find.luadoc | 17 | ||||
-rw-r--r-- | core/args.lua | 9 | ||||
-rw-r--r-- | core/events.lua | 254 | ||||
-rw-r--r-- | core/file_io.lua | 53 | ||||
-rw-r--r-- | core/gui.lua | 44 | ||||
-rw-r--r-- | core/keys.lua | 18 | ||||
-rw-r--r-- | core/locale.conf | 1 | ||||
-rw-r--r-- | modules/lua/init.lua | 2 | ||||
-rw-r--r-- | modules/textadept/adeptsense.lua | 10 | ||||
-rw-r--r-- | modules/textadept/bookmarks.lua | 2 | ||||
-rw-r--r-- | modules/textadept/command_entry.lua | 7 | ||||
-rw-r--r-- | modules/textadept/editing.lua | 14 | ||||
-rw-r--r-- | modules/textadept/filter_through.lua | 5 | ||||
-rw-r--r-- | modules/textadept/find.lua | 14 | ||||
-rw-r--r-- | modules/textadept/keys.lua | 4 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 25 | ||||
-rw-r--r-- | modules/textadept/mime_types.lua | 31 | ||||
-rw-r--r-- | modules/textadept/run.lua | 2 | ||||
-rw-r--r-- | modules/textadept/session.lua | 4 | ||||
-rw-r--r-- | modules/textadept/snippets.lua | 2 |
21 files changed, 249 insertions, 286 deletions
diff --git a/core/.command_entry.luadoc b/core/.command_entry.luadoc index 0eb996c0..03c52eb0 100644 --- a/core/.command_entry.luadoc +++ b/core/.command_entry.luadoc @@ -10,23 +10,6 @@ module('gui.command_entry') -- ## Fields -- -- * `entry_text` [string]: The text in the entry. --- --- ## Events --- --- The following is a list of all command entry events generated in --- `event_name(arguments)` format: --- --- * **command\_entry\_command** (command)<br /> --- Called when a command is entered into the Command Entry. --- - command: the string command. --- * **command\_entry\_keypress** (code, shift, control, alt)<br /> --- Called when a key is pressed in the Command Entry. --- - code: the key code (according to `<gdk/gdkkeysyms.h>`). --- - shift: flag indicating whether or not the Shift key is pressed. --- - control: flag indicating whether or not the Control key is pressed. --- - alt: flag indicating whether or not the Alt/Apple key is pressed. --- <br /> --- Note: The Alt-Option key in Mac OSX is not available. --- Focuses the command entry. function focus() end diff --git a/core/.find.luadoc b/core/.find.luadoc index 3b68e7af..b5e3dd99 100644 --- a/core/.find.luadoc +++ b/core/.find.luadoc @@ -15,23 +15,6 @@ module('gui.find') -- * `whole_word` [bool]: Only whole-word matches are allowed in searches. -- * `lua` [bool]: The search text is interpreted as a Lua pattern. -- * `in_files` [bool]: Search for the text in a list of files. --- --- ## Events --- --- The following is a list of all find events generated in --- `event_name(arguments)` format: --- --- * **find** (text, next)<br /> --- Called when attempting to finding text via the Find dialog box. --- - text: the text to search for. --- - next: flat indicating whether or not the search direction is forward. --- * **replace** (text)<br /> --- Called when the found text is selected and asked to be replaced. --- - text: the text to replace the selected text with. --- * **replace\_all** (find\_text, repl\_text)<br /> --- Called when all occurances of found text are to be replaced. --- - find\_text: the text to search for. --- - repl\_text: the text to replace found text with. --- -- Displays and focuses the find/replace dialog. diff --git a/core/args.lua b/core/args.lua index d9f959e1..06fc6137 100644 --- a/core/args.lua +++ b/core/args.lua @@ -4,13 +4,10 @@ module('args', package.seeall) -- Markdown: --- ## Events +-- ## Arg Events -- --- The following is a list of all arg events generated in --- `event_name(arguments)` format: --- --- * **arg\_none** ()<br /> --- Called when no command line args have been passed to Textadept on init. +-- * `'arg_none'`: Called when no command line arguments are passed to Textadept +-- on init. local arg = arg diff --git a/core/events.lua b/core/events.lua index e5a73c8e..022ccad1 100644 --- a/core/events.lua +++ b/core/events.lua @@ -29,121 +29,128 @@ module('events', package.seeall) -- -- ## Textadept Events -- --- The following is a list of all Scintilla events generated by Textadept in --- `event_name(arguments)` format: +-- This is the set of default events that Textadept emits with the arguments +-- they pass. Events that modules emit are listed on their respective LuaDoc +-- pages. -- --- * **char\_added** (ch)<br /> --- Called when an ordinary text character is added to the buffer. --- - ch: the ASCII representation of the character. --- * **save\_point\_reached** ()<br /> --- Called when a save point is entered. --- * **save\_point\_left** ()<br /> --- Called when a save point is left. --- * **double\_click** (modifiers, position, line)<br /> --- Called when the mouse button is double-clicked. --- - modifiers: the appropriate combination of `SCI_SHIFT`, `SCI_CTRL`, --- and `SCI_ALT` to indicate the keys that were held down at the time of --- the double click. --- - position: the text position the click occured at. --- - line: the line number the click occured at. --- * **update\_ui** ()<br /> --- Called when the text or styling of the buffer has changed or the selection --- range has changed. --- * **margin\_click** (margin, modifiers, position)<br /> --- Called when the mouse is clicked inside a margin. --- - margin: the margin number that was clicked. --- - modifiers: the appropriate combination of `SCI_SHIFT`, `SCI_CTRL`, --- and `SCI_ALT` to indicate the keys that were held down at the time of --- the margin click. --- - position: The position of the start of the line in the buffer that +-- * `APPLEEVENT_ODOC`: Called when Mac OSX tells Textadept to open a document. +-- <br /> +-- * `uri`: The URI to open. +-- * `AUTO_C_CHAR_DELETED`: Called when the user deleted a character while the +-- autocompletion list was active. +-- * `AUTO_C_RELEASE`: Called when the user has cancelled the autocompletion +-- list. +-- * `AUTO_C_SELECTION`: Called when the user has selected an item in an +-- autocompletion list and before the selection is inserted. Automatic +-- insertion can be cancelled by calling `buffer:auto_c_cancel()` before +-- returning from the event handler.<br /> +-- * `text`: The text of the selection. +-- * `position`: The start position of the word being completed. +-- * `BUFFER_AFTER_SWITCH`: Called right after a buffer is switched to. +-- * `BUFFER_BEFORE_SWITCH`: Called right before another buffer is switched to. +-- * `BUFFER_DELETED`: Called after a buffer was deleted. +-- * `BUFFER_NEW`: Called when a new buffer is created. +-- * `CALL_TIP_CLICK`: Called when the user clicks on a calltip. +-- <br /> +-- * `position`: Set to 1 if the click is in an up arrow, 2 if in a down +-- arrow, and 0 if elsewhere. +-- * `CHAR_ADDED`: Called when an ordinary text character is added to the +-- buffer.<br /> +-- * `ch`: The text character byte. +-- * `COMMAND_ENTRY_COMMAND`: Called when a command is entered into the Command +-- Entry.<br /> +-- * `command`: The command text. +-- * `COMMAND_ENTRY_KEYPRESS`: Called when a key is pressed in the Command +-- Entry.<br /> +-- * `code`: The key code. +-- * `shift`: The Shift key is held down. +-- * `ctrl`: The Control key is held down. +-- * `alt`: The Alt/Apple key is held down. +-- * `DOUBLE_CLICK`: Called when the mouse button is double-clicked.<br /> +-- * `position`: The text position of the double click. +-- * `line`: The line of the double click. +-- * `modifiers`: The key modifiers held down. It is a combination of zero +-- or more of `_SCINTILLA.constants.SCMOD_ALT`, +-- `_SCINTILLA.constants.SCMOD_CTRL`, +-- `_SCINTILLA.constants.SCMOD_SHIFT`, and +-- `_SCINTILLA.constants.SCMOD_META`. +-- * `ERROR`: Called when an error occurs.<br /> +-- * `text`: The error text. +-- * `FIND`: Called when finding text via the Find dialog box.<br /> +-- * `text`: The text to search for. +-- * `next`: Search forward. +-- * `HOTSPOT_CLICK`: Called when the user clicks on text that is in a style +-- with the hotspot attribute set.<br /> +-- * `position`: The text position of the click. +-- * `modifiers`: The key modifiers held down. It is a combination of zero +-- or more of `_SCINTILLA.constants.SCMOD_ALT`, +-- `_SCINTILLA.constants.SCMOD_CTRL`, +-- `_SCINTILLA.constants.SCMOD_SHIFT`, and +-- `_SCINTILLA.constants.SCMOD_META`. +-- * `HOTSPOT_DOUBLE_CLICK`: Called when the user double clicks on text that is +-- in a style with the hotspot attribute set.<br /> +-- * `position`: The text position of the double click. +-- * `modifiers`: The key modifiers held down. It is a combination of zero +-- or more of `_SCINTILLA.constants.SCMOD_ALT`, +-- `_SCINTILLA.constants.SCMOD_CTRL`, +-- `_SCINTILLA.constants.SCMOD_SHIFT`, and +-- `_SCINTILLA.constants.SCMOD_META`. +-- * `HOTSPOT_RELEASE_CLICK`: Called when the user releases the mouse on text +-- that is in a style with the hotspot attribute set.<br /> +-- * `position`: The text position of the release. +-- * `INDICATOR_CLICK`: Called when the user clicks the mouse on text that has +-- an indicator.<br /> +-- * `position`: The text position of the click. +-- * `modifiers`: The key modifiers held down. It is a combination of zero +-- or more of `_SCINTILLA.constants.SCMOD_ALT`, +-- `_SCINTILLA.constants.SCMOD_CTRL`, +-- `_SCINTILLA.constants.SCMOD_SHIFT`, and +-- `_SCINTILLA.constants.SCMOD_META`. +-- * `INDICATOR_RELEASE`: Called when the user releases the mouse on text that +-- has an indicator.<br /> +-- * `position`: The text position of the release. +-- * `KEYPRESS`: Called when a key is pressed.<br /> +-- * `code`: The key code. +-- * `shift`: The Shift key is held down. +-- * `ctrl`: The Control key is held down. +-- * `alt`: The Alt/Apple key is held down. +-- * `MARGIN_CLICK`: Called when the mouse is clicked inside a margin.<br /> +-- * `margin`: The margin number that was clicked. +-- * `position`: The position of the start of the line in the buffer that -- corresponds to the margin click. --- * **user\_list\_selection** (wParam, text, position)<br /> --- Called when the user has selected an item in a user list. --- - wParam: the list_type parameter from --- [`buffer:user_list_show()`][buffer_user_list_show]. --- - text: the text of the selection. --- - position: the position the list was displayed at. --- * **uri\_dropped** (text)<br /> --- Called when the user has dragged a URI such as a file name or web address --- into Textadept. --- - text: URI text. --- * **hotspot\_click** (position, modifiers)<br /> --- Called when the user clicks on a hotspot. --- - position: the position in the buffer that the user clicked --- - modifiers: the appropriate combination of `SCI_SHIFT`, `SCI_CTRL`, --- and `SCI_ALT` to indicate the keys that were held down at the time of --- the hotspot click. --- * **hotspot\_double\_click** (position, modifiers)<br /> --- Called when the user double-clicks on a hotspot. --- - position: the position in the buffer that the user double-clicked --- - modifiers: the appropriate combination of `SCI_SHIFT`, `SCI_CTRL`, --- and `SCI_ALT` to indicate the keys that were held down at the time of --- the hotspot double-click. --- * **call\_tip\_click** (position)<br /> --- Called when the user clicks on a calltip. --- - position: 1 if the click is in an up arrow, 2 if in a down arrow, and --- 0 if elsewhere. --- * **auto\_c\_selection** (text, position)<br /> --- Called when the user has selected an item in an autocompletion list. --- - text: the text of the selection. --- - position: the start position of the word being completed. --- * **indicator\_click** (position, modifiers)<br /> --- Called when the user clicks on an indicator. --- - position: the position in the buffer that the user clicked. --- - modifiers: the appropriate combination of `SCI_SHIFT`, `SCI_CTRL`, --- and `SCI_ALT` to indicate the keys that were held down at the time of --- the indicator click. --- * **indicator\_release** (position)<br /> --- Called when the user releases the mouse button after clicking on an --- indicator. --- - position: the position in the buffer that the user clicked. --- * **auto\_c\_cancelled** ()<br /> --- Called when the user has cancelled the autocompletion list. --- * **auto\_c\_char\_deleted** ()<br /> --- Called when the user deleted a character while the autocompletion list was --- active. --- * **hotspot\_release\_click** (position)<br /> --- Called when the user releases the mouse button after clicking on a hotspot. --- - position: the position in the buffer that the user clicked. --- --- [buffer_user_list_show]: ../modules/buffer.html#buffer:user_list_show --- --- The following is a list of gui events generated in --- `event_name(arguments)` format: --- --- * **buffer\_new** ()<br /> --- Called when a new [buffer][buffer] is created. --- * **buffer\_deleted** ()<br /> --- Called when a [buffer][buffer] has been deleted. --- * **buffer\_before\_switch** ()<br /> --- Called right before another [buffer][buffer] is switched to. --- * **buffer\_after\_switch** ()<br /> --- Called right after a [buffer][buffer] was switched to. --- * **view\_new** ()<br /> --- Called when a new [view][view] is created. --- * **view\_before\_switch** ()<br /> --- Called right before another [view][view] is switched to. --- * **view\_after\_switch** ()<br /> --- Called right after [view][view] was switched to. --- * **reset\_before** ()<br /> --- Called before resetting the Lua state during a call to [`reset()`][reset]. --- * **reset\_after** ()<br /> --- Called after resetting the Lua state during a call to [`reset()`][reset]. --- * **quit** ()<br /> --- Called when quitting Textadept.<br /> --- Note: Any quit handlers added must be inserted at index 1 because the --- default quit handler in `core/events.lua` returns `true`, which ignores all --- subsequent handlers. --- * **error** (text)<br /> --- Called when an error occurs in the C code. --- - text: The error text. --- * **appleevent\_odoc** (uri)<br /> --- Called when Mac OSX instructs Textadept to open a document. --- - uri: The URI to open. --- --- [buffer]: ../modules/buffer.html --- [view]: ../modules/view.html --- [reset]: ../modules/_G.html#reset +-- * `modifiers`: The appropriate combination of +-- `_SCINTILLA.constants.SCI_SHIFT`, `_SCINTILLA.constants.SCI_CTRL`, +-- and `_SCINTILLA.constants.SCI_ALT` to indicate the keys that were +-- held down at the time of the margin click. +-- * `MENU_CLICKED`: Called when a menu item is selected.<br /> +-- * `menu_id`: The numeric ID of the menu item set in `gui.gtkmenu()`. +-- * `QUIT`: Called when quitting Textadept. When connecting to this event, +-- connect with an index of 1 or the handler will be ignored. +-- * `REPLACE`: Called to replace selected (found) text.<br /> +-- * `text`: The text to replace selected text with. +-- * `REPLACE_ALL`: Called to replace all occurances of found text.<br /> +-- * `find_text`: The text to search for. +-- * `repl_text`: The text to replace found text with. +-- * `RESET_AFTER`: Called after resetting the Lua state. This is triggered by +-- `_G.reset()`. +-- * `RESET_BEFORE`: Called before resetting the Lua state. This is triggered by +-- `_G.reset()`. +-- * `SAVE_POINT_LEFT`: Called when a save point is left. +-- * `SAVE_POINT_REACHED`: Called when a save point is entered. +-- * `UPDATE_UI`: Called when either the text or styling of the buffer has +-- changed or the selection range has changed. +-- * `URI_DROPPED`: Called when the user has dragged a URI such as a file name +-- onto the view.<br /> +-- * `text`: The URI text. +-- * `USER_LIST_SELECTION`: Called when the user has selected an item in a user +-- list.<br /> +-- * `list_type`: This is set to the list_type parameter from the +-- `buffer:user_list_show()` call that initiated the list. +-- * `text`: The text of the selection. +-- * `position`: The position the list was displayed at. +-- * `VIEW_NEW`: Called when a new view is created. +-- * `VIEW_BEFORE_SWITCH`: Called right before another view is switched to. +-- * `VIEW_AFTER_SWITCH`: Called right after another view is switched to. -- -- ## Example -- @@ -154,7 +161,7 @@ module('events', package.seeall) -- end -- -- events.connect('my_event', my_event_handler) --- events.emit('my_event', 'my message') +-- events.emit('my_event', 'my message') -- prints 'my message' to a view --- -- A table of event names and a table of functions connected to them. @@ -173,6 +180,7 @@ local handlers = handlers -- @return Index of handler. -- @see disconnect function connect(event, f, index) + if not event then error(L('Undefined event name')) end if not handlers[event] then handlers[event] = {} end local h = handlers[event] if index then table.insert(h, index, f) else h[#h + 1] = f end @@ -200,6 +208,7 @@ local error_emitted = false -- @param ... Arguments passed to the handler. -- @return true or false if any handler explicitly returned such; nil otherwise. function emit(event, ...) + if not event then error(L('Undefined event name')) end local h = handlers[event] if not h then return end local pcall, unpack, type = _G.pcall, _G.unpack, _G.type @@ -208,7 +217,7 @@ function emit(event, ...) if not ok then if not error_emitted then error_emitted = true - emit('error', result) + emit(events.ERROR, result) error_emitted = false else io.stderr:write(result) @@ -224,9 +233,9 @@ local scnnotifications = { [c.SCN_CHARADDED] = { 'char_added', 'ch' }, [c.SCN_SAVEPOINTREACHED] = { 'save_point_reached' }, [c.SCN_SAVEPOINTLEFT] = { 'save_point_left' }, - [c.SCN_DOUBLECLICK] = { 'double_click', 'modifiers', 'position', 'line' }, + [c.SCN_DOUBLECLICK] = { 'double_click', 'position', 'line', 'modifiers' }, [c.SCN_UPDATEUI] = { 'update_ui' }, - [c.SCN_MARGINCLICK] = { 'margin_click', 'margin', 'modifiers', 'position' }, + [c.SCN_MARGINCLICK] = { 'margin_click', 'margin', 'position', 'modifiers' }, [c.SCN_USERLISTSELECTION] = { 'user_list_selection', 'wParam', 'text', 'position' }, @@ -255,3 +264,14 @@ function notification(n) for i = 2, #f do args[i - 1] = n[f[i]] end return emit(f[1], unpack(args)) end + +-- Set event constants. +for _, n in pairs(scnnotifications) do _M[n[1]:upper()] = n[1] end +local ta_events = { + 'appleevent_odoc', 'buffer_after_switch', 'buffer_before_switch', + 'buffer_deleted', 'buffer_new', 'command_entry_command', + 'command_entry_keypress', 'error', 'find', 'keypress', 'menu_clicked', 'quit', + 'replace', 'replace_all', 'reset_after', 'reset_before', 'view_after_switch', + 'view_before_switch', 'view_new' +} +for _, e in pairs(ta_events) do _M[e:upper()] = e end diff --git a/core/file_io.lua b/core/file_io.lua index c583e365..016b66da 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -18,7 +18,7 @@ module('io', package.seeall) -- -- Example: -- --- events.connect('file_opened', +-- events.connect(events.FILE_OPENED, -- function(utf8_filename) -- local filename = utf8_filename:iconv(_CHARSET, 'UTF-8') -- local f = io.open(filename, 'rb') @@ -28,23 +28,26 @@ module('io', package.seeall) -- -- [string_iconv]: ../modules/string.html#iconv -- --- ## Events +-- ## File Events -- --- The following is a list of all file I/O events generated in --- `event_name(arguments)` format: --- --- * **file\_opened** (filename) <br /> --- Called when a file has been opened in a new buffer. --- - filename: the filename encoded in UTF-8. --- * **file\_before\_save** (filename) <br /> --- Called right before a file is saved to disk. --- - filename: the filename encoded in UTF-8. --- * **file\_after\_save** (filename) <br /> --- Called right after a file is saved to disk. --- - filename: the filename encoded in UTF-8. --- * **file\_saved_as** (filename) <br /> --- Called when a file is saved under another filename. --- - filename: the other filename encoded in UTF-8. +-- * `_G.events.FILE_OPENED`: Called when a file is opened in a new buffer. +-- Arguments:<br /> +-- * `filename`: The filename encoded in UTF-8. +-- * `_G.events.FILE_BEFORE_SAVE`: Called right before a file is saved to disk. +-- Arguments:<br /> +-- * `filename`: The filename encoded in UTF-8. +-- * `_G.events.FILE_AFTER_SAVE`: Called right after a file is saved to disk. +-- Arguments:<br /> +-- * `filename`: The filename encoded in UTF-8. +-- * `_G.events.FILE_SAVED_AS`: Called when a file is saved under a different +-- filename. Arguments:<br /> +-- * `filename`: The filename encoded in UTF-8. + +-- Events. +events.FILE_OPENED = 'file_opened' +events.FILE_BEFORE_SAVE = 'file_before_save' +events.FILE_AFTER_SAVE = 'file_after_save' +events.FILE_SAVED_AS = 'file_saved_as' --- -- List of recently opened files. @@ -154,7 +157,7 @@ local function open_helper(utf8_filename) buffer.modification_time = lfs.attributes(filename).modification buffer.filename = utf8_filename buffer:set_save_point() - events.emit('file_opened', utf8_filename) + events.emit(events.FILE_OPENED, utf8_filename) -- Add file to recent files list, eliminating duplicates. for i, file in ipairs(recent_files) do @@ -222,7 +225,7 @@ end local function save(buffer) gui.check_focused_buffer(buffer) if not buffer.filename then return buffer:save_as() end - events.emit('file_before_save', buffer.filename) + events.emit(events.FILE_BEFORE_SAVE, buffer.filename) local text = buffer:get_text(buffer.length) if buffer.encoding then local bom = buffer.encoding_bom or '' @@ -236,7 +239,7 @@ local function save(buffer) buffer:set_save_point() buffer.modification_time = lfs.attributes(filename).modification if buffer._type then buffer._type = nil end - events.emit('file_after_save', buffer.filename) + events.emit(events.FILE_AFTER_SAVE, buffer.filename) end -- LuaDoc is in core/.buffer.luadoc. @@ -254,7 +257,7 @@ local function save_as(buffer, utf8_filename) if #utf8_filename > 0 then buffer.filename = utf8_filename buffer:save() - events.emit('file_saved_as', utf8_filename) + events.emit(events.FILE_SAVED_AS, utf8_filename) end end @@ -327,11 +330,11 @@ local function update_modified_file() end end end -events.connect('buffer_after_switch', update_modified_file) -events.connect('view_after_switch', update_modified_file) +events.connect(events.BUFFER_AFTER_SWITCH, update_modified_file) +events.connect(events.VIEW_AFTER_SWITCH, update_modified_file) -- Set additional buffer functions. -events.connect('buffer_new', function() +events.connect(events.BUFFER_NEW, function() local buffer = buffer buffer.reload = reload buffer.set_encoding = set_encoding @@ -342,7 +345,7 @@ events.connect('buffer_new', function() end) -- Close initial 'Untitled' buffer. -events.connect('file_opened', function(utf8_filename) +events.connect(events.FILE_OPENED, function(utf8_filename) local b = _BUFFERS[1] if #_BUFFERS == 2 and not (b.filename or b._type or b.dirty) then view:goto_buffer(1, true) diff --git a/core/gui.lua b/core/gui.lua index 3cb97dfe..36c25165 100644 --- a/core/gui.lua +++ b/core/gui.lua @@ -36,7 +36,7 @@ function gui._print(buffer_type, ...) if not message_buffer then message_buffer = new_buffer() message_buffer._type = buffer_type - events.emit('file_opened') + events.emit(events.FILE_OPENED) else message_view:goto_buffer(message_buffer_index, true) end @@ -90,7 +90,7 @@ end local connect = _G.events.connect -- Sets default properties for a Scintilla window. -connect('view_new', function() +connect(events.VIEW_NEW, function() local buffer = buffer local c = _SCINTILLA.constants @@ -111,13 +111,13 @@ connect('view_new', function() if not ok then io.stderr:write(err) end end end) -connect('view_new', function() events.emit('update_ui') end) +connect(events.VIEW_NEW, function() events.emit(events.UPDATE_UI) end) local SETDIRECTFUNCTION = _SCINTILLA.properties.direct_function[1] local SETDIRECTPOINTER = _SCINTILLA.properties.doc_pointer[2] local SETLEXERLANGUAGE = _SCINTILLA.functions.set_lexer_language[1] -- Sets default properties for a Scintilla document. -connect('buffer_new', function() +connect(events.BUFFER_NEW, function() local function run() local buffer = buffer @@ -151,7 +151,7 @@ connect('buffer_new', function() local ok, err = pcall(run) if not ok then io.stderr:write(err) end end) -connect('buffer_new', function() events.emit('update_ui') end) +connect(events.BUFFER_NEW, function() events.emit(events.UPDATE_UI) end) -- Sets the title of the Textadept window to the buffer's filename. -- @param buffer The currently focused buffer. @@ -162,19 +162,19 @@ local function set_title(buffer) end -- Changes Textadept title to show 'clean' buffer. -connect('save_point_reached', function() +connect(events.SAVE_POINT_REACHED, function() buffer.dirty = false set_title(buffer) end) -- Changes Textadept title to show 'dirty' buffer. -connect('save_point_left', function() +connect(events.SAVE_POINT_LEFT, function() buffer.dirty = true set_title(buffer) end) -- Open uri(s). -connect('uri_dropped', function(utf8_uris) +connect(events.URI_DROPPED, function(utf8_uris) for utf8_uri in utf8_uris:gmatch('[^\r\n]+') do if utf8_uri:find('^file://') then utf8_uri = utf8_uri:match('^file://([^\r\n]+)') @@ -187,14 +187,14 @@ connect('uri_dropped', function(utf8_uris) end end end) -connect('appleevent_odoc', - function(uri) return events.emit('uri_dropped', 'file://'..uri) end) +connect(events.APPLEEVENT_ODOC, + function(uri) return events.emit(events.URI_DROPPED, 'file://'..uri) end) local string_format = string.format local EOLs = { L('CRLF'), L('CR'), L('LF') } local GETLEXERLANGUAGE = _SCINTILLA.functions.get_lexer_language[1] -- Sets docstatusbar text. -connect('update_ui', function() +connect(events.UPDATE_UI, function() local buffer = buffer local pos = buffer.current_pos local line, max = buffer:line_from_position(pos) + 1, buffer.line_count @@ -210,14 +210,14 @@ connect('update_ui', function() end) -- Toggles folding. -connect('margin_click', function(margin, modifiers, position) +connect(events.MARGIN_CLICK, function(margin, position, modifiers) buffer:toggle_fold(buffer:line_from_position(position)) end) -connect('buffer_new', function() set_title(buffer) end) +connect(events.BUFFER_NEW, function() set_title(buffer) end) -- Save buffer properties. -connect('buffer_before_switch', function() +connect(events.BUFFER_BEFORE_SWITCH, function() local buffer = buffer -- Save view state. buffer._anchor = buffer.anchor @@ -234,7 +234,7 @@ connect('buffer_before_switch', function() end) -- Restore buffer properties. -connect('buffer_after_switch', function() +connect(events.BUFFER_AFTER_SWITCH, function() local buffer = buffer if not buffer._folds then return end -- Restore fold state. @@ -247,21 +247,21 @@ connect('buffer_after_switch', function() end) -- Updates titlebar and statusbar. -connect('buffer_after_switch', function() +connect(events.BUFFER_AFTER_SWITCH, function() set_title(buffer) - events.emit('update_ui') + events.emit(events.UPDATE_UI) end) -- Updates titlebar and statusbar. -connect('view_after_switch', function() +connect(events.VIEW_AFTER_SWITCH, function() set_title(buffer) - events.emit('update_ui') + events.emit(events.UPDATE_UI) end) -connect('reset_after', function() gui.statusbar_text = 'Lua reset' end) +connect(events.RESET_AFTER, function() gui.statusbar_text = 'Lua reset' end) -- Prompts for confirmation if any buffers are dirty. -connect('quit', function() +connect(events.QUIT, function() local list = {} for _, buffer in ipairs(_BUFFERS) do if buffer.dirty then @@ -282,4 +282,4 @@ connect('quit', function() return true end) -connect('error', function(...) gui._print(L('[Error Buffer]'), ...) end) +connect(events.ERROR, function(...) gui._print(L('[Error Buffer]'), ...) end) diff --git a/core/keys.lua b/core/keys.lua index e3170793..bdd146ad 100644 --- a/core/keys.lua +++ b/core/keys.lua @@ -83,20 +83,6 @@ module('keys', package.seeall) -- All Lua functions must be defined BEFORE they are reference in key commands. -- Therefore, any module containing key commands should be loaded after all -- other modules, whose functions are being referenced, have been loaded. --- --- ## Events --- --- The following is a list of all key events generated in --- `event_name(arguments)` format: --- --- * **keypress** (code, shift, control, alt)<br /> --- Called when a key is pressed. --- - code: the key code (according to `<gdk/gdkkeysyms.h>`). --- - shift: flag indicating whether or not the Shift key is pressed. --- - control: flag indicating whether or not the Control key is pressed. --- - alt: flag indicating whether or not the Alt/Apple key is pressed. --- <br /> --- Note: The Alt-Option key in Mac OSX is not available. -- settings local ADD = '' @@ -114,7 +100,7 @@ local type = _G.type local unpack = _G.unpack local no_args = {} local getmetatable = getmetatable -local error = function(e) events.emit('error', e) end +local error = function(e) events.emit(events.ERROR, e) end --- -- Lookup table for key values higher than 255. @@ -248,4 +234,4 @@ local function keypress(code, shift, control, alt) end -- PROPAGATE otherwise. end -events.connect('keypress', keypress, 1) +events.connect(events.KEYPRESS, keypress, 1) diff --git a/core/locale.conf b/core/locale.conf index 741df6f4..f76aee58 100644 --- a/core/locale.conf +++ b/core/locale.conf @@ -29,6 +29,7 @@ Quit without saving? = Quit without saving? The following buffers are unsaved: = The following buffers are unsaved: Quit _without saving = Quit _without saving [Error Buffer] = [Error Buffer] +Undefined event name = Undefined event name % core/file_io.lua Encoding conversion failed. = Encoding conversion failed. diff --git a/modules/lua/init.lua b/modules/lua/init.lua index cca7e3cb..1e88e8c6 100644 --- a/modules/lua/init.lua +++ b/modules/lua/init.lua @@ -145,7 +145,7 @@ function goto_required() end end -events.connect('file_after_save', +events.connect(events.FILE_AFTER_SAVE, function() -- show syntax errors as annotations if buffer:get_lexer() == 'lua' then local buffer = buffer diff --git a/modules/textadept/adeptsense.lua b/modules/textadept/adeptsense.lua index 82ea7bea..f7166660 100644 --- a/modules/textadept/adeptsense.lua +++ b/modules/textadept/adeptsense.lua @@ -523,7 +523,7 @@ end function add_trigger(sense, c, only_fields, only_functions) if #c > 2 then return end -- TODO: warn local c1, c2 = c:match('.$'):byte(), #c > 1 and c:sub(1, 1):byte() - local i = events.connect('char_added', function(char) + local i = events.connect(events.CHAR_ADDED, function(char) if char == c1 and buffer:get_lexer(true) == sense.lexer then if c2 and buffer.char_at[buffer.current_pos - 2] ~= c2 then return end sense:complete(only_fields, only_functions) @@ -604,7 +604,7 @@ function show_apidoc(sense) end buffer:call_tip_show(buffer.current_pos, apidocs[apidocs.pos or 1]) -- Cycle through calltips. - local event_id = events.connect('call_tip_click', function(position) + local event_id = events.connect(events.CALL_TIP_CLICK, function(position) apidocs.pos = apidocs.pos + (position == 1 and -1 or 1) if apidocs.pos > #apidocs then apidocs.pos = 1 end if apidocs.pos < 1 then apidocs.pos = #apidocs end @@ -612,7 +612,7 @@ function show_apidoc(sense) end) _G.timeout(1, function() if pcall(buffer.call_tip_active, buffer) then return true end - events.disconnect('call_tip_click', event_id) + events.disconnect(events.CALL_TIP_CLICK, event_id) end) return true end @@ -776,7 +776,9 @@ function new(lang) if sense then sense.ctags_kinds = {} sense.api_files = {} - for _, i in ipairs(sense.events) do events.disconnect('char_added', i) end + for _, i in ipairs(sense.events) do + events.disconnect(events.CHAR_ADDED, i) + end sense.events = {} sense:clear() end diff --git a/modules/textadept/bookmarks.lua b/modules/textadept/bookmarks.lua index 7db46b65..d4f01cf0 100644 --- a/modules/textadept/bookmarks.lua +++ b/modules/textadept/bookmarks.lua @@ -86,5 +86,5 @@ function goto() end if buffer then buffer:marker_set_back(MARK_BOOKMARK, MARK_BOOKMARK_COLOR) end -events.connect('view_new', +events.connect(events.VIEW_NEW, function() buffer:marker_set_back(MARK_BOOKMARK, MARK_BOOKMARK_COLOR) end) diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua index eac4c99e..6eaf8daa 100644 --- a/modules/textadept/command_entry.lua +++ b/modules/textadept/command_entry.lua @@ -2,6 +2,7 @@ -- Modified by Jay Gould. local L = _G.locale.localize +local events = _G.events -- Environment for abbreviated commands. -- @class table @@ -28,16 +29,16 @@ local env = setmetatable({}, { }) -- Execute a Lua command. -events.connect('command_entry_command', function(command) +events.connect(events.COMMAND_ENTRY_COMMAND, function(command) local f, err = loadstring(command) if err then error(err) end gui.command_entry.focus() -- toggle focus to hide setfenv(f, env) f() - events.emit('update_ui') + events.emit(events.UPDATE_UI) end) -events.connect('command_entry_keypress', function(code) +events.connect(events.COMMAND_ENTRY_KEYPRESS, function(code) local ce = gui.command_entry local KEYSYMS = keys.KEYSYMS if KEYSYMS[code] == 'esc' then diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index 557f3be4..cf61af71 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -79,7 +79,7 @@ braces = { -- () [] {} local current_call_tip = {} -- Matches characters specified in char_matches. -events.connect('char_added', function(c) +events.connect(events.CHAR_ADDED, function(c) if not AUTOPAIR then return end local buffer = buffer local match = (char_matches[buffer:get_lexer()] or char_matches)[c] @@ -87,7 +87,7 @@ events.connect('char_added', function(c) end) -- Removes matched chars on backspace. -events.connect('keypress', function(code, shift, control, alt) +events.connect(events.KEYPRESS, function(code, shift, control, alt) if not AUTOPAIR or K[code] ~= '\b' or buffer.selections ~= 1 then return end local buffer = buffer local pos = buffer.current_pos @@ -97,7 +97,7 @@ events.connect('keypress', function(code, shift, control, alt) end) -- Highlights matching braces. -events.connect('update_ui', function() +events.connect(events.UPDATE_UI, function() if not HIGHLIGHT_BRACES then return end local buffer = buffer local current_pos = buffer.current_pos @@ -114,7 +114,7 @@ events.connect('update_ui', function() end) -- Auto-indent on return. -events.connect('char_added', function(char) +events.connect(events.CHAR_ADDED, function(char) if not AUTOINDENT or char ~= 10 then return end local buffer = buffer local anchor, caret = buffer.anchor, buffer.current_pos @@ -272,7 +272,7 @@ function prepare_for_save() buffer:convert_eo_ls(buffer.eol_mode) buffer:end_undo_action() end -events.connect('file_before_save', prepare_for_save) +events.connect(events.FILE_BEFORE_SAVE, prepare_for_save) --- -- Selects the current word under the caret and if action indicates, deletes it. @@ -445,7 +445,7 @@ local function clear_highlighted_words() buffer.indicator_current = INDIC_HIGHLIGHT buffer:indicator_clear_range(0, buffer.length) end -events.connect('keypress', +events.connect(events.KEYPRESS, function(c) if K[c] == 'esc' then clear_highlighted_words() end end) --- @@ -484,4 +484,4 @@ local function set_highlight_properties() buffer.indic_alpha[INDIC_HIGHLIGHT] = INDIC_HIGHLIGHT_ALPHA end if buffer then set_highlight_properties() end -events.connect('view_new', set_highlight_properties) +events.connect(events.VIEW_NEW, set_highlight_properties) diff --git a/modules/textadept/filter_through.lua b/modules/textadept/filter_through.lua index 6861166f..8f6b70db 100644 --- a/modules/textadept/filter_through.lua +++ b/modules/textadept/filter_through.lua @@ -1,6 +1,7 @@ -- Copyright 2007-2011 Mitchell mitchell<att>caladbolg.net. See LICENSE. local L = _G.locale.localize +local events = _G.events --- -- Filter-Through for the textadept module. @@ -26,14 +27,14 @@ function filter_through() gui.command_entry.focus() end -events.connect('command_entry_keypress', function(code) +events.connect(events.COMMAND_ENTRY_KEYPRESS, function(code) if filter_through_active and code == 0xff1b then -- escape filter_through_active = false end end, 1) -- place before command_entry.lua's handler (if necessary) -- Filter through. -events.connect('command_entry_command', function(text) +events.connect(events.COMMAND_ENTRY_COMMAND, function(text) if filter_through_active then local buffer = buffer local s, e = buffer.selection_start, buffer.selection_end diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index f770e2dd..4010a5d6 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -144,7 +144,7 @@ local function find_(text, next, flags, nowrap, wrapped) return result end -events.connect('find', find_) +events.connect(events.FIND, find_) -- Finds and selects text incrementally in the current buffer from a start -- point. @@ -164,7 +164,7 @@ function find.find_incremental() gui.command_entry.focus() end -events.connect('command_entry_keypress', function(code) +events.connect(events.COMMAND_ENTRY_KEYPRESS, function(code) local K = _G.keys.KEYSYMS if find.incremental then if K[code] == 'esc' then @@ -181,7 +181,7 @@ events.connect('command_entry_keypress', function(code) end, 1) -- place before command_entry.lua's handler (if necessary) -- 'Find next' for incremental search. -events.connect('command_entry_command', function(text) +events.connect(events.COMMAND_ENTRY_COMMAND, function(text) if find.incremental then find.incremental_start = buffer.current_pos + 1 find_incremental(text) @@ -241,7 +241,7 @@ local function replace(rtext) buffer:goto_pos(buffer.current_pos) end end -events.connect('replace', replace) +events.connect(events.REPLACE, replace) -- Replaces all found text. -- If any text is selected, all found text in that selection is replaced. @@ -287,7 +287,7 @@ local function replace_all(ftext, rtext, flags) gui.statusbar_text = ("%d %s"):format(count, L('replacement(s) made')) buffer:end_undo_action() end -events.connect('replace_all', replace_all) +events.connect(events.REPLACE_ALL, replace_all) -- When the user double-clicks a found file, go to the line in the file the text -- was found at. @@ -325,7 +325,7 @@ local function goto_file(pos, line_num) end end end -events.connect('double_click', goto_file) +events.connect(events.DOUBLE_CLICK, goto_file) -- LuaDoc is in core/.find.luadoc. function find.goto_file_in_list(next) @@ -358,5 +358,5 @@ function find.goto_file_in_list(next) end if buffer then buffer:marker_set_back(MARK_FIND, MARK_FIND_COLOR) end -events.connect('view_new', +events.connect(events.VIEW_NEW, function() buffer:marker_set_back(MARK_FIND, MARK_FIND_COLOR) end) diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua index ddd237af..b4da1271 100644 --- a/modules/textadept/keys.lua +++ b/modules/textadept/keys.lua @@ -32,10 +32,10 @@ local function toggle_setting(setting, i) elseif type(state) == 'number' then buffer[setting] = buffer[setting] == 0 and (i or 1) or 0 end - events.emit('update_ui') -- for updating statusbar + events.emit(events.UPDATE_UI) -- for updating statusbar end local RECENT_FILES = _SCINTILLA.next_user_list_type() -events.connect('user_list_selection', +events.connect(events.USER_LIST_SELECTION, function(type, text) if type == RECENT_FILES then io.open_file(text) end end) local function show_recent_file_list() local buffer = buffer diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index 2051820e..9343efaa 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -10,26 +10,13 @@ local gui = _G.gui -- This module, like _m.textadept.keys, should be 'require'ed last. module('_m.textadept.menu', package.seeall) --- Markdown: --- ## Events --- --- The following is a list of all menu events generated in --- `event_name(arguments)` format: --- --- * **menu\_clicked** (menu\_id)<br /> --- Called when a menu item is selected. --- - menu\_id: the numeric ID of the menu item set in --- [`gui.gtkmenu()`][gui_gtkmenu]. --- --- [gui_gtkmenu]: ../modules/gui.html#gtkmenu - local _buffer, _view = buffer, view local m_textadept, m_editing = _m.textadept, _m.textadept.editing local SEPARATOR = { 'separator' } local function set_encoding(encoding) buffer:set_encoding(encoding) - events.emit('update_ui') -- for updating statusbar + events.emit(events.UPDATE_UI) -- for updating statusbar end local function toggle_setting(setting, i) local state = buffer[setting] @@ -38,21 +25,21 @@ local function toggle_setting(setting, i) elseif type(state) == 'number' then buffer[setting] = buffer[setting] == 0 and (i or 1) or 0 end - events.emit('update_ui') -- for updating statusbar + events.emit(events.UPDATE_UI) -- for updating statusbar end local function set_indentation(i) buffer.indent, buffer.tab_width = i, i - events.emit('update_ui') -- for updating statusbar + events.emit(events.UPDATE_UI) -- for updating statusbar end local function set_eol_mode(mode) buffer.eol_mode = mode buffer:convert_eo_ls(mode) - events.emit('update_ui') -- for updating statusbar + events.emit(events.UPDATE_UI) -- for updating statusbar end local function set_lexer(lexer) buffer:set_lexer(lexer) buffer:colourise(0, -1) - events.emit('update_ui') -- for updating statusbar + events.emit(events.UPDATE_UI) -- for updating statusbar end local function open_webpage(url) local cmd @@ -361,7 +348,7 @@ set_contextmenu(context_menu) -- Most of this handling code comes from keys.lua. local no_args = {} -events.connect('menu_clicked', function(menu_id) +events.connect(events.MENU_CLICKED, function(menu_id) local action, action_type if menu_id > 1000 then action = context_actions[menu_id - 1000] diff --git a/modules/textadept/mime_types.lua b/modules/textadept/mime_types.lua index 6d81455d..dcc7f404 100644 --- a/modules/textadept/mime_types.lua +++ b/modules/textadept/mime_types.lua @@ -22,16 +22,15 @@ module('_m.textadept.mime_types', package.seeall) -- -- [buffer_set_lexer_language]: buffer.html#buffer:set_lexer_language -- --- ## Events +-- ## Mime-type Events -- --- The following is a list of all mime-type events generated in --- `event_name(arguments)` format: --- --- * **language\_module\_loaded** (lang)<br /> --- Called when a language-specific module is loaded. This is useful for --- overriding its key commands since they are not available when Textadept --- starts. --- - lang: The language lexer name. +-- * `_G.events.LANGUAGE_MODULE_LOADED`: Called when loading a language-specific +-- module. This is useful for overriding its key commands since they are not +-- available when Textadept starts. Arguments:<br /> +-- * `lang`: The language lexer name. + +-- Events. +events.LANGUAGE_MODULE_LOADED = 'language_module_loaded' --- -- File extensions with their associated lexers. @@ -139,7 +138,7 @@ local function set_lexer(buffer, lang) if ret then ret, err = pcall(require, lang..'.post_init') _m[lang].set_buffer_properties() - events.emit('language_module_loaded', lang) + events.emit(events.LANGUAGE_MODULE_LOADED, lang) end local module_not_found = "^module '"..lang.."[^\']*' not found:" if not ret and not err:find(module_not_found) then error(err) end @@ -170,7 +169,7 @@ local function get_lexer(buffer, current) return get_style_name(buffer, style_at[i]):match('^(.+)_whitespace$') or lexer end -events.connect('buffer_new', function() +events.connect(events.BUFFER_NEW, function() buffer.set_lexer, buffer.get_lexer = set_lexer, get_lexer buffer.get_style_name = get_style_name end, 1) @@ -213,11 +212,11 @@ local function restore_lexer() end local connect = events.connect -connect('file_opened', handle_new) -connect('file_saved_as', handle_new) -connect('buffer_after_switch', restore_lexer) -connect('view_new', restore_lexer, 1) -connect('reset_after', +connect(events.FILE_OPENED, handle_new) +connect(events.FILE_SAVED_AS, handle_new) +connect(events.BUFFER_AFTER_SWITCH, restore_lexer) +connect(events.VIEW_NEW, restore_lexer, 1) +connect(events.RESET_AFTER, function() buffer:set_lexer(buffer._lexer or 'container') end) --- diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua index 65526386..684bf0ab 100644 --- a/modules/textadept/run.lua +++ b/modules/textadept/run.lua @@ -123,4 +123,4 @@ function goto_error(pos, line_num) end end end -events.connect('double_click', goto_error) +events.connect(events.DOUBLE_CLICK, goto_error) diff --git a/modules/textadept/session.lua b/modules/textadept/session.lua index fbda6ae9..a92ceb3e 100644 --- a/modules/textadept/session.lua +++ b/modules/textadept/session.lua @@ -49,7 +49,7 @@ function load(filename) else new_buffer() buffer._type = filename - events.emit('file_opened', filename) + events.emit(events.FILE_OPENED, filename) end -- Restore saved buffer selection and view. local anchor = tonumber(anchor) or 0 @@ -166,7 +166,7 @@ function save(filename) end end -events.connect('quit', function() if SAVE_ON_QUIT then save() end end, 1) +events.connect(events.QUIT, function() if SAVE_ON_QUIT then save() end end, 1) local function no_session() SAVE_ON_QUIT = false end args.register('-n', '--nosession', 0, no_session, 'No session functionality') diff --git a/modules/textadept/snippets.lua b/modules/textadept/snippets.lua index 0f4369b3..a3cfa313 100644 --- a/modules/textadept/snippets.lua +++ b/modules/textadept/snippets.lua @@ -419,7 +419,7 @@ _snippet_mt = { local INDIC_HIDDEN = _SCINTILLA.constants.INDIC_HIDDEN if buffer then buffer.indic_style[INDIC_SNIPPET] = INDIC_HIDDEN end -events.connect('view_new', +events.connect(events.VIEW_NEW, function() buffer.indic_style[INDIC_SNIPPET] = INDIC_HIDDEN end) --- |