aboutsummaryrefslogtreecommitdiff
path: root/modules/textadept/run.lua
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2009-06-22 20:25:45 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2009-06-22 20:25:45 -0400
commit7de84ef35184bc9e180a8c2ca158974e0899f558 (patch)
tree06388253bc05a9616d3634821eb0eb7b17d884da /modules/textadept/run.lua
parenta1ca4d50bb488a4e0a3357a3a135c7433d2c64f1 (diff)
downloadtextadept-7de84ef35184bc9e180a8c2ca158974e0899f558.tar.gz
textadept-7de84ef35184bc9e180a8c2ca158974e0899f558.zip
Can use functions to return compile or go strings; modules/textadept/run.lua
Utilize this with Java.
Diffstat (limited to 'modules/textadept/run.lua')
-rw-r--r--modules/textadept/run.lua23
1 files changed, 18 insertions, 5 deletions
diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua
index 594b4657..3210adac 100644
--- a/modules/textadept/run.lua
+++ b/modules/textadept/run.lua
@@ -37,7 +37,8 @@ end
---
-- [Local table] File extensions and their associated 'compile' actions.
--- Each key is a file extension whose value is a command line string to execute.
+-- Each key is a file extension whose value is a either a command line string to
+-- execute or a function returning one.
-- @class table
-- @name compile_for_ext
local compile_for_ext = {
@@ -52,18 +53,30 @@ local compile_for_ext = {
function compile()
if not buffer.filename then return end
local action = compile_for_ext[buffer.filename:match('[^.]+$')]
- if action then execute(action) end
+ if action then execute(type(action) == 'function' and action() or action) end
end
---
-- [Local table] File extensions and their associated 'go' actions.
--- Each key is a file extension whose value is a command line string to execute.
+-- Each key is a file extension whose value is either a command line string to
+-- execute or a function returning one.
-- @class table
-- @name go_for_ext
local go_for_ext = {
c = '%(filedir)%(filename_noext)',
cpp = '%(filedir)%(filename_noext)',
- java = 'java %(filename_noext)',
+ java = function()
+ local buffer = buffer
+ local package = buffer:get_text():match('package%s+([^;]+)')
+ if package then
+ local classpath = ''
+ for dot in package:gmatch('%.') do classpath = classpath..'../' end
+ return 'java -cp '..(WIN32 and '%CLASSPATH%:' or '$CLASSPATH:')..
+ classpath..'../ '..package..'.%(filename_noext)'
+ else
+ return 'java %(filename_noext)'
+ end
+ end,
lua = 'lua %(filename)',
pl = 'perl %(filename)',
php = 'php -f %(filename)',
@@ -77,7 +90,7 @@ local go_for_ext = {
function go()
if not buffer.filename then return end
local action = go_for_ext[buffer.filename:match('[^.]+$')]
- if action then execute(action) end
+ if action then execute(type(action) == 'function' and action() or action) end
end
---