aboutsummaryrefslogtreecommitdiff
path: root/core
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
parente47fe640c0cd6826fa2b46d3b3fad7268766a093 (diff)
downloadtextadept-102c01ba2db51190c7c79592a6ea2fdb29d4d4fa.tar.gz
textadept-102c01ba2db51190c7c79592a6ea2fdb29d4d4fa.zip
Added Tab-completion to Lua Command Entry.
Diffstat (limited to 'core')
-rw-r--r--core/.command_entry.lua25
-rw-r--r--core/.textadept.lua4
-rw-r--r--core/events.lua68
-rw-r--r--core/ext/command_entry.lua36
-rw-r--r--core/ext/key_commands.lua2
5 files changed, 62 insertions, 73 deletions
diff --git a/core/.command_entry.lua b/core/.command_entry.lua
new file mode 100644
index 00000000..6de23763
--- /dev/null
+++ b/core/.command_entry.lua
@@ -0,0 +1,25 @@
+-- Copyright 2007 Mitchell mitchell<att>caladbolg.net. See LICENSE.
+-- This is a DUMMY FILE used for making LuaDoc for built-in functions in the
+-- global textadept.command_entry table.
+
+---
+-- Textadept's Lua command entry.
+-- [Dummy file]
+module('textadept.command_entry')
+
+---
+-- Textadept's Lua command entry table.
+-- @class table
+-- @name textadept.command_entry
+-- @field entry_text The text in the entry.
+command_entry = {}
+
+--- 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/.textadept.lua b/core/.textadept.lua
index 011c70aa..d58aed97 100644
--- a/core/.textadept.lua
+++ b/core/.textadept.lua
@@ -57,10 +57,6 @@ function goto_view(n, absolute) end
function get_split_table() end
---
--- Focuses the command entry.
-function focus_command() end
-
----
-- Creates a GTK menu, returning the userdata.
-- @param menu_table A table defining the menu. It is an ordered list of strings
-- that are handled as follows:
diff --git a/core/events.lua b/core/events.lua
index fffa5aca..7a1ed360 100644
--- a/core/events.lua
+++ b/core/events.lua
@@ -383,74 +383,6 @@ add_handler('quit',
return true
end)
-
----
--- Shows completions for the current command_entry text.
--- Opens a new buffer (if one hasn't already been opened) for printing possible
--- completions.
--- @param command The command to complete.
-function show_completions(command)
- local textadept = textadept
- local cmpl_buffer, goto
- if buffer.shows_completions then
- cmpl_buffer = buffer
- else
- for index, buffer in ipairs(textadept.buffers) do
- if buffer.shows_completions then
- cmpl_buffer = index
- goto = buffer.doc_pointer ~= textadept.focused_doc_pointer
- elseif buffer.doc_pointer == textadept.focused_doc_pointer then
- textadept.prev_buffer = index
- end
- end
- if not cmpl_buffer then
- cmpl_buffer = textadept.new_buffer()
- cmpl_buffer.shows_completions = true
- else
- if goto then view:goto(cmpl_buffer) end
- cmpl_buffer = textadept.buffers[cmpl_buffer]
- end
- end
- cmpl_buffer:clear_all()
-
- 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)
- for _, cmpl in ipairs(cmpls) do cmpl_buffer:add_text(cmpl..'\n') end
- cmpl_buffer:set_save_point()
-end
-
----
--- Hides the completion buffer if it is currently focused and restores the
--- previous focused buffer (if possible).
-function hide_completions()
- local textadept = textadept
- if buffer.shows_completions then
- buffer:close()
- if textadept.prev_buffer then view:goto_buffer(textadept.prev_buffer) end
- end
-end
-
---
-- Default error handler.
-- Opens a new buffer (if one hasn't already been opened) for printing errors.
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 }