aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/.command_entry.lua7
-rw-r--r--core/.find.lua58
-rw-r--r--core/.pm.lua38
-rw-r--r--core/events.lua75
-rw-r--r--core/ext/command_entry.lua69
-rw-r--r--core/ext/find.lua58
-rw-r--r--core/ext/pm.lua53
-rw-r--r--core/ext/pm/modules_browser.lua6
8 files changed, 189 insertions, 175 deletions
diff --git a/core/.command_entry.lua b/core/.command_entry.lua
index 3d5e24fd..c1a06f45 100644
--- a/core/.command_entry.lua
+++ b/core/.command_entry.lua
@@ -16,10 +16,3 @@ command_entry = { entry_text = nil }
--- Focuses the command entry.
function focus() end
-
----
--- Gets completions for the current command_entry text.
--- This function is called internally and shouldn't be called by script.
--- @param command The command to complete.
--- @return sorted table of completions
-function get_completions_for(command) end
diff --git a/core/.find.lua b/core/.find.lua
index bea87c36..40829cb1 100644
--- a/core/.find.lua
+++ b/core/.find.lua
@@ -33,7 +33,7 @@ module('textadept.find')
---
-- Textadept's find table.
-- @class table
--- @name textadept.find
+-- @name find
-- @field find_entry_text The text in the find entry.
-- @field replace_entry_text The text in the replace entry.
-- @field match_case Flag indicating whether or not case-sensitive search is
@@ -53,68 +53,20 @@ find = {
function focus() end
---
--- [Local table] Text escape sequences with their associated characters.
--- @class table
--- @name escapes
-local escapes = {}
-
----
--- Finds and selects text in the current buffer.
--- This is used by the find dialog. It is recommended to use the
--- buffer:search_in_target() or buffer:search_next() and buffer:search_prev()
--- functions for scripting.
--- @param text The text to find.
--- @param next Flag indicating whether or not the search direction is forward.
--- @param flags Search flags. This is a number mask of 4 flags: match case (2),
--- whole word (4), Lua pattern (8), and in files (16) joined with binary OR.
--- If nil, this is determined based on the checkboxes in the find box.
--- @param nowrap Flag indicating whether or not the search won't wrap.
--- @param wrapped Utility flag indicating whether or not the search has wrapped
--- for displaying useful statusbar information. This flag is used and set
--- internally, and should not be set otherwise.
--- @return position of the found text or -1
-function find.find(text, next, flags, nowrap, wrapped) end
-
----
--- Replaces found text.
--- This function is used by the find dialog. It is not recommended to call it
--- via scripts.
--- textadept.find.find is called first, to select any found text. The selected
--- text is then replaced by the specified replacement text.
--- This function ignores 'Find in Files'.
--- @param rtext The text to replace found text with. It can contain both Lua
--- capture items (%n where 1 <= n <= 9) for Lua pattern searches and %()
--- sequences for embedding Lua code for any search.
--- @see find.find
-function find.replace(rtext) end
-
----
--- Replaces all found text.
--- This function is used by the find dialog. It is not recommended to call it
--- via scripts.
--- If any text is selected, all found text in that selection is replaced.
--- This function ignores 'Find in Files'.
--- @param ftext The text to find.
--- @param rtext The text to replace found text with.
--- @param flags The number mask identical to the one in 'find'.
--- @see find.find
-function find.replace_all(ftext, rtext, flags) end
-
----
-- Mimicks a press of the 'Find Next' button in the Find box.
-function find.call_find_next() end
+function find_next() end
---
-- Mimicks a press of the 'Find Prev' button in the Find box.
-function find.call_find_prev() end
+function find_prev() end
---
-- Mimicks a press of the 'Replace' button in the Find box.
-function find.call_replace() end
+function replace() end
---
-- Mimicks a press of the 'Replace All' button in the Find box.
-function find.call_replace_all() end
+function replace_all() end
---
-- Goes to the next or previous file found relative to the file
diff --git a/core/.pm.lua b/core/.pm.lua
index 3b1ffbd8..5371d286 100644
--- a/core/.pm.lua
+++ b/core/.pm.lua
@@ -61,12 +61,6 @@ module('textadept.pm')
-- current GtkTreePath).
pm = { entry_text = nil, width = nil, cursor = nil }
---- Focuses the project manager entry.
-function focus() end
-
---- Clears the project manager contents.
-function clear() end
-
--- Requests the project manager to get its contents based on its entry text.
function activate() end
@@ -75,3 +69,35 @@ function activate() end
-- manager entry combo box.
-- @param prefix The text to add.
function add_browser(prefix) end
+
+--- Clears the project manager contents.
+function clear() end
+
+---
+-- Adds contents to the Project Manager view.
+-- @param contents Table of tables to for display in the treeview (single
+-- level). Each key in the return table is the treeview item's ID. The table
+-- value has the following recognized fields:
+-- * parent - boolean value indicating if this entry can contain children.
+-- If true, an expanding arrow is displayed next to the entry.
+-- * pixbuf - a string representing a GTK stock-id whose icon is displayed
+-- next to an entry.
+-- * text - the entry's Pango marked-up display text.
+-- Note that only a SINGLE level of data needs to be returned. When parents
+-- are expanded, this function is called again to get that level of data.
+-- @param parent String representation of parent GtkTreePath to add the child
+-- contents to.
+function fill(contents, parent)
+
+--- Focuses the project manager entry.
+function focus() end
+
+---
+-- Shows a context menu.
+-- @param menu Table of menu items. It consists of an ordered list of strings
+-- to be used to construct a context menu. The strings are handled as follows:
+-- * 'gtk-*' - a stock menu item is created based on the GTK stock-id.
+-- * 'separator' - a menu separator item is created.
+-- * Otherwise a regular menu item with a mnemonic is created.
+-- @param event The GDK event associated with the context menu request.
+function show_context_menu(menu, event) end
diff --git a/core/events.lua b/core/events.lua
index 3d0cadee..28e446c9 100644
--- a/core/events.lua
+++ b/core/events.lua
@@ -71,7 +71,35 @@ module('textadept.events', package.seeall)
-- alt: flag indicating whether or not alt is pressed.
-- menu_clicked(menu_id)
-- menu_id: the numeric ID of the menu item.
--- pm_view_filled()
+-- pm_contents_request(full_path, expanding)
+-- full_path: a numerically indexed table of treeview item parents. The
+-- first index contains the text of pm_entry. Subsequent indexes contain
+-- the ID's of parents of the child requested for expanding (if any).
+-- expanding: indicates if the contents of a parent are being requested.
+-- pm_item_selected(selected_item, gdkevent)
+-- selected_item: identical to 'full_path' for 'pm_contents_request' event.
+-- gdkevent: the GDK event associated with the request. It must be passed to
+-- pm.show_context_menu()
+-- pm_context_menu_request(selected_item)
+-- selected_item: identical to 'full_path' for 'pm_contents_request' event.
+-- pm_menu_clicked(menu_id, selected_item)
+-- menu_id: the numeric ID for the menu item.
+-- selected_item: identical to 'full_path' for 'pm_contents_request' event.
+-- find(text, next)
+-- text: the text to find.
+-- next: flag indicating whether or not the search direction is forward.
+-- replace(text)
+-- text: the text to replace the current selection with. It can contain both
+-- Lua capture items (%n where 1 <= n <= 9) for Lua pattern searches and %()
+-- sequences for embedding Lua code for any search.
+-- replace_all(find_text, repl_text)
+-- find_text: the text to find.
+-- repl_text: the text to replace found text with.
+-- find_keypress(code)
+-- code: the key code.
+-- command_entry_completions_request()
+-- command_entry_keypress(code)
+-- code: the key code.
local events = textadept.events
@@ -163,41 +191,6 @@ function notification(n)
if f then f(n) end
end
--- Textadept events.
-function buffer_new()
- return handle('buffer_new')
-end
-function buffer_deleted()
- return handle('buffer_deleted')
-end
-function buffer_before_switch()
- return handle('buffer_before_switch')
-end
-function buffer_after_switch()
- return handle('buffer_after_switch')
-end
-function view_new()
- return handle('view_new')
-end
-function view_before_switch()
- return handle('view_before_switch')
-end
-function view_after_switch()
- return handle('view_after_switch')
-end
-function quit()
- return handle('quit')
-end
-function keypress(code, shift, control, alt)
- return handle('keypress', code, shift, control, alt)
-end
-function menu_clicked(menu_id_str)
- return handle('menu_clicked', tonumber(menu_id_str))
-end
-function pm_view_filled()
- return handle('pm_view_filled')
-end
-
-- Default handlers to follow.
add_handler('view_new',
@@ -478,11 +471,9 @@ add_handler('quit',
end)
if MAC then
- function appleevent_odoc(uri) return handle('uri_dropped', 'file://'..uri) end
+ add_handler('appleevent_odoc',
+ function(uri) return handle('uri_dropped', 'file://'..uri) end)
end
----
--- Default error handler.
--- Prints the errors to an error buffer.
--- @param ... Error strings.
-function error(...) textadept._print(locale.ERROR_BUFFER, ...) end
+add_handler('error',
+ function(...) textadept._print(locale.ERROR_BUFFER, ...) end)
diff --git a/core/ext/command_entry.lua b/core/ext/command_entry.lua
index d2a64243..0170f21c 100644
--- a/core/ext/command_entry.lua
+++ b/core/ext/command_entry.lua
@@ -2,32 +2,51 @@
local textadept = _G.textadept
local locale = _G.locale
-local ce = textadept.command_entry
--- LuaDoc is in core/.command_entry.lua
-function ce.get_completions_for(command)
- local substring = command:match('[%w_.:]+$') or ''
- local path, o, prefix = substring:match('^([%w_.:]-)([.:]?)([%w_]*)$')
- local ret, tbl = pcall(loadstring('return ('..path..')'))
- if not ret then tbl = getfenv(0) end
- if type(tbl) ~= 'table' then return end
- local cmpls = {}
- for k in pairs(tbl) do
- if type(k) == 'string' and k:find('^'..prefix) then
- cmpls[#cmpls + 1] = k
- end
- end
- if path == 'buffer' then
- if o == ':' then
- for f in pairs(textadept.buffer_functions) do
- if f:find('^'..prefix) then cmpls[#cmpls + 1] = f end
+textadept.events.add_handler('command_entry_completions_request',
+ function(command) -- get a Lua completion list for the command being entered
+ local substring = command:match('[%w_.:]+$') or ''
+ local path, o, prefix = substring:match('^([%w_.:]-)([.:]?)([%w_]*)$')
+ local ret, tbl = pcall(loadstring('return ('..path..')'))
+ if not ret then tbl = getfenv(0) end
+ if type(tbl) ~= 'table' then return end
+ local cmpls = {}
+ for k in pairs(tbl) do
+ if type(k) == 'string' and k:find('^'..prefix) then
+ cmpls[#cmpls + 1] = k
end
- else
- for p in pairs(textadept.buffer_properties) do
- if p:find('^'..prefix) then cmpls[#cmpls + 1] = p end
+ end
+ if path == 'buffer' then
+ if o == ':' then
+ for f in pairs(textadept.buffer_functions) do
+ if f:find('^'..prefix) then cmpls[#cmpls + 1] = f end
+ end
+ else
+ for p in pairs(textadept.buffer_properties) do
+ if p:find('^'..prefix) then cmpls[#cmpls + 1] = p end
+ end
end
end
- end
- table.sort(cmpls)
- return cmpls
-end
+ table.sort(cmpls)
+ textadept.command_entry.show_completions(cmpls)
+ end)
+
+textadept.events.add_handler('command_entry_command',
+ function(command) -- execute a Lua command
+ local f, err = loadstring(command)
+ if err then error(err) end
+ f()
+ end)
+
+textadept.events.add_handler('command_entry_keypress',
+ function(code)
+ local ce = textadept.command_entry
+ if code == 65307 then -- escape
+ ce.focus() -- toggle focus to hide
+ return true
+ elseif code == 65289 then -- tab
+ textadept.events.handle('command_entry_completions_request',
+ ce.entry_text)
+ return true
+ end
+ end)
diff --git a/core/ext/find.lua b/core/ext/find.lua
index b4f4efee..c97cefd3 100644
--- a/core/ext/find.lua
+++ b/core/ext/find.lua
@@ -10,14 +10,28 @@ local MARK_FIND = 0
local MARK_FIND_COLOR = 0x4D9999
local previous_view
--- LuaDoc is in core/.find.lua.
+---
+-- [Local table] Text escape sequences with their associated characters.
+-- @class table
+-- @name escapes
local escapes = {
['\\a'] = '\a', ['\\b'] = '\b', ['\\f'] = '\f', ['\\n'] = '\n',
['\\r'] = '\r', ['\\t'] = '\t', ['\\v'] = '\v', ['\\\\'] = '\\'
}
--- LuaDoc is in core/.find.lua.
-function find.find(text, next, flags, nowrap, wrapped)
+---
+-- [Local function] Finds and selects text in the current buffer.
+-- @param text The text to find.
+-- @param next Flag indicating whether or not the search direction is forward.
+-- @param flags Search flags. This is a number mask of 4 flags: match case (2),
+-- whole word (4), Lua pattern (8), and in files (16) joined with binary OR.
+-- If nil, this is determined based on the checkboxes in the find box.
+-- @param nowrap Flag indicating whether or not the search won't wrap.
+-- @param wrapped Utility flag indicating whether or not the search has wrapped
+-- for displaying useful statusbar information. This flag is used and set
+-- internally, and should not be set otherwise.
+-- @return position of the found text or -1
+local function find_(text, next, flags, nowrap, wrapped)
if #text == 0 then return end
local buffer = buffer
local first_visible_line = buffer.first_visible_line -- for 'no results found'
@@ -128,7 +142,7 @@ function find.find(text, next, flags, nowrap, wrapped)
buffer:goto_pos(buffer.length)
end
textadept.statusbar_text = locale.FIND_SEARCH_WRAPPED
- result = find.find(text, next, flags, true, true)
+ result = find_(text, next, flags, true, true)
if result == -1 then
textadept.statusbar_text = locale.FIND_NO_RESULTS
buffer:line_scroll(0, first_visible_line)
@@ -141,9 +155,18 @@ function find.find(text, next, flags, nowrap, wrapped)
return result
end
+textadept.events.add_handler('find', find_)
--- LuaDoc is in core/.find.lua.
-function find.replace(rtext)
+---
+-- [Local function] Replaces found text.
+-- 'find_' is called first, to select any found text. The selected text is then
+-- replaced by the specified replacement text.
+-- This function ignores 'Find in Files'.
+-- @param rtext The text to replace found text with. It can contain both Lua
+-- capture items (%n where 1 <= n <= 9) for Lua pattern searches and %()
+-- sequences for embedding Lua code for any search.
+-- @see find
+local function replace(rtext)
if #buffer:get_sel_text() == 0 then return end
if find.in_files then find.in_files = false end
local buffer = buffer
@@ -179,9 +202,17 @@ function find.replace(rtext)
buffer:goto_pos(buffer.current_pos)
end
end
+textadept.events.add_handler('replace', replace)
--- LuaDoc is in core/.find.lua.
-function find.replace_all(ftext, rtext, flags)
+---
+-- [Local function] Replaces all found text.
+-- If any text is selected, all found text in that selection is replaced.
+-- This function ignores 'Find in Files'.
+-- @param ftext The text to find.
+-- @param rtext The text to replace found text with.
+-- @param flags The number mask identical to the one in 'find'.
+-- @see find
+local function replace_all(ftext, rtext, flags)
if #ftext == 0 then return end
if find.in_files then find.in_files = false end
local buffer = buffer
@@ -189,8 +220,8 @@ function find.replace_all(ftext, rtext, flags)
local count = 0
if #buffer:get_sel_text() == 0 then
buffer:goto_pos(0)
- while(find.find(ftext, true, flags, true) ~= -1) do
- find.replace(rtext)
+ while(find_(ftext, true, flags, true) ~= -1) do
+ replace(rtext)
count = count + 1
end
else
@@ -201,13 +232,13 @@ function find.replace_all(ftext, rtext, flags)
local end_marker =
buffer:marker_add(buffer:line_from_position(e + 1), MARK_FIND)
buffer:goto_pos(s)
- local pos = find.find(ftext, true, flags, true)
+ local pos = find_(ftext, true, flags, true)
while pos ~= -1 and
pos < buffer:position_from_line(
buffer:marker_line_from_handle(end_marker)) do
- find.replace(rtext)
+ replace(rtext)
count = count + 1
- pos = find.find(ftext, true, flags, true)
+ pos = find_(ftext, true, flags, true)
end
e = buffer:position_from_line(buffer:marker_line_from_handle(end_marker))
buffer:goto_pos(e)
@@ -220,6 +251,7 @@ function find.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)
---
-- [Local function] When the user double-clicks a found file, go to the line in
diff --git a/core/ext/pm.lua b/core/ext/pm.lua
index 67cbbbfb..8838582c 100644
--- a/core/ext/pm.lua
+++ b/core/ext/pm.lua
@@ -8,37 +8,36 @@ local current_browser = nil
local last_browser_text = nil
local browser_cursors = {}
--- LuaDoc is in core/.browser.lua.
-function pm.get_contents_for(full_path, expanding)
- for _, browser in pairs(pm.browsers) do
- if browser.matches(full_path[1]) then
- current_browser = browser
- if last_browser_text and last_browser_text ~= pm.entry_text then
- -- Switching browsers, save the current one's cursor.
- -- Don't reset last_browser_text here though, we still need to detect
- -- the switch when the 'pm_view_filled' event is called so as to restore
- -- the cursor to the new browser.
- browser_cursors[last_browser_text] = pm.cursor
+textadept.events.add_handler('pm_contents_request',
+ function(full_path, expanding)
+ for _, browser in pairs(pm.browsers) do
+ if browser.matches(full_path[1]) then
+ current_browser = browser
+ if last_browser_text and last_browser_text ~= pm.entry_text then
+ -- Switching browsers, save the current one's cursor.
+ -- Don't reset last_browser_text here though, we still need to detect
+ -- the switch when the 'pm_view_filled' event is called so as to restore
+ -- the cursor to the new browser.
+ browser_cursors[last_browser_text] = pm.cursor
+ end
+ pm.fill(browser.get_contents_for(full_path, expanding), expanding)
+ textadept.events.handle('pm_view_filled')
end
- return browser.get_contents_for(full_path, expanding)
end
- end
-end
+ end)
--- LuaDoc is in core/.browser.lua.
-function pm.perform_action(selected_item)
- current_browser.perform_action(selected_item)
-end
+textadept.events.add_handler('pm_item_selected',
+ function(selected_item) current_browser.perform_action(selected_item) end)
--- LuaDoc is in core/.browser.lua.
-function pm.get_context_menu(selected_item)
- return current_browser.get_context_menu(selected_item)
-end
+textadept.events.add_handler('pm_context_menu_request',
+ function(selected_item, event)
+ pm.show_context_menu(current_browser.get_context_menu(selected_item), event)
+ end)
--- LuaDoc is in core/.browser.lua.
-function pm.perform_menu_action(menu_id, selected_item)
- current_browser.perform_menu_action(menu_id, selected_item)
-end
+textadept.events.add_handler('pm_menu_clicked',
+ function(menu_id, selected_item)
+ current_browser.perform_menu_action(menu_id, selected_item)
+ end)
-- LuaDoc is in core/.browser.lua.
function pm.toggle_visible()
@@ -51,7 +50,7 @@ function pm.toggle_visible()
end
textadept.events.add_handler('pm_view_filled',
- function() -- tries to restore the cursor for a previous browser
+ function() -- try to restore previous browser cursor
if last_browser_text ~= pm.entry_text then
last_browser_text = pm.entry_text
local previous_cursor = browser_cursors[pm.entry_text]
diff --git a/core/ext/pm/modules_browser.lua b/core/ext/pm/modules_browser.lua
index 4cbe715c..8472ee0d 100644
--- a/core/ext/pm/modules_browser.lua
+++ b/core/ext/pm/modules_browser.lua
@@ -84,8 +84,10 @@ function matches(entry_text)
end
local function modify_path(path)
- path[1] = textadept.iconv(_HOME..'/modules', 'UTF-8', _CHARSET)
- return path
+ local new_path = {}
+ for _, v in ipairs(path) do new_path[#new_path + 1] = v end
+ new_path[1] = textadept.iconv(_HOME..'/modules', 'UTF-8', _CHARSET)
+ return new_path
end
function get_contents_for(full_path)