aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2014-10-05 21:41:57 -0400
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2014-10-05 21:41:57 -0400
commit5d12b299cd329f6a103c577040bb51a03a0f81ef (patch)
treeeb17d520c67a5c172c3230e34753c0598b169d67 /modules
parent1be7d50f3cee5aa4a06c083d195290e8fe8cacaf (diff)
Added editing keys for use with other modes; modules/textadept/command_entry.lua
Diffstat (limited to 'modules')
-rw-r--r--modules/textadept/command_entry.lua40
1 files changed, 27 insertions, 13 deletions
diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua
index 8dca8c6a..f6549a71 100644
--- a/modules/textadept/command_entry.lua
+++ b/modules/textadept/command_entry.lua
@@ -19,22 +19,43 @@ local M = ui.command_entry
-- local function complete_lua() ... end
-- local function execute_lua() ... end
-- keys['ce'] = {ui.command_entry.enter_mode, 'lua_command'}
--- keys.lua_command = {
+-- keys.lua_command = setmetatable({
-- ['\t'] = complete_lua,
-- ['\n'] = {ui.command_entry.finish_mode, execute_lua}
--- }
+-- }, ui.command_entry.editing_keys)
--
-- In this case, `Ctrl+E` opens the command entry and enters "lua_command" key
-- mode where the `Tab` and `Enter` keys have special, defined functionality.
-- (By default, Textadept pre-defines `Esc` to exit any command entry mode.)
-- `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.
+-- handles all other editing and movement keys normally.
-- @field height (number)
-- The height in pixels of the command entry.
module('ui.command_entry')]]
---
+-- A metatable with typical platform-specific key bindings for text entries.
+-- This metatable may be used to add basic editing keys to command entry modes.
+-- @usage setmetatable(keys.my_mode, ui.command_entry.editing_keys)
+-- @class table
+-- @name editing_keys
+M.editing_keys = {__index = {
+ [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 'cZ' or 'mZ'] = {buffer.redo, M}, cy = {buffer.redo, M},
+ -- Movement keys.
+ [(OSX or CURSES) and 'cf' or '\0'] = {buffer.char_right, M},
+ [(OSX or CURSES) and 'cb' or '\0'] = {buffer.char_left, M},
+ [(OSX or CURSES) and 'ca' or '\0'] = {buffer.vc_home, M},
+ [(OSX or CURSES) and 'ce' or '\0'] = {buffer.line_end, M},
+ [(OSX or CURSES) and 'cd' or '\0'] = {buffer.clear, M}
+}}
+
+---
-- Opens the command entry in key mode *mode*.
-- Key bindings will be looked up in `keys[mode]` instead of `keys`. The `Esc`
-- key exits the current mode, closes the command entry, and restores normal key
@@ -66,7 +87,7 @@ function M.finish_mode(f)
if f then f(M:get_text()) end
end
--- Environment for abbreviated commands.
+-- Environment for abbreviated Lua commands.
-- @class table
-- @name env
local env = setmetatable({}, {
@@ -140,16 +161,9 @@ local function complete_lua(code)
end
-- Define key mode for entering Lua commands.
-keys.lua_command = {
+keys.lua_command = setmetatable({
['\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},
-}
+}, M.editing_keys)
-- Configure the command entry's default properties.
events.connect(events.INITIALIZED, function()