aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2009-07-13 16:24:46 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2009-07-13 16:24:46 -0400
commitce026c2b52f0461b02b2af4d89fbcce3c8994848 (patch)
tree6ca969f180136b1dbd222bad252b3c97af529c4e
parent79db25baefd6994071ddc2efc7cb52cfb9c78af7 (diff)
downloadtextadept-ce026c2b52f0461b02b2af4d89fbcce3c8994848.tar.gz
textadept-ce026c2b52f0461b02b2af4d89fbcce3c8994848.zip
Consolidate core/ext/command_entry.lua.
-rw-r--r--core/ext/command_entry.lua58
1 files changed, 26 insertions, 32 deletions
diff --git a/core/ext/command_entry.lua b/core/ext/command_entry.lua
index 0170f21c..6d46c5c6 100644
--- a/core/ext/command_entry.lua
+++ b/core/ext/command_entry.lua
@@ -3,34 +3,6 @@
local textadept = _G.textadept
local locale = _G.locale
-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
- 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
- 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)
@@ -41,12 +13,34 @@ textadept.events.add_handler('command_entry_command',
textadept.events.add_handler('command_entry_keypress',
function(code)
local ce = textadept.command_entry
- if code == 65307 then -- escape
+ if code == 0xff1b 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)
+ elseif code == 0xff09 then -- tab
+ local substring = ce.entry_text: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
+ end
+ else
+ for p in pairs(textadept.buffer_properties) do
+ if p:find('^'..prefix) then cmpls[#cmpls + 1] = p end
+ end
+ end
+ end
+ table.sort(cmpls)
+ ce.show_completions(cmpls)
return true
end
end)