aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/file_io.lua64
-rw-r--r--core/init.lua15
-rw-r--r--core/ui.lua6
-rw-r--r--doc/04_WorkingWithFiles.md7
-rw-r--r--doc/06_AdeptEditing.md13
-rw-r--r--modules/textadept/keys.lua16
-rw-r--r--modules/textadept/menu.lua2
-rw-r--r--modules/textadept/run.lua122
-rw-r--r--src/Makefile9
-rw-r--r--src/textadept.c10
10 files changed, 203 insertions, 61 deletions
diff --git a/core/file_io.lua b/core/file_io.lua
index a313cc66..6e82f66d 100644
--- a/core/file_io.lua
+++ b/core/file_io.lua
@@ -358,9 +358,46 @@ function io.open_recent_file()
if button == 1 and i then io.open_file(io.recent_files[i]) end
end
+-- List of version control directories.
+local vcs = {'.bzr', '.git', '.hg', '.svn', 'CVS'}
+
+---
+-- Returns the root directory of the project that contains filesystem path
+-- *path*.
+-- @param path Optional filesystem path to a project or a file contained within
+-- a project. The default value is the buffer's filename or the current
+-- working directory.
+-- @return string root
+-- @name get_project_root
+function io.get_project_root(path)
+ local root
+ local lfs_attributes = lfs.attributes
+ local dir = path or (buffer.filename or lfs.currentdir()):match('^(.+)[/\\]')
+ while dir do
+ for i = 1, #vcs do
+ if lfs_attributes(dir..'/'..vcs[i], 'mode') == 'directory' then
+ if vcs[i] ~= '.svn' and vcs[i] ~= 'CVS' then return dir end
+ root = dir
+ break
+ end
+ end
+ dir = dir:match('^(.+)[/\\]')
+ end
+ return root
+end
+
+---
+-- Map of file paths to filters used by `io.snapopen()`.
+-- @class table
+-- @name snapopen_filters
+-- @see snapopen
+io.snapopen_filters = {}
+
---
-- Prompts the user to select files to be opened from *paths*, a string
-- directory path or list of directory paths, using a filtered list dialog.
+-- If *paths* is `nil`, uses the current project's root directory, which is
+-- obtained from `io.get_project_root()`.
-- Files shown in the dialog do not match any pattern in either string or table
-- *filter* or, unless *exclude_FILTER* is `true`, in `lfs.FILTER`. A filter
-- table contains Lua patterns that match filenames to exclude, an optional
@@ -368,15 +405,22 @@ end
-- and an optional `extensions` sub-table that contains raw file extensions to
-- exclude. Any patterns starting with '!' exclude files and directories that do
-- not match the pattern that follows. The number of files in the list is capped
--- at `SNAPOPEN_MAX`.
+-- at `SNAPOPEN_MAX`. If *filter* is `nil` and *paths* is ultimately a string,
+-- the filter from the `io.snapopen_filters` table is used. In that case, unless
+-- explicitly specified, *exclude_FILTER* becomes `true`.
-- *opts* is an optional table of additional options for
-- `ui.dialogs.filteredlist()`.
--- @param paths String directory path or table of directory paths to search.
--- @param filter Optional filter for files and directories to exclude.
+-- @param paths Optional string directory path or table of directory paths to
+-- search. The default value is the current project's root directory, if
+-- available.
+-- @param filter Optional filter for files and directories to exclude. The
+-- default value comes from `io.snapopen_filters` if *paths* is a string.
-- @param exclude_FILTER Optional flag indicating whether or not to exclude the
-- default filter `lfs.FILTER` in the search. If `false`, adds `lfs.FILTER` to
-- *filter*.
--- The default value is `false` to include the default filter.
+-- Normally, the default value is `false` to include the default filter.
+-- However, in the instances where *filter* comes from `io.snapopen_filters`,
+-- the default value is `true`.
-- @param opts Optional table of additional options for
-- `ui.dialogs.filteredlist()`.
-- @usage io.snapopen(buffer.filename:match('^.+/')) -- list all files in the
@@ -385,12 +429,22 @@ end
-- directory
-- @usage io.snapopen('/project', {folders = {'build'}}) -- list all source
-- files in a project directory
+-- @see io.snapopen_filters
-- @see lfs.FILTER
-- @see SNAPOPEN_MAX
-- @see ui.dialogs.filteredlist
-- @name snapopen
function io.snapopen(paths, filter, exclude_FILTER, opts)
- if type(paths) == 'string' then paths = {paths} end
+ if not paths then paths = io.get_project_root() end
+ if type(paths) == 'string' then
+ if not filter then
+ filter = io.snapopen_filters[paths]
+ if filter and type(exclude_FILTER) == "nil" then
+ exclude_FILTER = filter ~= lfs.FILTER
+ end
+ end
+ paths = {paths}
+ end
local utf8_list = {}
for i = 1, #paths do
lfs.dir_foreach(paths[i], function(file)
diff --git a/core/init.lua b/core/init.lua
index df4a5e38..2d540018 100644
--- a/core/init.lua
+++ b/core/init.lua
@@ -16,6 +16,17 @@ keys = require('keys')
_M = {} -- language modules table
-- LuaJIT compatibility.
if jit then module, package.searchers, bit32 = nil, package.loaders, bit end
+-- curses compatibility.
+if CURSES then
+ function spawn(argv, working_dir, stdout_cb, stderr_cb, exit_cb)
+ local current_dir = lfs.currentdir()
+ lfs.chdir(working_dir:iconv(_CHARSET, 'UTF-8'))
+ local p = io.popen(argv:iconv(_CHARSET, 'UTF-8')..' 2>&1')
+ stdout_cb(p:read('*all'))
+ exit_cb(select(3, p:close()))
+ lfs.chdir(current_dir)
+ end
+end
--[[ This comment is for LuaDoc.
---
@@ -128,6 +139,8 @@ local timeout
---
-- Spawns an interactive child process *argv* in a separate thread with the help
-- of GLib.
+-- The terminal version spawns processes in the same thread and does not use
+-- GLib.
-- @param argv A UTF-8-encoded command line string containing the program's name
-- followed by arguments to pass to it. `PATH` is searched for program names.
-- @param working_dir The child's UTF-8 current working directory (cwd) or `nil`
@@ -136,6 +149,8 @@ local timeout
-- of standard output read from the child. Stdout is read asynchronously in
-- 1KB or 0.5KB blocks (depending on the platform), or however much data is
-- available at the time. All text is encoded in `_CHARSET`.
+-- The terminal version sends all output, whether it be stdout or stderr to
+-- this callback.
-- @param stderr_cb A Lua function that accepts a string parameter for a block
-- of standard error read from the child. Stderr is read asynchronously in 1KB
-- or 0.5kB blocks (depending on the platform), or however much data is
diff --git a/core/ui.lua b/core/ui.lua
index 6ebd28b1..3aa30855 100644
--- a/core/ui.lua
+++ b/core/ui.lua
@@ -28,7 +28,7 @@ local ui = ui
-- The default value is `true`.
-- @field SILENT_PRINT (bool)
-- Whether or not to print messages to buffers silently.
--- The default value is `false`, and focuses buffers when messages are printed
+-- The default value is `false`, and focuses buffers when messages are printed
-- to them.
module('ui')]]
@@ -94,8 +94,8 @@ ui.dialogs = setmetatable({}, {__index = function(t, k)
return function(options)
if not options.button1 then options.button1 = _L['_OK'] end
local select = options.select
- if type(select) == 'number' then
- options.select = select - 1
+ if type(select) == 'number' then
+ options.select = select - 1
elseif type(select) == 'table' then
for i = 1, #select do select[i] = select[i] - 1 end
end
diff --git a/doc/04_WorkingWithFiles.md b/doc/04_WorkingWithFiles.md
index 9ea15e84..0aba401d 100644
--- a/doc/04_WorkingWithFiles.md
+++ b/doc/04_WorkingWithFiles.md
@@ -93,9 +93,10 @@ A quicker, though slightly more limited alternative to the standard file
selection dialog is snapopen. It too behaves like the buffer browser, but
displays a list of files to open, including files in sub-directories. Pressing
`Ctrl+Alt+Shift+O` (`^⌘⇧O` on Mac OSX | `M-S-O` in curses) snaps open the
-current file's directory and `Ctrl+U` (`⌘U` | `^U`) snaps open *~/.textadept/*.
-Snapopen is pretty limited from the "Tools -> Snapopen" menu, but more versatile
-in [scripts][].
+current file's directory, `Ctrl+U` (`⌘U` | `^U`) snaps open *~/.textadept/*, and
+`Ctrl+Alt+Shift+P` (`^⌘⇧P` | `M-^P`) snaps open the current project (which must
+be under version control). Snapopen is pretty limited from the
+"Tools -> Snapopen" menu, but more versatile in [scripts][].
[scripts]: api/io.html#snapopen
diff --git a/doc/06_AdeptEditing.md b/doc/06_AdeptEditing.md
index b5e66b88..fd59b9d8 100644
--- a/doc/06_AdeptEditing.md
+++ b/doc/06_AdeptEditing.md
@@ -298,13 +298,16 @@ Pressing `Ctrl+/` (`⌘/` on Mac OSX | `M-/` in curses) comments or uncomments t
code on the selected lines. Selecting any part of a line renders the entire line
eligible for commenting or uncommenting.
-### Compile and Run
+### Compile, Run, and Build
Textadept knows most of the commands that compile and/or run code in source
-files. Pressing `Ctrl+Shift+R` (`⌘⇧R` on Mac OSX | `M-^R` in curses) executes
-the command for compiling code in the current file and `Ctrl+R` (`⌘R` | `^R`)
-executes the command for running code. A new buffer shows the output from the
-command and marks any recognized warnings and errors. Pressing `Ctrl+Alt+E`
+files. It can also sometimes detect your project's build file and run that.
+Pressing `Ctrl+Shift+R` (`⌘⇧R` on Mac OSX | `M-^R` in curses) executes the
+command for compiling code in the current file, `Ctrl+R` (`⌘R` | `^R`) executes
+the command for running code, and `Ctrl+Shift+B` (`⌘⇧B` on Mac OSX | `M-^B` in
+curses) executes the command for building a project. `Ctrl+Shift+X` (`⌘⇧X` |
+`N/A`) stops the currently running process. A new buffer shows the output from
+the command and marks any recognized warnings and errors. Pressing `Ctrl+Alt+E`
(`^⌘E` | `M-X`) attempts to jump to the source of the next recognized warning or
error and `Ctrl+Alt+Shift+E` (`^⌘⇧E` | `M-S-X`) attempts to jump to the previous
one. Double-clicking on warnings and errors also jumps to their sources. If
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
diff --git a/src/Makefile b/src/Makefile
index 563fdfe6..9521d575 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -182,11 +182,16 @@ lua_objs = lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o \
lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o \
lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \
lmathlib.o loadlib.o loslib.o ltablib.o lstrlib.o
-lua_lib_objs = lpeg.o lfs.o lspawn.o
+lua_lib_objs = lpeg.o lfs.o
#lua_lib_objs = lpcap.o lpcode.o lpprint.o lptree.o lpvm.o lfs.o
-luajit_lib_objs = lpegjit.o lfsjit.o lspawnjit.o
+luajit_lib_objs = lpegjit.o lfsjit.o
#luajit_lib_objs = lpcapjit.o lpcodejit.o lpprintjit.o lptreejit.o lpvmjit.o \
# lfsjit.o
+ifneq (curses, $(findstring curses, $(MAKECMDGOALS)))
+ # Compile in lspawn module.
+ lua_lib_objs += lspawn.o
+ luajit_lib_objs += lspawnjit.o
+endif
termkey_objs = termkey.o driver-ti.o driver-csi.o
windowman_objs = windowman.o
cdk_objs = binding.o buttonbox.o button.o cdk.o cdk_display.o cdk_objs.o \
diff --git a/src/textadept.c b/src/textadept.c
index d3d1dd67..e0c9e36f 100644
--- a/src/textadept.c
+++ b/src/textadept.c
@@ -210,7 +210,9 @@ static void new_buffer(sptr_t);
static Scintilla *new_view(sptr_t);
static int lL_init(lua_State *, int, char **, int);
LUALIB_API int luaopen_lpeg(lua_State *), luaopen_lfs(lua_State *);
+#if !CURSES
LUALIB_API int luaopen_spawn(lua_State *);
+#endif
/**
* Emits an event.
@@ -1603,7 +1605,9 @@ static int lL_init(lua_State *L, int argc, char **argv, int reinit) {
luaL_openlibs(L);
lL_openlib(L, "lpeg", luaopen_lpeg);
lL_openlib(L, "lfs", luaopen_lfs);
+#if !CURSES
lL_openlib(L, "spawn", luaopen_spawn);
+#endif
lua_newtable(L);
lua_newtable(L);
@@ -2125,11 +2129,9 @@ static Scintilla *new_view(sptr_t doc) {
SS(view, SCI_USEPOPUP, 0, 0);
lL_addview(lua, view);
l_setglobalview(lua, view);
+ if (doc) SS(view, SCI_SETDOCPOINTER, 0, doc);
focus_view(view), focused_view = view;
- if (doc) {
- SS(view, SCI_SETDOCPOINTER, 0, doc);
- l_setglobaldoc(lua, doc);
- } else new_buffer(SS(view, SCI_GETDOCPOINTER, 0, 0));
+ if (!doc) new_buffer(SS(view, SCI_GETDOCPOINTER, 0, 0));
if (!initing) lL_event(lua, "view_new", -1);
return view;
}