From bc763f8042a55ed87eb733fa79cf9abfc2ac6fd6 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Sat, 16 Apr 2016 21:10:50 -0400 Subject: Added menu item and dialog for setting run/compile command arguments. --- modules/textadept/menu.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'modules/textadept/menu.lua') diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index 91a0d60a..4e7cc785 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -173,6 +173,33 @@ local default_menubar = { SEPARATOR, {_L['_Run'], textadept.run.run}, {_L['_Compile'], textadept.run.compile}, + {_L['Set _Arguments...'], function() + if not buffer.filename then return end + local run_commands = textadept.run.run_commands + local compile_commands = textadept.run.compile_commands + local base_commands, utf8_args = {}, {} + for i, commands in ipairs{run_commands, compile_commands} do + -- Compare the base run/compile command with the one for the current + -- file. The difference is any additional arguments set previously. + base_commands[i] = commands[buffer.filename:match('[^.]+$')] or + commands[buffer:get_lexer()] + local current_command = (commands[buffer.filename] or '') + local args = current_command:sub(#base_commands[i] + 2) + utf8_args[i] = args:iconv('UTF-8', _CHARSET) + end + local button, utf8_args = ui.dialogs.inputbox{ + title = _L['Set _Arguments...']:gsub('_', ''), informative_text = { + _L['Command line arguments'], _L['For Run:'], _L['For Compile:'] + }, text = utf8_args, width = not CURSES and 400 or nil + } + if button ~= 1 then return end + for i, commands in ipairs{run_commands, compile_commands} do + -- Add the additional arguments to the base run/compile command and set + -- the new command to be the one used for the current file. + commands[buffer.filename] = base_commands[i]..' '.. + utf8_args[i]:iconv(_CHARSET, 'UTF-8') + end + end}, {_L['Buil_d'], textadept.run.build}, {_L['S_top'], textadept.run.stop}, {_L['_Next Error'], function() textadept.run.goto_error(false, true) end}, -- cgit v1.2.3