aboutsummaryrefslogtreecommitdiff
path: root/core/ext
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2008-06-17 16:43:09 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2008-06-17 16:43:09 -0400
commit102c01ba2db51190c7c79592a6ea2fdb29d4d4fa (patch)
tree781576920293b05c7585e410f8dc9d3f2e48a44f /core/ext
parente47fe640c0cd6826fa2b46d3b3fad7268766a093 (diff)
downloadtextadept-102c01ba2db51190c7c79592a6ea2fdb29d4d4fa.tar.gz
textadept-102c01ba2db51190c7c79592a6ea2fdb29d4d4fa.zip
Added Tab-completion to Lua Command Entry.
Diffstat (limited to 'core/ext')
-rw-r--r--core/ext/command_entry.lua36
-rw-r--r--core/ext/key_commands.lua2
2 files changed, 37 insertions, 1 deletions
diff --git a/core/ext/command_entry.lua b/core/ext/command_entry.lua
new file mode 100644
index 00000000..8c796610
--- /dev/null
+++ b/core/ext/command_entry.lua
@@ -0,0 +1,36 @@
+-- Copyright 2007-2008 Mitchell mitchell<att>caladbolg.net. See LICENSE.
+
+local ce = textadept.command_entry
+
+---
+-- 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 ce.get_completions_for(command)
+ local textadept = textadept
+ 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:match('^'..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:match('^'..prefix) then cmpls[#cmpls + 1] = f end
+ end
+ else
+ for p in pairs(textadept.buffer_properties) do
+ if p:match('^'..prefix) then cmpls[#cmpls + 1] = p end
+ end
+ end
+ end
+ table.sort(cmpls)
+ return cmpls
+end
diff --git a/core/ext/key_commands.lua b/core/ext/key_commands.lua
index ca22ff37..83d88f47 100644
--- a/core/ext/key_commands.lua
+++ b/core/ext/key_commands.lua
@@ -207,7 +207,7 @@ keys.ct.v.t = { toggle_setting, 'use_tabs' }
keys.ct.v.w = { toggle_setting, 'view_ws' }
-- Miscellaneous commands.
-keys.cc = { t.focus_command }
+keys.cc = { t.command_entry.focus }
local m_events = t.events
keys.cab = { m_events.handle, 'call_tip_click', 1 }
keys.caf = { m_events.handle, 'call_tip_click', 2 }