aboutsummaryrefslogtreecommitdiff
path: root/modules/textadept/command_entry.lua
diff options
context:
space:
mode:
Diffstat (limited to 'modules/textadept/command_entry.lua')
-rw-r--r--modules/textadept/command_entry.lua52
1 files changed, 24 insertions, 28 deletions
diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua
index b75405ca..8dca8c6a 100644
--- a/modules/textadept/command_entry.lua
+++ b/modules/textadept/command_entry.lua
@@ -30,8 +30,8 @@ local M = ui.command_entry
-- `Tab` shows a list of Lua completions for the entry text and `Enter` exits
-- "lua_command" key mode and executes the entered code. The command entry
-- handles all other keys normally.
--- @field entry_text (string)
--- The text in the command entry.
+-- @field height (number)
+-- The height in pixels of the command entry.
module('ui.command_entry')]]
---
@@ -47,9 +47,7 @@ module('ui.command_entry')]]
function M.enter_mode(mode)
keys.MODE = mode
if mode and not keys[mode]['esc'] then keys[mode]['esc'] = M.enter_mode end
- -- In curses, M.focus() does not return immediately, so the key sequence that
- -- called M.focus() is still on the keychain. Clear it.
- if CURSES then keys.clear_key_sequence() end
+ M:select_all()
M.focus()
end
@@ -63,9 +61,9 @@ end
-- @usage keys['\n'] = {ui.command_entry.finish_mode, ui.print}
-- @name finish_mode
function M.finish_mode(f)
+ if M:auto_c_active() then return false end -- allow Enter to autocomplete
M.enter_mode(nil)
- if f then f(M.entry_text) end
- if CURSES then return false end -- propagate to exit CDK entry on Enter
+ if f then f(M:get_text()) end
end
-- Environment for abbreviated commands.
@@ -103,13 +101,12 @@ local function execute_lua(code)
end
args.register('-e', '--execute', 1, execute_lua, 'Execute Lua code')
--- Shows a set of Lua code completions for string *code* or `entry_text`.
+-- Shows a set of Lua code completions for string *code* or the entry's text.
-- Completions are subject to an "abbreviated" environment where the `buffer`,
-- `view`, and `ui` tables are also considered as globals.
--- @param code The Lua code to complete. The default value is the value of
--- `entry_text`.
+-- @param code The Lua code to complete. The default value is the entry's text.
local function complete_lua(code)
- if not code then code = M.entry_text end
+ if not code then code = M:get_text() end
local symbol, op, part = code:match('([%w_.]-)([%.:]?)([%w_]*)$')
local ok, result = pcall((load('return ('..symbol..')', nil, 'bt', env)))
local cmpls = {}
@@ -139,19 +136,28 @@ local function complete_lua(code)
end
end
table.sort(cmpls)
- M.show_completions(cmpls)
+ M:auto_c_show(#part - 1, table.concat(cmpls, ' '))
end
-- Define key mode for entering Lua commands.
keys.lua_command = {
- ['\t'] = complete_lua, ['\n'] = {M.finish_mode, execute_lua}
+ ['\t'] = complete_lua, ['\n'] = {M.finish_mode, execute_lua},
+ [not OSX and 'cx' or 'mx'] = {buffer.cut, M},
+ [not OSX and 'cc' or 'mc'] = {buffer.copy, M},
+ [not OSX and 'cv' or 'mv'] = {buffer.paste, M},
+ [not OSX and not CURSES and 'ca' or 'ma'] = {buffer.select_all, M},
+ [not OSX and 'cz' or 'mz'] = {buffer.undo, M},
+ [not OSX and 'cy' or 'mZ'] = {buffer.redo, M},
+ [not OSX and 'cZ' or 'mZ'] = {buffer.redo, M},
}
--- Pass command entry keys to the default keypress handler.
--- Since the command entry is designed to be modal, command entry key bindings
--- should stay separate from editor key bindings.
-events.connect(events.COMMAND_ENTRY_KEYPRESS, function(...)
- if keys.MODE then return events.emit(events.KEYPRESS, ...) end
+-- Configure the command entry's default properties.
+events.connect(events.INITIALIZED, function()
+ if not arg then return end -- no need to reconfigure on reset
+ M.h_scroll_bar, M.v_scroll_bar = false, false
+ M.margin_width_n[0], M.margin_width_n[1], M.margin_width_n[2] = 0, 0, 0
+ if not CURSES then M.height = M:text_height(1) end
+ M:set_lexer('lua')
end)
--[[ The function below is a Lua C function.
@@ -161,14 +167,4 @@ end)
-- @class function
-- @name focus
local focus
-
----
--- Shows completion list *completions* for the current word prefix.
--- Word prefix characters are alphanumerics and underscores. On selection, the
--- word prefix is replaced with the completion.
--- @param completions The table of completions to show. Non-string values are
--- ignored.
--- @class function
--- @name show_completions
-local show_completions
]]