From f65b2b2a66f05b20010256ca1d81cc3252ea1471 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Wed, 26 Mar 2014 10:15:53 -0400 Subject: Include my new "lspawn" module by default for spawning processes. The `textadept.run` module now uses `spawn()` instead of `io.popen()`. This module replaces the dependency on winapi. Removed experimental `io.popen()` and `os.execute()` hooks. They may be re-implemented later using `spawn()`. --- modules/textadept/run.lua | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'modules/textadept/run.lua') diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua index d7248862..15bf3c9c 100644 --- a/modules/textadept/run.lua +++ b/modules/textadept/run.lua @@ -14,8 +14,11 @@ local M = {} -- @field MARK_ERROR (number) -- The run or compile error marker number. -- @field cwd (string, Read-only) --- The most recently executed compile or run shell command's working directory. +-- The most recently executed compile or run shell command's working +-- directory. -- 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. -- @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 @@ -56,8 +59,6 @@ local function command(commands, compiling) commands[buffer:get_lexer()] if not command then return end if type(command) == 'function' then command = command() end - - preferred_view = view local filepath, filedir, filename = buffer.filename, '', buffer.filename if filepath:find('[/\\]') then filedir, filename = filepath:match('^(.+[/\\])([^/\\]+)$') @@ -67,20 +68,23 @@ local function command(commands, compiling) ['%(filepath)'] = filepath, ['%(filedir)'] = filedir, ['%(filename)'] = filename, ['%(filename_noext)'] = filename_noext, }):gsub('%%([dfe])', {d = filedir, f = filename, e = filename_noext}) - local current_dir = lfs.currentdir() - lfs.chdir(filedir) - local event = compiling and events.COMPILE_OUTPUT or events.RUN_OUTPUT + + preferred_view = view local events_emit = events.emit + local event = compiling and events.COMPILE_OUTPUT or events.RUN_OUTPUT local lexer = buffer:get_lexer() - events_emit(event, lexer, '> '..command:iconv('UTF-8', _CHARSET)) - local p = io.popen(command..' 2>&1') - for line in p:lines() do - events_emit(event, lexer, line:iconv('UTF-8', _CHARSET)) + local function emit_output(output) + events_emit(event, lexer, output:iconv('UTF-8', _CHARSET)) end - local ok, status, code = p:close() - if ok and code then events_emit(event, lexer, status..': '..code) end + + emit_output('> '..command) + ui.SILENT_PRINT = true + proc = spawn(command, filedir, emit_output, emit_output, function(status) + emit_output('> exit status: '..status) + ui.SILENT_PRINT = false + end) + M.cwd = filedir - lfs.chdir(current_dir) end -- Parses the given message for a warning or error message and returns a table @@ -168,6 +172,11 @@ M.run_commands = {actionscript=WIN32 and 'start "" "%e.swf"' or OSX and 'open "f function M.run() command(M.run_commands) end events.connect(events.RUN_OUTPUT, print_output) +--- +-- Stops the currently running process, if any. +-- @name stop +function M.stop() if proc then proc:kill() end end + --- -- List of warning and error string patterns that match various compile and run -- warnings and errors. -- cgit v1.2.3