diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/lua/api | 11 | ||||
-rw-r--r-- | modules/lua/tags | 5 | ||||
-rw-r--r-- | modules/textadept/command_entry.lua | 167 | ||||
-rw-r--r-- | modules/textadept/find.lua | 23 | ||||
-rw-r--r-- | modules/textadept/keys.lua | 50 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 6 |
6 files changed, 129 insertions, 133 deletions
diff --git a/modules/lua/api b/modules/lua/api index 6c27b0f9..128b2d31 100644 --- a/modules/lua/api +++ b/modules/lua/api @@ -138,7 +138,7 @@ KEYPRESS events.KEYPRESS (string)\nEmitted when pressing a key.\nIf any handler KEYSYMS keys.KEYSYMS (table)\nLookup table for string representations of key codes higher than 255.\nKey codes can be identified by temporarily uncommenting the `print()`\nstatements in *core/keys.lua*. KEYWORD lexer.KEYWORD (string)\nThe token name for keyword tokens. LABEL lexer.LABEL (string)\nThe token name for label tokens. -LEXER_LOADED events.LEXER_LOADED (string)\nEmitted after loading a language lexer.\nThis is useful for overriding a language module's key bindings or other\nproperties since the module is not loaded when Textadept starts.\nArguments:\n\n* *`lexer`*: The language lexer's name. +LEXER_LOADED events.LEXER_LOADED (string)\nEmitted after loading a language lexer.\nThis is useful for overriding a language module's key bindings or other\nproperties since the module is not loaded when Textadept starts.\nArguments:\n\n* _`lexer`_: The language lexer's name. LINUX _G.LINUX (bool)\nWhether or not Textadept is running on Linux. MARGINOPTION_NONE buffer.MARGINOPTION_NONE (number, Read-only)\n MARGINOPTION_SUBLINESELECT buffer.MARGINOPTION_SUBLINESELECT (number, Read-only)\n @@ -482,7 +482,7 @@ collectgarbage _G.collectgarbage([opt [, arg]])\nThis function is a generic inte colorselect ui.dialogs.colorselect(options)\nPrompts the user with a color selection dialog defined by dialog options\ntable *options*, returning the color selected.\nIf the user canceled the dialog, returns `nil`.\n@param options Table of key-value option pairs for the option select dialog.\n\n * `title`: The dialog's title text.\n * `color`: The initially selected color as either a number in "0xBBGGRR"\n format, or as a string in "#RRGGBB" format.\n * `palette`: The list of colors to show in the dialog's color palette.\n Up to 20 colors can be specified as either numbers in "0xBBGGRR" format\n or as strings in "#RRGGBB" format. If `true` (no list was given), a\n default palette is shown.\n * `string_output`: Return the selected color in string "#RRGGBB" format\n instead of numeric "0xBBGGRR" format. The default value is `false`.\n * `float`: Show the dialog on top of all desktop windows. The default value\n is `false`.\n@usage ui.dialogs.colorselect{title = 'Foreground color', color = 0x000000,\n palette = {'#000000', 0x0000FF, '#00FF00', 0xFF0000}}\n@return selected color colourise buffer.colourise(buffer, start_pos, end_pos)\nInstructs the lexer to style and mark fold points in the range of text\nbetween *start_pos* and *end_pos*.\nIf *end_pos* is `-1`, styles and marks to the end of the buffer.\n@param buffer A buffer.\n@param start_pos The start position of the range of text in *buffer* to\n process.\n@param end_pos The end position of the range of text in *buffer* to process,\n or `-1` to process from *start_pos* to the end of *buffer*. column buffer.column (table, Read-only)\nTable of column numbers (taking tab widths into account) for positions\nstarting from zero.\nMulti-byte characters count as single characters. -command_entry ui.command_entry (module)\nTextadept's Command Entry. +command_entry ui.command_entry (module)\nTextadept's Command Entry.\nIt supports multiple modes that each have their own functionality, such as\nrunning Lua code, searching for text incrementally, and filtering text\nthrough shell commands. comment_string textadept.editing.comment_string (table)\nMap of lexer names to line comment strings for programming languages, used by\nthe `block_comment()` function.\nKeys are lexer names and values are either the language's line comment\nprefixes or block comment delimiters separated by a '|' character.\n@see block_comment compile textadept.run.compile(filename)\nCompiles file *filename* or the current file using an appropriate shell\ncommand from the `compile_commands` table.\nThe shell command is determined from the file's filename, extension, or\nlanguage in that order.\nEmits `COMPILE_OUTPUT` events.\n@param filename Optional path to the file to compile. The default value is\n the current file's filename.\n@see compile_commands\n@see _G.events compile_commands textadept.run.compile_commands (table)\nMap of filenames, file extensions, and lexer names to their associated\n"compile" shell command line strings or functions that return such strings.\nCommand line strings may have the following macros:\n\n + `%f`: The file's name, including its extension.\n + `%e`: The file's name, excluding its extension.\n + `%d`: The file's directory path.\n + `%p`: The file's full path.\n\nFunctions may also return a working directory to operate in. By default, it\nis the current file's parent directory. @@ -550,7 +550,7 @@ edge_column buffer.edge_column (number)\nThe column number to mark long lines at edge_mode buffer.edge_mode (number)\nThe long line mark mode.\n\n* `buffer.EDGE_NONE`\n Long lines are not marked.\n* `buffer.EDGE_LINE`\n Draw a single vertical line whose color is `buffer.edge_colour` at\n column `buffer.edge_column`.\n* `buffer.EDGE_BACKGROUND`\n Change the background color of text after column `buffer.edge_column`\n to `buffer.edge_colour`.\n* `buffer.EDGE_MULTILINE`\n Draw vertical lines whose colors and columns are defined by calls to\n `buffer:multi_edge_add_line()`. edit_toggle_overtype buffer.edit_toggle_overtype(buffer)\nToggles `buffer.overtype`.\n@param buffer A buffer. editing textadept.editing (module)\nEditing features for Textadept. -editing_keys ui.command_entry.editing_keys (table)\nA metatable with typical platform-specific key bindings for text entries.\nThis metatable may be used to add basic editing keys to command entry modes.\nIt is automatically added to command entry modes unless a metatable was\npreviously set. +editing_keys ui.command_entry.editing_keys (table)\nA metatable with typical platform-specific key bindings for text entries.\nThis metatable may be used to add basic editing and movement keys to command\nentry modes. It is automatically added to command entry modes unless a\nmetatable was previously set. embed lexer.embed(lexer, child, start_rule, end_rule)\nEmbeds child lexer *child* in parent lexer *lexer* using patterns\n*start_rule* and *end_rule*, which signal the beginning and end of the\nembedded lexer, respectively.\n@param lexer The parent lexer.\n@param child The child lexer.\n@param start_rule The pattern that signals the beginning of the embedded\n lexer.\n@param end_rule The pattern that signals the end of the embedded lexer.\n@usage html:embed(css, css_start_rule, css_end_rule)\n@usage html:embed(lex, php_start_rule, php_end_rule) -- from php lexer emit events.emit(event, ...)\nSequentially calls all handler functions for event *event* with the given\narguments.\n*event* may be any arbitrary string and does not need to have been previously\ndefined. If any handler explicitly returns `true` or `false`, `emit()`\nreturns that value and ceases to call subsequent handlers. This is useful for\nstopping the propagation of an event like a keypress after it has been\nhandled.\n@param event The string event name.\n@param ... Arguments passed to the handler.\n@usage events.emit('my_event', 'my message')\n@return `true` or `false` if any handler explicitly returned such; `nil`\n otherwise. empty_undo_buffer buffer.empty_undo_buffer(buffer)\nDeletes the undo and redo history.\n@param buffer A buffer. @@ -562,7 +562,6 @@ end_styled buffer.end_styled (number, Read-only)\nThe current styling position o end_undo_action buffer.end_undo_action(buffer)\nEnds a sequence of actions to be undone or redone as a single action.\n@param buffer A buffer. ensure_visible buffer.ensure_visible(buffer, line)\nEnsures line number *line* is visible by expanding any fold points hiding it.\n@param buffer A buffer.\n@param line The line number in *buffer* to ensure visible. ensure_visible_enforce_policy buffer.ensure_visible_enforce_policy(buffer, line)\nEnsures line number *line* is visible by expanding any fold points hiding it\nbased on the vertical caret policy previously defined in\n`buffer.set_visible_policy()`.\n@param buffer A buffer.\n@param line The line number in *buffer* to ensure visible. -enter_mode ui.command_entry.enter_mode(mode, lexer, height)\nOpens the command entry in key mode *mode*, highlighting text with lexer name\n*lexer*, and displaying *height* number of lines at a time.\nKey bindings will be looked up in `keys[mode]` instead of `keys`. The `Esc`\nkey exits the current mode, closes the command entry, and restores normal key\nlookup.\nThis function is useful for binding keys to enter a command entry mode.\n@param mode The key mode to enter into, or `nil` to exit the current mode.\n@param lexer Optional string lexer name to use for command entry text. The\n default value is `'text'`.\n@param height Optional number of lines to display in the command entry. The\n default value is `1`.\n@usage keys['ce'] =\n function() ui.command_entry.enter_mode('command_entry') end\n@see _G.keys.MODE eol_mode buffer.eol_mode (number)\nThe current end of line mode. Changing the current mode does not convert\nany of the buffer's existing end of line characters.\nUse `buffer.convert_eols()` to do so.\n\n* `buffer.EOL_CRLF`\n Carriage return with line feed ("\r\\n").\n* `buffer.EOL_CR`\n Carriage return ("\r").\n* `buffer.EOL_LF`\n Line feed ("\\n").\n\nThe default value is `buffer.EOL_CRLF` on Windows platforms,\n`buffer.EOL_LF` otherwise. error _G.error(message [, level])\nTerminates the last protected function called and returns `message`\nas the error object. Function `error` never returns.\n\nUsually, `error` adds some information about the error position at the\nbeginning of the message, if the message is a string. The `level` argument\nspecifies how to get the error position. With level 1 (the default), the\nerror position is where the `error` function was called. Level 2 points the\nerror to where the function that called `error` was called; and so on.\nPassing a level 0 avoids the addition of error position information to the\nmessage. error_patterns textadept.run.error_patterns (table)\nMap of file extensions and lexer names to their associated lists of string\npatterns that match warning and error messages emitted by compile and run\ncommands for those file extensions and lexers.\nPatterns match single lines and contain captures for a filename, line number,\ncolumn number (optional), and warning or error message (optional).\nDouble-clicking a warning or error message takes the user to the source of\nthat warning/error.\nNote: `(.-)` captures in patterns are interpreted as filenames; `(%d+)`\ncaptures are interpreted as line numbers first, and then column numbers; and\nany other capture is treated as warning/error message text. @@ -592,12 +591,12 @@ find_in_files ui.find.find_in_files(dir, filter)\nSearches directory *dir* or th find_in_files_filters ui.find.find_in_files_filters (table)\nMap of file paths to filters used in `ui.find.find_in_files()`.\n@see find_in_files find_in_files_timeout ui.find.find_in_files_timeout (number)\nThe approximate interval in seconds between prompts for continuing an\n"In files" search.\nThe default value is 10 seconds. find_incremental ui.find.find_incremental(text, next, anchor)\nBegins an incremental search using the command entry if *text* is `nil`.\nOtherwise, continues an incremental search by searching for the next or\nprevious instance of string *text*, depending on boolean *next*.\n*anchor* indicates whether or not to search for *text* starting from the\ncaret position instead of the position where the incremental search began.\nOnly the `match_case` find option is recognized. Normal command entry\nfunctionality is unavailable until the search is finished or by pressing\n`Esc` (`⎋` on Mac OSX | `Esc` in curses).\n@param text The text to incrementally search for, or `nil` to begin an\n incremental search.\n@param next Flag indicating whether or not the search direction is forward.\n@param anchor Optional flag indicating whether or not to start searching from\n the caret position. The default value is `false`. +find_incremental_keys ui.find.find_incremental_keys (table)\nTable of key bindings used when searching for text incrementally. find_label_text ui.find.find_label_text (string, Write-only)\nThe text of the "Find" label.\nThis is primarily used for localization. find_next ui.find.find_next()\nMimics pressing the "Find Next" button. find_next_button_text ui.find.find_next_button_text (string, Write-only)\nThe text of the "Find Next" button.\nThis is primarily used for localization. find_prev ui.find.find_prev()\nMimics pressing the "Find Prev" button. find_prev_button_text ui.find.find_prev_button_text (string, Write-only)\nThe text of the "Find Prev" button.\nThis is primarily used for localization. -finish_mode ui.command_entry.finish_mode(f)\nExits the current key mode, closes the command entry, and calls function *f*\n(if given) with the command entry's text as an argument.\nThis is useful for binding keys to exit a command entry mode and perform an\naction with the entered text.\n@param f Optional function to call. It should accept the command entry text\n as an argument.\n@usage keys['\\n'] =\n function() return ui.command_entry.finish_mode(ui.print) end first_visible_line buffer.first_visible_line (number)\nThe line number of the line at the top of the view, starting from zero. float lexer.float (pattern)\nA pattern that matches a floating point number. floor math.floor(x)\nReturns the largest integral value smaller than or equal to `x`. @@ -886,6 +885,7 @@ para_down_extend buffer.para_down_extend(buffer)\nMoves the caret down one parag para_up buffer.para_up(buffer)\nMoves the caret up one paragraph.\nParagraphs are surrounded by one or more blank lines.\n@param buffer A buffer. para_up_extend buffer.para_up_extend(buffer)\nMoves the caret up one paragraph, extending the selected text to the new\nposition.\nParagraphs are surrounded by one or more blank lines.\n@param buffer A buffer. paste buffer.paste(buffer)\nPastes the clipboard's contents into the buffer, replacing any selected text\naccording to `buffer.multi_paste`.\n@param buffer A buffer. +paste_reindent textadept.editing.paste_reindent()\nPastes the text from the clipboard, taking into account the buffer's\nindentation settings and the indentation of the current and preceding lines. path lexer.path (string)\nThe path used to search for a lexer to load.\nIdentical in format to Lua's `package.path` string.\nThe default value is `package.path`. path package.path (string)\nThe path used by `require` to search for a Lua loader.\nAt start-up, Lua initializes this variable with the value of the\nenvironment variable `LUA_PATH_5_3` or the environment variable `LUA_PATH`\nor with a default path defined in `luaconf.h`, if those environment\nvariables are not defined. Any "`;;`" in the value of the environment\nvariable is replaced by the default path. patterns textadept.file_types.patterns (table)\nMap of first-line patterns to their associated lexer names.\nEach pattern is matched against the first line in the file. @@ -976,6 +976,7 @@ ruby _G.snippets.ruby (table)\nContainer for Ruby-specific snippets. ruby _M.ruby (module)\nThe ruby module.\nIt provides utilities for editing Ruby code. run textadept.run (module)\nCompile and run source code files with Textadept.\nLanguage modules may tweak the `compile_commands`,\n`run_commands`, and `error_patterns` tables for particular languages.\nThe user may tweak `build_commands` for particular projects. run textadept.run.run(filename)\nRuns file *filename* or the current file using an appropriate shell command\nfrom the `run_commands` table.\nThe shell command is determined from the file's filename, extension, or\nlanguage in that order.\nEmits `RUN_OUTPUT` events.\n@param filename Optional path to the file to run. The default value is the\n current file's filename.\n@see run_commands\n@see _G.events +run ui.command_entry.run(f, mode_keys, lexer, height)\nOpens the command entry, subjecting it to any key bindings defined in table\n*mode_keys*, highlighting text with lexer name *lexer*, and displaying\n*height* number of lines at a time, and then when the `Enter` key is pressed,\ncloses the command entry and calls function *f* (if non-`nil`) with the\ncommand entry's text as an argument.\nBy default with no arguments given, opens a Lua command entry.\nThe command entry does not respond to Textadept's default key bindings, but\ninstead to the key bindings defined in *mode_keys* and in\n`ui.command_entry.editing_keys`.\n@param f Optional function to call upon pressing `Enter` in the command\n entry, ending the mode. It should accept the command entry text as an\n argument.\n@param mode_keys Optional table of key bindings to respond to. This is in\n addition to the basic editing and movement keys defined in\n `ui.command_entry.editing_keys`.\n `Esc` and `Enter` are automatically defined to cancel and finish the\n command entry, respectively.\n This parameter may be omitted completely.\n@param lexer Optional string lexer name to use for command entry text. The\n default value is `'text'`.\n@param height Optional number of lines to display in the command entry. The\n default value is `1`.\n@usage ui.command_entry.run(ui.print)\n@see editing_keys run_commands textadept.run.run_commands (table)\nMap of filenames, file extensions, and lexer names to their associated "run"\nshell command line strings or functions that return strings.\nCommand line strings may have the following macros:\n\n + `%f`: The file's name, including its extension.\n + `%e`: The file's name, excluding its extension.\n + `%d`: The file's directory path.\n + `%p`: The file's full path.\n\nFunctions may also return a working directory to operate in. By default, it\nis the current file's parent directory. run_in_background textadept.run.run_in_background (bool)\nRun shell commands silently in the background.\nThis only applies when the message buffer is open, though it does not have\nto be visible.\nThe default value is `false`. running coroutine.running()\nReturns the running coroutine plus a boolean, true when the running coroutine\nis the main one. diff --git a/modules/lua/tags b/modules/lua/tags index 9e9193fe..95fe1e19 100644 --- a/modules/lua/tags +++ b/modules/lua/tags @@ -570,7 +570,6 @@ end_styled _ 0;" F class:buffer end_undo_action _ 0;" f class:buffer ensure_visible _ 0;" f class:buffer ensure_visible_enforce_policy _ 0;" f class:buffer -enter_mode _ 0;" f class:ui.command_entry eol_mode _ 0;" F class:buffer error _ 0;" f error_patterns _ 0;" t class:textadept.run @@ -600,12 +599,12 @@ find_in_files _ 0;" f class:ui.find find_in_files_filters _ 0;" t class:ui.find find_in_files_timeout _ 0;" F class:ui.find find_incremental _ 0;" f class:ui.find +find_incremental_keys _ 0;" t class:ui.find find_label_text _ 0;" F class:ui.find find_next _ 0;" f class:ui.find find_next_button_text _ 0;" F class:ui.find find_prev _ 0;" f class:ui.find find_prev_button_text _ 0;" F class:ui.find -finish_mode _ 0;" f class:ui.command_entry first_visible_line _ 0;" F class:buffer float _ 0;" F class:lexer floor _ 0;" f class:math @@ -894,6 +893,7 @@ para_down_extend _ 0;" f class:buffer para_up _ 0;" f class:buffer para_up_extend _ 0;" f class:buffer paste _ 0;" f class:buffer +paste_reindent _ 0;" f class:textadept.editing path _ 0;" F class:lexer path _ 0;" F class:package patterns _ 0;" t class:textadept.file_types @@ -983,6 +983,7 @@ ruby _ 0;" m class:_M ruby _ 0;" t class:keys ruby _ 0;" t class:snippets run _ 0;" f class:textadept.run +run _ 0;" f class:ui.command_entry run _ 0;" m class:textadept run_commands _ 0;" t class:textadept.run run_in_background _ 0;" F class:textadept.run diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua index 9b4f36e9..0a8ca6e4 100644 --- a/modules/textadept/command_entry.lua +++ b/modules/textadept/command_entry.lua @@ -6,40 +6,19 @@ local M = ui.command_entry --[[ This comment is for LuaDoc. --- -- Textadept's Command Entry. --- --- ## Modes --- --- The command entry supports multiple [modes](#keys.Modes) that have their own --- sets of key bindings stored in a separate table in `_G.keys` under a mode --- prefix key. Mode names are arbitrary, but cannot conflict with lexer names or --- key sequence strings (e.g. `'lua'` or `'send'`) due to the method Textadept --- uses for looking up key bindings. An example mode is "lua_command" mode for --- executing Lua commands: --- --- local function complete_lua() ... end --- local function run_lua() ... end --- keys['ce'] = function() ui.command_entry.enter_mode('lua_command') end --- keys.lua_command = { --- ['\t'] = complete_lua, --- ['\n'] = function() return ui.command_entry.finish_mode(run_lua) end --- } --- --- 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 editing and movement keys normally. +-- It supports multiple modes that each have their own functionality, such as +-- running Lua code, searching for text incrementally, and filtering text +-- through shell commands. -- @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. --- It is automatically added to command entry modes unless a metatable was --- previously set. --- @usage setmetatable(keys.my_mode, ui.command_entry.editing_keys) +-- This metatable may be used to add basic editing and movement keys to command +-- entry modes. It is automatically added to command entry modes unless a +-- metatable was previously set. +-- @usage setmetatable(mode_keys, ui.command_entry.editing_keys) -- @class table -- @name editing_keys M.editing_keys = {__index = { @@ -60,52 +39,6 @@ M.editing_keys = {__index = { [(OSX or CURSES) and 'cd' or '\0'] = function() M:clear() end }} ---- --- 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'] = --- function() ui.command_entry.enter_mode('command_entry') end --- @see _G.keys.MODE --- @name enter_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 - local mkeys = keys[mode] - if not mkeys['esc'] then mkeys['esc'] = M.enter_mode end - if not getmetatable(mkeys) then setmetatable(mkeys, M.editing_keys) end - end - M:select_all() - M.focus() - M:set_lexer(lexer or 'text') - M.height = M:text_height(0) * (height or 1) -end - ---- --- Exits the current key mode, closes the command entry, and calls function *f* --- (if given) with the command entry's text as an argument. --- This is useful for binding keys to exit a command entry mode and perform an --- action with the entered text. --- @param f Optional function to call. It should accept the command entry text --- as an argument. --- @usage keys['\n'] = --- function() return ui.command_entry.finish_mode(ui.print) end --- @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:get_text())) end -end - -- Environment for abbreviated Lua commands. -- @class table -- @name env @@ -197,19 +130,95 @@ local function complete_lua() M:auto_c_show(#part - 1, table.concat(cmpls, ' ')) end --- Define key mode for entering Lua commands. -keys.lua_command = { - ['\t'] = complete_lua, - ['\n'] = function() return M.finish_mode(run_lua) end -} +-- Key mode for entering Lua commands. +-- @class table +-- @name lua_mode_keys +local lua_mode_keys = {['\t'] = complete_lua} + +--- +-- Opens the command entry, subjecting it to any key bindings defined in table +-- *mode_keys*, highlighting text with lexer name *lexer*, and displaying +-- *height* number of lines at a time, and then when the `Enter` key is pressed, +-- closes the command entry and calls function *f* (if non-`nil`) with the +-- command entry's text as an argument. +-- By default with no arguments given, opens a Lua command entry. +-- The command entry does not respond to Textadept's default key bindings, but +-- instead to the key bindings defined in *mode_keys* and in +-- `ui.command_entry.editing_keys`. +-- @param f Optional function to call upon pressing `Enter` in the command +-- entry, ending the mode. It should accept the command entry text as an +-- argument. +-- @param mode_keys Optional table of key bindings to respond to. This is in +-- addition to the basic editing and movement keys defined in +-- `ui.command_entry.editing_keys`. +-- `Esc` and `Enter` are automatically defined to cancel and finish the +-- command entry, respectively. +-- This parameter may be omitted completely. +-- @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`. +-- @see editing_keys +-- @usage ui.command_entry.run(ui.print) +-- @name run +function M.run(f, mode_keys, lexer, height) + if M:auto_c_active() then M:auto_c_cancel() end -- may happen in curses + if not f and not mode_keys then + f, mode_keys, lexer = run_lua, lua_mode_keys, 'lua' + elseif type(mode_keys) == 'string' then + mode_keys, lexer, height = {}, mode_keys, lexer + elseif not mode_keys then + mode_keys = {} + end + if not mode_keys['esc'] then mode_keys['esc'] = M.focus end -- hide + mode_keys['\n'] = mode_keys['\n'] or function() + if M:auto_c_active() then return false end -- allow Enter to autocomplete + M.focus() -- hide + if f then f((M:get_text())) end + end + if not getmetatable(mode_keys) then + setmetatable(mode_keys, M.editing_keys) + end + M:select_all() + M.focus() + M:set_lexer(lexer or 'text') + M.height = M:text_height(0) * (height or 1) + keys._command_entry, keys.MODE = mode_keys, '_command_entry' +end + +-- Redefine ui.command_entry.focus() to clear any current key mode on hide/show. +local orig_focus = M.focus +M.focus = function() + keys.MODE = nil + orig_focus() +end -- Configure the command entry's default properties. +-- Also find the key binding for `textadept.editing.show_documentation` and use +-- it to show Lua documentation in the Lua command entry. events.connect(events.INITIALIZED, function() 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.call_tip_position = true + for key, f in pairs(keys) do + if f == textadept.editing.show_documentation then + lua_mode_keys[key] = function() + -- Temporarily change _G.buffer since ui.command_entry is the "active" + -- buffer. + local orig_buffer = _G.buffer + _G.buffer = ui.command_entry + textadept.editing.show_documentation() + _G.buffer = orig_buffer + end + break + end + end end) +-- TODO: deprecated; remove after next release. +M.enter_mode = function() ui.dialogs.ok_msgbox{text='ui.command_entry.enter_mode() is deprecated and will be removed.',informative_text='Please use ui.command_entry.run()',no_cancel=true} end +M.finish_mode = function() ui.dialogs.ok_msgbox{text='ui.command_entry.finish_mode() is deprecated and will be removed.',informative_text='Please use ui.command_entry.run()',no_cancel=true} end + --[[ The function below is a Lua C function. --- diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index b817289f..120abae5 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -204,10 +204,31 @@ function M.find_incremental(text, next, anchor) if text then find_incremental(text, next, anchor) return end incremental_start = buffer.current_pos ui.command_entry:set_text('') - ui.command_entry.enter_mode('find_incremental') + ui.command_entry.run(nil, M.find_incremental_keys) end --- +-- Table of key bindings used when searching for text incrementally. +-- @class table +-- @name find_incremental_keys +M.find_incremental_keys = setmetatable({ + ['\n'] = function() + M.find_entry_text = ui.command_entry:get_text() -- save + M.find_incremental(ui.command_entry:get_text(), true, true) + end, + ['\b'] = function() + local e = ui.command_entry:position_before(ui.command_entry.length) + M.find_incremental(ui.command_entry:text_range(0, e), true) + return false -- propagate + end +}, {__index = function(_, k) + -- Add the character for any key pressed without modifiers to incremental + -- find. + if #k > 1 and k:find('^[cams]*.+$') then return end + M.find_incremental(ui.command_entry:get_text()..k, true) +end}) + +--- -- Searches directory *dir* or the user-specified directory for files that match -- search text and search options (subject to optional filter *filter*), and -- prints the results to a buffer titled "Files Found", highlighting found text. diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua index 2d9cc31f..e2968ab6 100644 --- a/modules/textadept/keys.lua +++ b/modules/textadept/keys.lua @@ -532,8 +532,8 @@ elseif CURSES then end -- Unbound keys are handled by Scintilla, but when playing back a macro, this is --- not possible. Define useful default keybindings so Scintilla does not have to --- handle them. +-- not possible. Define useful default key bindings so Scintilla does not have +-- to handle them. keys.left, keys.sleft = buffer.char_left, buffer.char_left_extend keys.cleft, keys.csleft = buffer.word_left, buffer.word_left_extend keys.right, keys.sright = buffer.char_right, buffer.char_right_extend @@ -555,50 +555,16 @@ keys['\b'], keys['s\b'] = buffer.delete_back, buffer.delete_back keys[not OSX and 'c\b' or 'm\b'] = buffer.del_word_left keys[not OSX and 'cs\b' or 'ms\b'] = buffer.del_line_left --- Modes. -keys.filter_through = { - ['\n'] = function() - return ui.command_entry.finish_mode(textadept.editing.filter_through) - end, -} -keys.find_incremental = { - ['\n'] = function() - ui.find.find_entry_text = ui.command_entry:get_text() -- save - ui.find.find_incremental(ui.command_entry:get_text(), true, true) - end, - ['cr'] = function() - ui.find.find_incremental(ui.command_entry:get_text(), false, true) - end, - ['\b'] = function() - local e = ui.command_entry:position_before(ui.command_entry.length) - ui.find.find_incremental(ui.command_entry:text_range(0, e), true) - return false -- propagate - end -} --- Add the character for any key pressed without modifiers to incremental find. -setmetatable(keys.find_incremental, {__index = function(_, k) - if #k > 1 and k:find('^[cams]*.+$') then return end - ui.find.find_incremental(ui.command_entry:get_text()..k, true) - end}) --- Show documentation for symbols in the Lua command entry. -keys.lua_command[GUI and 'ch' or 'mh'] = function() - -- Temporarily change _G.buffer since ui.command_entry is the "active" buffer. - local orig_buffer = _G.buffer - _G.buffer = ui.command_entry - textadept.editing.show_documentation() - _G.buffer = orig_buffer +-- Other. +ui.find.find_incremental_keys.cr = function() + ui.find.find_incremental(ui.command_entry:get_text(), false, true) -- reverse end if OSX or CURSES then -- UTF-8 input. - keys.utf8_input = { - ['\n'] = function() - return ui.command_entry.finish_mode(function(code) - buffer:add_text(utf8.char(tonumber(code, 16))) - end) - end - } keys[OSX and 'mU' or 'mu'] = function() - ui.command_entry.enter_mode('utf8_input') + ui.command_entry.run(function(code) + buffer:add_text(utf8.char(tonumber(code, 16))) + end) end end diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index caaa3463..9b4cb9a4 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -103,7 +103,7 @@ local default_menubar = { {_L['T_ranspose Characters'], textadept.editing.transpose_chars}, {_L['_Join Lines'], textadept.editing.join_lines}, {_L['_Filter Through'], function() - ui.command_entry.enter_mode('filter_through', 'bash') + ui.command_entry.run(textadept.editing.filter_through, 'bash') end}, { title = _L['_Select'], @@ -163,9 +163,7 @@ local default_menubar = { }, { title = _L['_Tools'], - {_L['Command _Entry'], function() - ui.command_entry.enter_mode('lua_command', 'lua') - end}, + {_L['Command _Entry'], ui.command_entry.run}, {_L['Select Co_mmand'], function() M.select_command() end}, SEPARATOR, {_L['_Run'], textadept.run.run}, |