diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/textadept/keys.lua | 16 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 2 | ||||
-rw-r--r-- | modules/textadept/run.lua | 122 |
3 files changed, 101 insertions, 39 deletions
diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua index a801540c..27fc599f 100644 --- a/modules/textadept/keys.lua +++ b/modules/textadept/keys.lua @@ -81,6 +81,8 @@ local M = {} -- Ctrl+Shift+E |⌘⇧E |M-S-C |Select command -- Ctrl+R |⌘R |^R |Run -- Ctrl+Shift+R |⌘⇧R |M-^R |Compile +-- Ctrl+Shift+B |⌘⇧B |M-^B |Build +-- Ctrl+Shift+X |⌘⇧X |N/A |Stop -- Ctrl+Alt+E |^⌘E |M-X |Next Error -- Ctrl+Alt+Shift+E|^⌘⇧E |M-S-X |Previous Error -- Ctrl+Space |⌥Esc |^Space |Complete symbol @@ -97,6 +99,7 @@ local M = {} -- Ctrl+U |⌘U |^U |Snapopen `_USERHOME` -- None |None |None |Snapopen `_HOME` -- Ctrl+Alt+Shift+O|^⌘⇧O |M-S-O |Snapopen current directory +-- Ctrl+Alt+Shift+P|^⌘⇧P |M-^P |Snapopen current project -- Ctrl+I |⌘I |None |Show style -- **Buffer** | | | -- Ctrl+Tab |^⇥ |M-N |Next buffer @@ -306,9 +309,9 @@ for _, f in ipairs(menu_buffer_functions) do buffer[f] = buffer[f] end -- Windows and Linux key bindings. -- -- Unassigned keys (~ denotes keys reserved by the operating system): --- c: A B C H p Q T ~ V X Y _ ) ] } + +-- c: A C H p Q T ~ V Y _ ) ] } + -- a: aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ_ ) ] } *+-/=\n\s --- ca: aAbBcCdD F jJkKlLmM N PqQ t xXy zZ_"'()[]{}<>* / \s +-- ca: aAbBcCdD F jJkKlLmM N qQ t xXy zZ_"'()[]{}<>* / \s -- -- CTRL = 'c' (Control ^) -- ALT = 'a' (Alt) @@ -321,9 +324,9 @@ for _, f in ipairs(menu_buffer_functions) do buffer[f] = buffer[f] end -- Mac OSX key bindings. -- -- Unassigned keys (~ denotes keys reserved by the operating system): --- m: A B C ~ JkK ~M p ~ tT U V XyY _ ) ] } + ~~\n +-- m: A C ~ JkK ~M p ~ tT U V yY _ ) ] } + ~~\n -- c: cC D gG H J K L oO qQ xXyYzZ_ ) ] } * / --- cm: aAbBcC~D F ~HiIjJkKlL~MnN pPq~rRsStTuUvVwWxXyYzZ_"'()[]{}<>*+-/=\t\n +-- cm: aAbBcC~D F ~HiIjJkKlL~MnN p q~rRsStTuUvVwWxXyYzZ_"'()[]{}<>*+-/=\t\n -- -- CTRL = 'c' (Control ^) -- ALT = 'a' (Alt/option ⌥) @@ -348,7 +351,7 @@ for _, f in ipairs(menu_buffer_functions) do buffer[f] = buffer[f] end -- -- Unassigned keys (~ denotes keys reserved by the operating system): -- c: g~~ ~ --- cm: bcd g~~ k ~ pq t xyz +-- cm: cd g~~ k ~ q t xyz -- m: e J qQ sS u vVw yYzZ_ + -- Note: m[befhstv] may be used by Linux/BSD GUI terminals for menu access. -- @@ -465,6 +468,8 @@ keys[not OSX and (not CURSES and 'ce' or 'mc') 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 +keys[not OSX and (not CURSES and 'cB' or 'cmb') or 'mB'] = textadept.run.build +if not CURSES then keys[not OSX and 'cX' or 'mX'] = textadept.run.stop end keys[not OSX and (not CURSES and 'cae' or 'mx') or 'cme'] = {textadept.run.goto_error, false, true} keys[not OSX and (not CURSES and 'caE' or 'mX') @@ -494,6 +499,7 @@ keys[not OSX and 'cu' or 'mu'] = {io.snapopen, _USERHOME} -- TODO: {io.snapopen, _HOME} keys[not OSX and (not CURSES and 'caO' or 'mO') or 'cmO'] = utils.snapopen_filedir +keys[not OSX and (not CURSES and 'caP' or 'cmp') or 'cmP'] = io.snapopen if not CURSES then keys[not OSX and 'ci' or 'mi'] = utils.show_style end -- Buffer. diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index 73ddbb83..836f3328 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -103,6 +103,7 @@ local menubar = { SEPARATOR, {_L['_Run'], textadept.run.run}, {_L['_Compile'], textadept.run.compile}, + {_L['Buil_d'], textadept.run.build}, {_L['S_top'], textadept.run.stop}, {_L['_Next Error'], {textadept.run.goto_error, false, true}}, {_L['_Previous Error'], {textadept.run.goto_error, false, false}}, @@ -122,6 +123,7 @@ local menubar = { {_L['Snapopen _User Home'], {io.snapopen, _USERHOME}}, {_L['Snapopen _Textadept Home'], {io.snapopen, _HOME}}, {_L['Snapopen _Current Directory'], utils.snapopen_filedir}, + {_L['Snapopen Current _Project'], io.snapopen}, }, { title = _L['_Snippets'], {_L['_Insert Snippet...'], textadept.snippets._select}, diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua index 15bf3c9c..3170b5aa 100644 --- a/modules/textadept/run.lua +++ b/modules/textadept/run.lua @@ -19,6 +19,7 @@ local M = {} -- It is used for going to error messages with relative file paths. -- @field proc (process) -- The currently running process or the most recent process run. +-- This field does not exist in the terminal version. -- @field _G.events.COMPILE_OUTPUT (string) -- Emitted when executing a language's compile shell command. -- By default, compiler output is printed to the message buffer. To override @@ -35,6 +36,14 @@ local M = {} -- -- * `lexer`: The language's lexer name. -- * `output`: A line of string output from the command. +-- @field _G.events.BUILD_OUTPUT (string) +-- Emitted when executing a project's build shell command. +-- By default, output is printed to the message buffer. To override this +-- behavior, connect to the event with an index of `1` and return `true`. +-- Arguments: +-- +-- * `project`: The path to the project being built. +-- * `output`: A line of string output from the command. module('textadept.run')]] M.MARK_WARNING = _SCINTILLA.next_marker_number() @@ -42,49 +51,76 @@ M.MARK_ERROR = _SCINTILLA.next_marker_number() -- Events. events.COMPILE_OUTPUT, events.RUN_OUTPUT = 'compile_output', 'run_output' +events.BUILD_OUTPUT = 'build_output' local preferred_view --- Executes a compile or run shell command. --- Emits a `COMPILE_OUTPUT` or `RUN_OUTPUT` event based on the `compiling` flag. --- @param commands Either `compile_commands` or `run_commands`. --- @param compiling Flag indicating whether or not the command is a compiler --- command. The default value is `false`. +-- Executes compile, run, or build shell command *command*. +-- Emits events named *event*. +-- @param commands Either `compile_commands`, `run_commands`, or +-- `build_commands`. +-- @param event Event to emit upon command output. -- @see _G.events -local function command(commands, compiling) - if not buffer.filename then return end - buffer:annotation_clear_all() - io.save_file() - local command = commands[buffer.filename:match('[^.]+$')] or - commands[buffer:get_lexer()] - if not command then return end +local function command(commands, event) + local command, cwd, data + if commands ~= M.build_commands then + if not buffer.filename then return end + buffer:annotation_clear_all() + io.save_file() + command = commands[buffer.filename:match('[^.]+$')] or + commands[buffer:get_lexer()] + cwd = buffer.filename:match('^(.+[/\\])[^/\\]+$') or '' + data = buffer:get_lexer() + else + cwd = io.get_project_root() + command = commands[cwd] + if not command then + local lfs_attributes = lfs.attributes + for build_file, build_command in pairs(commands) do + if lfs_attributes(cwd..'/'..build_file) then + local button, cmd = ui.dialogs.standard_inputbox{ + title = _L['Command'], informative_text = cwd, text = build_command + } + if button == 1 then command = cmd end + break + end + end + end + data = cwd + end if type(command) == 'function' then command = command() end - local filepath, filedir, filename = buffer.filename, '', buffer.filename - if filepath:find('[/\\]') then - filedir, filename = filepath:match('^(.+[/\\])([^/\\]+)$') + if not command then return end + if buffer.filename then + local filepath, filedir, filename = buffer.filename, '', buffer.filename + if filepath:find('[/\\]') then + filedir, filename = filepath:match('^(.+[/\\])([^/\\]+)$') + end + local filename_noext = filename:match('^(.+)%.') + command = command:gsub('%%%b()', { + ['%(filepath)'] = filepath, ['%(filedir)'] = filedir, + ['%(filename)'] = filename, ['%(filename_noext)'] = filename_noext, + }):gsub('%%([dfe])', {d = filedir, f = filename, e = filename_noext}) end - local filename_noext = filename:match('^(.+)%.') - command = command:gsub('%%%b()', { - ['%(filepath)'] = filepath, ['%(filedir)'] = filedir, - ['%(filename)'] = filename, ['%(filename_noext)'] = filename_noext, - }):gsub('%%([dfe])', {d = filedir, f = filename, e = filename_noext}) preferred_view = view local events_emit = events.emit - local event = compiling and events.COMPILE_OUTPUT or events.RUN_OUTPUT - local lexer = buffer:get_lexer() local function emit_output(output) - events_emit(event, lexer, output:iconv('UTF-8', _CHARSET)) + ui.SILENT_PRINT = true + for line in output:gmatch('[^\r\n]+') do + events_emit(event, data, line:iconv('UTF-8', _CHARSET)) + end + ui.SILENT_PRINT = false end + command, cwd = command:iconv('UTF-8', _CHARSET), cwd:iconv('UTF-8', _CHARSET) + if commands == M.build_commands then emit_output('> cd '..cwd) end emit_output('> '..command) - ui.SILENT_PRINT = true - proc = spawn(command, filedir, emit_output, emit_output, function(status) + local p, err = spawn(command, cwd, emit_output, emit_output, function(status) emit_output('> exit status: '..status) - ui.SILENT_PRINT = false end) + if not p then error(err) end - M.cwd = filedir + M.proc, M.cwd = p, cwd end -- Parses the given message for a warning or error message and returns a table @@ -128,7 +164,7 @@ end --- -- Map of file extensions or lexer names to their associated "compile" shell --- command line strings or functions returning such strings. +-- command line strings or functions that return such strings. -- Command line strings may have the following macros: -- -- + `%f` or `%(filename)`: The file's name, including its extension. @@ -142,16 +178,16 @@ M.compile_commands = {actionscript='mxmlc "%f"',ada='gnatmake "%f"',ansi_c='gcc --- -- Compiles the current file based on its extension or language, using the -- shell command from the `compile_commands` table. --- Emits a `COMPILE_OUTPUT` event. +-- Emits `COMPILE_OUTPUT` events. -- @see compile_commands -- @see _G.events -- @name compile -function M.compile() command(M.compile_commands, true) end +function M.compile() command(M.compile_commands, events.COMPILE_OUTPUT) end events.connect(events.COMPILE_OUTPUT, print_output) --- -- Map of file extensions or lexer names to their associated "run" shell command --- line strings or functions returning such strings. +-- line strings or functions that return strings. -- Command line strings may have the following macros: -- -- + `%f` or `%(filename)`: The file's name, including its extension. @@ -165,17 +201,35 @@ M.run_commands = {actionscript=WIN32 and 'start "" "%e.swf"' or OSX and 'open "f --- -- Runs the current file based on its extension or language, using the shell -- command from the `run_commands` table. --- Emits a `RUN_OUTPUT` event. +-- Emits `RUN_OUTPUT` events. -- @see run_commands -- @see _G.events -- @name run -function M.run() command(M.run_commands) end +function M.run() command(M.run_commands, events.RUN_OUTPUT) end events.connect(events.RUN_OUTPUT, print_output) --- +-- Map of project root paths and "makefiles" to their associated "build" shell +-- command line strings or functions that return such strings. +-- @class table +-- @name build_commands +M.build_commands = {--[[Ant]]['build.xml']='ant',--[[Make]]Makefile='make',GNUmakefile='make',makefile='make',--[[Maven]]['pom.xml']='mvn',--[[Ruby]]Rakefile='rake'} + +--- +-- Builds the current project based on the buffer's filename or the current +-- working directory. +-- If a "makefile" type of build file is found, prompts the user for the full +-- build command. +-- Emits `BUILD_OUTPUT` events. +-- @see _G.events +-- @name build +function M.build() command(M.build_commands, events.BUILD_OUTPUT) end +events.connect(events.BUILD_OUTPUT, print_output) + +--- -- Stops the currently running process, if any. -- @name stop -function M.stop() if proc then proc:kill() end end +function M.stop() if M.proc then M.proc:kill() end end --- -- List of warning and error string patterns that match various compile and run |