From 7de84ef35184bc9e180a8c2ca158974e0899f558 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Mon, 22 Jun 2009 20:25:45 -0400 Subject: Can use functions to return compile or go strings; modules/textadept/run.lua Utilize this with Java. --- modules/textadept/run.lua | 23 ++++++++++++++++++----- 1 file 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 --- -- cgit v1.2.3