aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/.command_entry.luadoc17
-rw-r--r--core/.find.luadoc17
-rw-r--r--core/args.lua9
-rw-r--r--core/events.lua254
-rw-r--r--core/file_io.lua53
-rw-r--r--core/gui.lua44
-rw-r--r--core/keys.lua18
-rw-r--r--core/locale.conf1
8 files changed, 193 insertions, 220 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.