aboutsummaryrefslogtreecommitdiff
path: root/modules/textadept/command_entry.lua
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2011-01-21 00:41:36 -0500
committermitchell <70453897+667e-11@users.noreply.github.com>2011-01-21 00:41:36 -0500
commit78bcda2db6b0b8669a6fbcf63b1143602f544416 (patch)
treedf837e91e357573ca84be0b20155189252337cec /modules/textadept/command_entry.lua
parent2247eeb38c71da492cb96711e133b353e7c3129d (diff)
downloadtextadept-78bcda2db6b0b8669a6fbcf63b1143602f544416.tar.gz
textadept-78bcda2db6b0b8669a6fbcf63b1143602f544416.zip
Code cleanup.
Diffstat (limited to 'modules/textadept/command_entry.lua')
-rw-r--r--modules/textadept/command_entry.lua105
1 files changed, 51 insertions, 54 deletions
diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua
index c2a20d92..eac4c99e 100644
--- a/modules/textadept/command_entry.lua
+++ b/modules/textadept/command_entry.lua
@@ -27,66 +27,63 @@ local env = setmetatable({}, {
end,
})
-events.connect('command_entry_command',
- function(command) -- execute a Lua 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')
- end)
+-- Execute a Lua command.
+events.connect('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')
+end)
-events.connect('command_entry_keypress',
- function(code)
- local ce = gui.command_entry
- local KEYSYMS = keys.KEYSYMS
- if KEYSYMS[code] == 'esc' then
- ce.focus() -- toggle focus to hide
- return true
- elseif KEYSYMS[code] == '\t' then
- local substring = ce.entry_text:match('[%w_.:]+$') or ''
- local path, o, prefix = substring:match('^([%w_.:]-)([.:]?)([%w_]*)$')
- local f, err = loadstring('return ('..path..')')
- if type(f) == "function" then setfenv(f, env) end
- local ok, tbl = pcall(f)
- local cmpls = {}
- prefix = '^'..prefix
- if not ok then -- shorthand notation
- for _, t in ipairs{ buffer, view, gui, _G } do
- for k in pairs(t) do
- if type(k) == 'string' and k:find(prefix) then
- cmpls[#cmpls + 1] = k
- end
- end
- end
- for f in pairs(_SCINTILLA.functions) do
- if f:find(prefix) then cmpls[#cmpls + 1] = f end
- end
- for p in pairs(_SCINTILLA.properties) do
- if p:find(prefix) then cmpls[#cmpls + 1] = p end
- end
- else
- if type(tbl) ~= 'table' then return end
- for k in pairs(tbl) do
+events.connect('command_entry_keypress', function(code)
+ local ce = gui.command_entry
+ local KEYSYMS = keys.KEYSYMS
+ if KEYSYMS[code] == 'esc' then
+ ce.focus() -- toggle focus to hide
+ return true
+ elseif KEYSYMS[code] == '\t' then
+ local substring = ce.entry_text:match('[%w_.:]+$') or ''
+ local path, o, prefix = substring:match('^([%w_.:]-)([.:]?)([%w_]*)$')
+ local f, err = loadstring('return ('..path..')')
+ if type(f) == "function" then setfenv(f, env) end
+ local ok, tbl = pcall(f)
+ local cmpls = {}
+ prefix = '^'..prefix
+ if not ok then -- shorthand notation
+ for _, t in ipairs{ buffer, view, gui, _G } do
+ for k in pairs(t) 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(_SCINTILLA.functions) do
- if f:find(prefix) then cmpls[#cmpls + 1] = f end
- end
- else
- for p in pairs(_SCINTILLA.properties) do
- if p:find(prefix) then cmpls[#cmpls + 1] = p end
- end
+ end
+ for f in pairs(_SCINTILLA.functions) do
+ if f:find(prefix) then cmpls[#cmpls + 1] = f end
+ end
+ for p in pairs(_SCINTILLA.properties) do
+ if p:find(prefix) then cmpls[#cmpls + 1] = p end
+ end
+ else
+ if type(tbl) ~= 'table' then return end
+ 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(_SCINTILLA.functions) do
+ if f:find(prefix) then cmpls[#cmpls + 1] = f end
+ end
+ else
+ for p in pairs(_SCINTILLA.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)
+ table.sort(cmpls)
+ ce.show_completions(cmpls)
+ return true
+ end
+end)