diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/lua/ta_api | 5 | ||||
-rw-r--r-- | modules/lua/ta_tags | 3 | ||||
-rw-r--r-- | modules/textadept/keys.lua | 8 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 1 | ||||
-rw-r--r-- | modules/textadept/run.lua | 60 |
5 files changed, 64 insertions, 13 deletions
diff --git a/modules/lua/ta_api b/modules/lua/ta_api index edaf6115..85d9fb97 100644 --- a/modules/lua/ta_api +++ b/modules/lua/ta_api @@ -250,6 +250,7 @@ SUSPEND events.SUSPEND (string)\nEmitted when suspending Textadept. If any handl TAB_CLICKED events.TAB_CLICKED (string)\nEmitted when the user clicks on a buffer tab.\nWhen connecting to this event, connect with an index of 1 if the handler\nneeds to run before Textadept switches between buffers.\nNote that Textadept always displays a context menu on right-click.\nArguments:\n\n* _`index`_: The numeric index of the clicked tab.\n* _`button`_: The mouse button number that was clicked, either `1` (left\n button), `2` (middle button), `3` (right button), `4` (wheel up), or `5`\n (wheel down).\n* _`shift`_: The "Shift" modifier key is held down.\n* _`ctrl`_: The "Control" modifier key is held down.\n* _`alt`_: The "Alt"/"Option" modifier key is held down.\n* _`cmd`_: The "Command" modifier key on macOS is held down. TD_LONGARROW view.TD_LONGARROW (number, Read-only)\n TD_STRIKEOUT view.TD_STRIKEOUT (number, Read-only)\n +TEST_OUTPUT events.TEST_OUTPUT (string)\nEmitted when executing a project's shell command for running tests.\nBy default, output is printed to the message buffer. In order to override\nthis behavior, connect to the event with an index of `1` and return `true`.\nArguments:\n\n* `output`: A line of string output from the command. TIME_FOREVER view.TIME_FOREVER (number, Read-only)\n TYPE lexer.TYPE (string)\nThe token name for type tokens. TYPEDEF textadept.editing.XPM_IMAGES.TYPEDEF (table)\nThe image number for type definitions. @@ -804,7 +805,7 @@ rgba_image_height view.rgba_image_height (number)\nThe height of the RGBA image rgba_image_scale view.rgba_image_scale (number)\nThe scale factor in percent of the RGBA image to be defined using\n`view.marker_define_rgba_image()`.\nThis is useful on macOS with a retina display where each display unit is 2\npixels: use a factor of `200` so that each image pixel is displayed using a\nscreen pixel. The default scale, `100`, will stretch each image pixel to\ncover 4 screen pixels on a retina display. rgba_image_width view.rgba_image_width (number)\nThe width of the RGBA image to be defined using\n`view.marker_define_rgba_image()` and\n`view.register_rgba_image()`. rotate_selection buffer.rotate_selection(buffer)\nDesignates the next additional selection to be the main selection.\n@param buffer A buffer. -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 (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` and `test_commands` for particular\nprojects. 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, keys, lang, height)\nOpens the command entry, subjecting it to any key bindings defined in table\n*keys*, highlighting text with lexer name *lang*, 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 *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 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 lang 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 and process environment table\nto operate in. By default, the working directory is the current file's parent\ndirectory and the environment is Textadept's environment. @@ -937,6 +938,8 @@ target_start buffer.target_start (number)\nThe position of the beginning of the target_start_virtual_space buffer.target_start_virtual_space (number)\nThe position of the beginning of virtual space in the target range.\nThis is set to `1` when `buffer.target_start` or\n`buffer.target_end` is set, or when `buffer.set_target_range()` is\ncalled. target_text buffer.target_text (string, Read-only)\nThe text in the target range. target_whole_document buffer.target_whole_document(buffer)\nDefines the target range's beginning and end positions as the beginning and\nend positions of the document, respectively.\n@param buffer A buffer. +test textadept.run.test(root_directory)\nRuns tests for the project whose root path is *root_directory* or the current\nproject using the shell command from the `test_commands` table.\nThe current project is determined by either the buffer's filename or the\ncurrent working directory.\nEmits `TEST_OUTPUT` events.\n@param root_directory The path to the project to run tests for. The default\n value is the current project.\n@see test_commands\n@see _G.events +test_commands textadept.run.test_commands (table)\nMap of project root paths to their associated "test" shell command line\nstrings or functions that return such strings.\nFunctions may also return a working directory and process environment table\nto operate in. By default, the working directory is the project's root\ndirectory and the environment is Textadept's environment. text_height view.text_height(view, line)\nReturns the pixel height of line number *line*.\n@param view A view.\n@param line The line number in *view* to get the pixel height of.\n@return number text_length buffer.text_length (number, Read-only)\nThe number of bytes in the buffer. text_range buffer.text_range(buffer, start_pos, end_pos)\nReturns the range of text between positions *start_pos* and *end_pos*.\n@param buffer A buffer.\n@param start_pos The start position of the range of text to get in *buffer*.\n@param end_pos The end position of the range of text to get in *buffer*. diff --git a/modules/lua/ta_tags b/modules/lua/ta_tags index 7e245f62..09f7071b 100644 --- a/modules/lua/ta_tags +++ b/modules/lua/ta_tags @@ -250,6 +250,7 @@ SUSPEND _HOME/core/events.lua /^module('events')]]$/;" F class:events TAB_CLICKED _HOME/core/events.lua /^module('events')]]$/;" F class:events TD_LONGARROW _HOME/core/.view.luadoc /^module('view')$/;" F class:view TD_STRIKEOUT _HOME/core/.view.luadoc /^module('view')$/;" F class:view +TEST_OUTPUT _HOME/modules/textadept/run.lua /^module('textadept.run')]]$/;" F class:events TIME_FOREVER _HOME/core/.view.luadoc /^module('view')$/;" F class:view TYPE _HOME/lexers/lexer.lua /^module('lexer')]=]$/;" F class:lexer TYPEDEF _HOME/modules/textadept/editing.lua /^M.XPM_IMAGES = {not CURSES and '/* XPM */static char *class[] = {/* columns rows colors chars-per-pixel */"16 16 10 1 "," c #000000",". c #001CD0","X c #008080","o c #0080E8","O c #00C0C0","+ c #24D0FC","@ c #00FFFF","# c #A4E8FC","$ c #C0FFFF","% c None",/* pixels */"%%%%% %%%%%%%%%","%%%% ## %%%%%%%","%%% ###++ %%%%%%","%% +++++. %%%%","%% oo++.. $$ %%","%% ooo.. $$$@@ %","%% ooo. @@@@@X %","%%% . OO@@XX %","%%% ## OOOXXX %","%% ###++ OOXX %%","% +++++. OX %%%","% oo++.. % %%%%","% ooo... %%%%%%%","% ooo.. %%%%%%%%","%% o. %%%%%%%%%","%%%% %%%%%%%%%%"};' or '*',not CURSES and '/* XPM */static char *namespace[] = {/* columns rows colors chars-per-pixel */"16 16 7 1 "," c #000000",". c #1D1D1D","X c #393939","o c #555555","O c #A8A8A8","+ c #AAAAAA","@ c None",/* pixels */"@@@@@@@@@@@@@@@@","@@@@+@@@@@@@@@@@","@@@.o@@@@@@@@@@@","@@@ +@@@@@@@@@@@","@@@ +@@@@@@@@@@@","@@+.@@@@@@@+@@@@","@@+ @@@@@@@o.@@@","@@@ +@@@@@@+ @@@","@@@ +@@@@@@+ @@@","@@@.X@@@@@@@.+@@","@@@@+@@@@@@@ @@@","@@@@@@@@@@@+ @@@","@@@@@@@@@@@+ @@@","@@@@@@@@@@@X.@@@","@@@@@@@@@@@+@@@@","@@@@@@@@@@@@@@@@"};' or '@',not CURSES and '/* XPM */static char *method[] = {/* columns rows colors chars-per-pixel */"16 16 5 1 "," c #000000",". c #E0BC38","X c #F0DC5C","o c #FCFC80","O c None",/* pixels */"OOOOOOOOOOOOOOOO","OOOOOOOOOOOOOOOO","OOOOOOOOOOOOOOOO","OOOOOOOOOO OOOO","OOOOOOOOO oo OO","OOOOOOOO ooooo O","OOOOOOO ooooo. O","OOOO O XXoo.. O","OOO oo XXX... O","OO ooooo XX.. OO","O ooooo. X. OOO","O XXoo.. O OOOO","O XXX... OOOOOOO","O XXX.. OOOOOOOO","OO X. OOOOOOOOO","OOOO OOOOOOOOOO"};' or '+',not CURSES and '/* XPM */static char *signal[] = {/* columns rows colors chars-per-pixel */"16 16 6 1 "," c #000000",". c #FF0000","X c #E0BC38","o c #F0DC5C","O c #FCFC80","+ c None",/* pixels */"++++++++++++++++","++++++++++++++++","++++++++++++++++","++++++++++ ++++","+++++++++ OO ++","++++++++ OOOOO +","+++++++ OOOOOX +","++++ + ooOOXX +","+++ OO oooXXX +","++ OOOOO ooXX ++","+ OOOOOX oX +++","+ ooOOXX + ++++","+ oooXXX +++++++","+ oooXX +++++..+","++ oX ++++++..+","++++ ++++++++++"};' or '~',not CURSES and '/* XPM */static char *slot[] = {/* columns rows colors chars-per-pixel */"16 16 5 1 "," c #000000",". c #E0BC38","X c #F0DC5C","o c #FCFC80","O c None",/* pixels */"OOOOOOOOOOOOOOOO","OOOOOOOOOOOOOOOO","OOOOOOOOOOOOOOOO","OOOOOOOOOO OOOO","OOOOOOOOO oo OO","OOOOOOOO ooooo O","OOOOOOO ooooo. O","OOOO O XXoo.. O","OOO oo XXX... O","OO ooooo XX.. OO","O ooooo. X. OOO","O XXoo.. O OOOO","O XXX... OOOOOOO","O XXX.. OOOOO ","OO X. OOOOOO O ","OOOO OOOOOOO "};' or '-',not CURSES and '/* XPM */static char *variable[] = {/* columns rows colors chars-per-pixel */"16 16 5 1 "," c #000000",". c #8C748C","X c #9C94A4","o c #ACB4C0","O c None",/* pixels */"OOOOOOOOOOOOOOOO","OOOOOOOOOOOOOOOO","OOOOOOOOOOOOOOOO","OOOOOOOOOOOOOOOO","OOOOOOOOOOOOOOOO","OOOOOOOOOOOOOOOO","OOOOOOOOO OOOOO","OOOOOOOO oo OOO","OOOOOOO ooooo OO","OOOOOO ooooo. OO","OOOOOO XXoo.. OO","OOOOOO XXX... OO","OOOOOO XXX.. OOO","OOOOOOO X. OOOO","OOOOOOOOO OOOOO","OOOOOOOOOOOOOOOO"};' or '.',not CURSES and '/* XPM */static char *struct[] = {/* columns rows colors chars-per-pixel */"16 16 14 1 "," c #000000",". c #008000","X c #00C000","o c #00FF00","O c #808000","+ c #C0C000","@ c #FFFF00","# c #008080","$ c #00C0C0","% c #00FFFF","& c #C0FFC0","* c #FFFFC0","= c #C0FFFF","- c None",/* pixels */"----- ---------","---- && -------","--- &&&oo ------","-- ooooo. ----","-- XXoo.. == --","-- XXX.. ===%% -","-- XXX. %%%%%# -","--- . $$%%## -","--- ** $$$### -","-- ***@@ $$## --","- @@@@@O $# ---","- ++@@OO - ----","- +++OOO -------","- +++OO --------","-- +O ---------","---- ----------"};' or '}',not CURSES and '/* XPM */static char *typedef[] = {/* columns rows colors chars-per-pixel */"16 16 10 1 "," c #000000",". c #404040","X c #6D6D6D","o c #777777","O c #949494","+ c #ACACAC","@ c #BBBBBB","# c #DBDBDB","$ c #EEEEEE","% c None",/* pixels */"%%%%% %%%%%%%%%","%%%% ## %%%%%%%","%%% ###++ %%%%%%","%% +++++. %%%%","%% oo++.. $$ %%","%% ooo.. $$$@@ %","%% ooo. @@@@@X %","%%% . OO@@XX %","%%% ## OOOXXX %","%% ###++ OOXX %%","% +++++. OX %%%","% oo++.. % %%%%","% ooo... %%%%%%%","% ooo.. %%%%%%%%","%% o. %%%%%%%%%","%%%% %%%%%%%%%%"};' or ':',CLASS=1,NAMESPACE=2,METHOD=3,SIGNAL=4,SLOT=5,VARIABLE=6,STRUCT=7,TYPEDEF=8}$/;" F class:textadept.editing.XPM_IMAGES @@ -939,6 +940,8 @@ target_start _HOME/core/.buffer.luadoc /^module('buffer')$/;" F class:buffer target_start_virtual_space _HOME/core/.buffer.luadoc /^module('buffer')$/;" F class:buffer target_text _HOME/core/.buffer.luadoc /^module('buffer')$/;" F class:buffer target_whole_document _HOME/core/.buffer.luadoc /^function target_whole_document(buffer) end$/;" f class:buffer +test _HOME/modules/textadept/run.lua /^function M.test(root_directory)$/;" f class:textadept.run +test_commands _HOME/modules/textadept/run.lua /^M.test_commands = {}$/;" t class:textadept.run text_height _HOME/core/.view.luadoc /^function text_height(view, line) end$/;" f class:view text_length _HOME/core/.buffer.luadoc /^module('buffer')$/;" F class:buffer text_range _HOME/core/.buffer.luadoc /^function text_range(buffer, start_pos, end_pos) end$/;" f class:buffer diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua index c365191a..0e5e69d5 100644 --- a/modules/textadept/keys.lua +++ b/modules/textadept/keys.lua @@ -82,6 +82,7 @@ local M = {} -- Ctrl+Shift+R |⌘⇧R |M-^R |Compile -- Ctrl+Shift+A |⌘⇧A |None |Set Arguments... -- Ctrl+Shift+B |⌘⇧B |M-^B |Build +-- Ctrl+Shift+T |⌘⇧T |M-^T |Run tests -- Ctrl+Shift+X |⌘⇧X |M-^X |Stop -- Ctrl+Alt+E |^⌘E |M-X |Next Error -- Ctrl+Alt+Shift+E|^⌘⇧E |M-S-X |Previous Error @@ -221,7 +222,7 @@ module('textadept.keys')]] -- Windows, Linux, and BSD key bindings. -- -- Unassigned keys (~ denotes keys reserved by the operating system): --- c: C H I Q T ~ V Y _ ) ] } + +-- c: C H I Q ~ V Y _ ) ] } + -- a: aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ_ ) ] } *+-/=\n\s -- ca: aAbBcCdD F H jJkKlLmM N qQ t xXy zZ_"'()[]{}<>* / \n\s -- @@ -234,7 +235,7 @@ module('textadept.keys')]] -- macOS key bindings. -- -- Unassigned keys (~ denotes keys reserved by the operating system): --- m: C ~H I JkK ~M p ~ tT V yY _ ) ] } + ~~\n +-- m: C ~H I JkK ~M p ~ t V yY _ ) ] } + ~~\n -- c: cC D gG H J K L oO qQ xXyYzZ_ ) ] } * / \n -- cm: aAbBcC~D F ~HiIjJkKlL~MnN p q~rRsStTuUvVwWxXyYzZ_"'()[]{}<>*+-/=\t\n -- @@ -261,7 +262,7 @@ module('textadept.keys')]] -- -- Unassigned keys (~ denotes keys reserved by the operating system): -- c: g~~ l~ ~ --- cm: cd g~~ k ~ q t yz +-- cm: cd g~~ k ~ q yz -- m: e J qQ sS vVw yY _ + -- Note: m[befhstv] may be used by Linux/BSD GUI terminals for menu access. -- @@ -370,6 +371,7 @@ local bindings = { [textadept.run.compile] = {'ctrl+R', 'cmd+R', 'ctrl+meta+r'}, [textadept.run.set_arguments] = {'ctrl+A', 'cmd+A', nil}, [textadept.run.build] = {'ctrl+B', 'cmd+B', 'ctrl+meta+b'}, + [textadept.run.test] = {'ctrl+T', 'cmd+T', 'ctrl+meta+t'}, [textadept.run.stop] = {'ctrl+X', 'cmd+X', 'ctrl+meta+x'}, [m('Tools/Next Error')] = {'ctrl+alt+e', 'ctrl+cmd+e', 'meta+x'}, [m('Tools/Previous Error')] = {'ctrl+alt+E', 'ctrl+cmd+E', 'meta+X'}, diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index 1ae2d909..b3ce1015 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -171,6 +171,7 @@ local default_menubar = { {_L['Compile'], textadept.run.compile}, {_L['Set Arguments...'], textadept.run.set_arguments}, {_L['Build'], textadept.run.build}, + {_L['Run tests'], textadept.run.test}, {_L['Stop'], textadept.run.stop}, {_L['Next Error'], function() textadept.run.goto_error(true) end}, {_L['Previous Error'], function() textadept.run.goto_error(false) end}, diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua index ba7526cf..f9f462f5 100644 --- a/modules/textadept/run.lua +++ b/modules/textadept/run.lua @@ -7,7 +7,8 @@ local M = {} -- Compile and run source code files with Textadept. -- [Language modules](#compile-and-run) may tweak the `compile_commands`, -- `run_commands`, and `error_patterns` tables for particular languages. --- The user may tweak `build_commands` for particular projects. +-- The user may tweak `build_commands` and `test_commands` for particular +-- projects. -- @field run_in_background (bool) -- Run shell commands silently in the background. -- This only applies when the message buffer is open, though it does not have @@ -43,6 +44,13 @@ local M = {} -- Arguments: -- -- * `output`: A line of string output from the command. +-- @field _G.events.TEST_OUTPUT (string) +-- Emitted when executing a project's shell command for running tests. +-- By default, output is printed to the message buffer. In order to override +-- this behavior, connect to the event with an index of `1` and return `true`. +-- Arguments: +-- +-- * `output`: A line of string output from the command. module('textadept.run')]] M.run_in_background = false @@ -51,7 +59,9 @@ M.MARK_WARNING = _SCINTILLA.next_marker_number() M.MARK_ERROR = _SCINTILLA.next_marker_number() -- Events. -local run_events = {'compile_output', 'run_output', 'build_output'} +local run_events = { + 'compile_output', 'run_output', 'build_output', 'test_output' +} for _, v in ipairs(run_events) do events[v:upper()] = v end -- Keep track of: the last process spawned in order to kill it if requested; the @@ -92,10 +102,10 @@ local function scan_for_error(message, ext_or_lexer) message:lower():find('warning') and not message:lower():find('error') -- Compile and run commands specify the file extension or lexer name used -- to determine the command, so the error patterns used are guaranteed to - -- be correct. Build commands have no such context and instead iterate - -- through all possible error patterns. Only consider the error/warning - -- valid if the extracted filename's extension or lexer name matches the - -- error pattern's extension or lexer name. + -- be correct. Build and test commands have no such context and instead + -- iterate through all possible error patterns. Only consider the + -- error/warning valid if the extracted filename's extension or lexer name + -- matches the error pattern's extension or lexer name. if ext_or_lexer then return detail end local ext = detail.filename:match('[^/\\.]+$') local lexer_name = textadept.file_types.extensions[ext] @@ -107,7 +117,7 @@ local function scan_for_error(message, ext_or_lexer) return nil end --- Prints an output line from a compile, run, or build shell command. +-- Prints an output line from a compile, run, build, or test shell command. -- Assume output is UTF-8 unless there's a recognized warning or error message. -- In that case assume it is encoded in _CHARSET and mark it. -- All stdout and stderr from the command is printed silently. @@ -129,8 +139,8 @@ local function print_line(line, ext_or_lexer) end local output_buffer --- Prints the output from a compile, run, or build shell command as a series of --- lines, performing buffering as needed. +-- Prints the output from a compile, run, build, or test shell command as a +-- series of lines, performing buffering as needed. -- @param output The output to print, or `nil` to flush any buffered output. -- @param ext_or_lexer Optional file extension or lexer name associated with the -- executed command. This is used for better error detection in compile and @@ -369,6 +379,38 @@ end events.connect(events.BUILD_OUTPUT, print_output) --- +-- Map of project root paths to their associated "test" shell command line +-- strings or functions that return such strings. +-- Functions may also return a working directory and process environment table +-- to operate in. By default, the working directory is the project's root +-- directory and the environment is Textadept's environment. +-- @class table +-- @name test_commands +M.test_commands = {} + +--- +-- Runs tests for the project whose root path is *root_directory* or the current +-- project using the shell command from the `test_commands` table. +-- The current project is determined by either the buffer's filename or the +-- current working directory. +-- Emits `TEST_OUTPUT` events. +-- @param root_directory The path to the project to run tests for. The default +-- value is the current project. +-- @see test_commands +-- @see _G.events +-- @name test +function M.test(root_directory) + if not assert_type(root_directory, 'string/nil', 1) then + root_directory = io.get_project_root() + if not root_directory then return end + end + for i = 1, #_BUFFERS do _BUFFERS[i]:annotation_clear_all() end + run_command( + M.test_commands[root_directory], root_directory, events.TEST_OUTPUT) +end +events.connect(events.TEST_OUTPUT, print_output) + +--- -- Stops the currently running process, if any. -- @name stop function M.stop() if proc then proc:kill() end end |