From 1a95f6cad42e99e477e2b1532f6a234b4b586006 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Mon, 13 Oct 2014 21:58:35 -0400 Subject: Parameterize lexer and height for `ui.command_entry.enter_mode()`. Also enable more accurate Lua command completion. --- modules/textadept/command_entry.lua | 16 +++++++++++----- modules/textadept/keys.lua | 2 +- modules/textadept/menu.lua | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) (limited to 'modules/textadept') diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua index 54971686..6ad48981 100644 --- a/modules/textadept/command_entry.lua +++ b/modules/textadept/command_entry.lua @@ -58,16 +58,21 @@ M.editing_keys = {__index = { }} --- --- Opens the command entry in key mode *mode*. +-- Opens the command entry in key mode *mode*, highlighting text with lexer name +-- *lexer*, and displaying *height* number of lines at a time. -- 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 -- lookup. -- This function is useful for binding keys to enter a command entry mode. -- @param mode The key mode to enter into, or `nil` to exit the current mode. +-- @param lexer Optional string lexer name to use for command entry text. The +-- default value is `'text'`. +-- @param height Optional number of lines to display in the command entry. The +-- default value is `1`. -- @usage keys['ce'] = {ui.command_entry.enter_mode, 'command_entry'} -- @see _G.keys.MODE -- @name enter_mode -function M.enter_mode(mode) +function M.enter_mode(mode, lexer, height) if M:auto_c_active() then M:auto_c_cancel() end -- may happen in curses keys.MODE = mode if mode then @@ -77,7 +82,8 @@ function M.enter_mode(mode) end M:select_all() M.focus() - if not CURSES then M.height = M:text_height(0) end + M:set_lexer(lexer or 'text') + M.height = M:text_height(0) * (height or 1) end --- @@ -134,7 +140,8 @@ args.register('-e', '--execute', 1, run_lua, 'Execute Lua code') -- "abbreviated" environment where the `buffer`, `view`, and `ui` tables are -- also considered as globals. local function complete_lua() - local symbol, op, part = M:get_text():match('([%w_.]-)([%.:]?)([%w_]*)$') + local line, pos = M:get_cur_line() + local symbol, op, part = line:sub(1, pos):match('([%w_.]-)([%.:]?)([%w_]*)$') local ok, result = pcall((load('return ('..symbol..')', nil, 'bt', env))) local cmpls = {} part = '^'..part @@ -174,7 +181,6 @@ 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 - M:set_lexer('lua') end) --[[ The function below is a Lua C function. diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua index b5fbaa45..3e463026 100644 --- a/modules/textadept/keys.lua +++ b/modules/textadept/keys.lua @@ -467,7 +467,7 @@ keys[not OSX and 'cj' or 'mj'] = editing.goto_line -- Tools. keys[not OSX and (not CURSES and 'ce' or 'mc') - or 'me'] = {ui.command_entry.enter_mode, 'lua_command'} + or 'me'] = {ui.command_entry.enter_mode, 'lua_command', 'lua'} keys[not OSX and (not CURSES and 'cE' or 'mC') or 'mE'] = utils.select_command keys[not OSX and 'cr' or 'mr'] = textadept.run.run keys[not OSX and (not CURSES and 'cR' or 'cmr') or 'mR'] = textadept.run.compile diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index 0cbf4590..e427e072 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -103,7 +103,7 @@ local menubar = { {_L['_Jump to'], editing.goto_line}, }, { title = _L['_Tools'], - {_L['Command _Entry'], {ui.command_entry.enter_mode, 'lua_command'}}, + {_L['Command _Entry'], {ui.command_entry.enter_mode, 'lua_command', 'lua'}}, {_L['Select Co_mmand'], utils.select_command}, SEPARATOR, {_L['_Run'], textadept.run.run}, -- cgit v1.2.3