aboutsummaryrefslogtreecommitdiff
path: root/modules/textadept
diff options
context:
space:
mode:
Diffstat (limited to 'modules/textadept')
-rw-r--r--modules/textadept/adeptsense.lua10
-rw-r--r--modules/textadept/bookmarks.lua2
-rw-r--r--modules/textadept/command_entry.lua7
-rw-r--r--modules/textadept/editing.lua14
-rw-r--r--modules/textadept/filter_through.lua5
-rw-r--r--modules/textadept/find.lua14
-rw-r--r--modules/textadept/keys.lua4
-rw-r--r--modules/textadept/menu.lua25
-rw-r--r--modules/textadept/mime_types.lua31
-rw-r--r--modules/textadept/run.lua2
-rw-r--r--modules/textadept/session.lua4
-rw-r--r--modules/textadept/snippets.lua2
12 files changed, 55 insertions, 65 deletions
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)
---