diff options
author | 2009-07-08 19:14:33 -0400 | |
---|---|---|
committer | 2009-07-08 19:14:33 -0400 | |
commit | 9827462bc8ac4ecc6009f2285c2397bf6ff64777 (patch) | |
tree | cc2d9b16d23a904d1107b111bf19f39ced993db1 /core/ext/command_entry.lua | |
parent | bfef6fc70792fe002df7f8c0bfc82749fcd08152 (diff) | |
download | textadept-9827462bc8ac4ecc6009f2285c2397bf6ff64777.tar.gz textadept-9827462bc8ac4ecc6009f2285c2397bf6ff64777.zip |
Extended the event system to include project manager, find, command entry, etc.
Diffstat (limited to 'core/ext/command_entry.lua')
-rw-r--r-- | core/ext/command_entry.lua | 69 |
1 files changed, 44 insertions, 25 deletions
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) |