Scite Run One Script

lua-users home
wiki

Select a script from a list and run it

The following script requires SciteExtMan. It uses the userlist mechanism of SciTE to display a list of script names. The user can then select one script and run it. This is useful for scripts that are not run often, and besides, this reduces the height of the Tools and the buffer tab menu. It fails silently if extman is not present.

The code below demonstrates how a user can select one of two recreational scripts (SciteElizaClassic and SciteTicTacToe.) To customize the code, simply put the appropriate information into the table AppList.

Note: Currently, SciteExtMan does not use the id parameter in order to differentiate between more than one userlists, so if you need more than one userlist, you will need to make some modifications to extman.


-----------------------------------------------------------------------
-- for global scripts; switch to "SciteUserHome" for per-user scripts
-----------------------------------------------------------------------
function loadscript(scriptfile)
  require(props["SciteDefaultHome"].."/script/"..scriptfile)
end

-----------------------------------------------------------------------
-- run selected scripts, silently fails if no extman
-----------------------------------------------------------------------
-- [[
if scite_Command then
scite_Command('Run A Script|ChooseAScript|Ctrl+9')
local AppList = {
  {"Tic Tac Toe", "SciTE_TicTacToe2.lua", "TicTacToe"},
  {"Classic Eliza", "SciTE_Classic_Eliza2.lua", "ClassicEliza"},
}
function ChooseAScript()
  local list = {}
  for i,v in ipairs(AppList) do list[i] = v[1] end
  if scite_UserListShow then
    scite_UserListShow(list, 1, RunSelectedScript)
  end
end
function RunSelectedScript(str)
  for i,v in ipairs(AppList) do
    if str == v[1] then
      loadscript(v[2]) -- change this to suit your environment
      if type(_G[v[3]]) == "function" then _G[v[3]]() end
    end
  end
end
end
--]]

--khman


This script works great. However, when I recently switched to SciTE version 1.74, it stopped working properly. Was able to get it working again by changing the line:

  require(props["SciteDefaultHome"].."/script/"..scriptfile)

to:

  dofile(props["SciteDefaultHome"].."\\scitelua\\"..scriptfile)

Note: on Linux the / is used. If you're on Windows, use \\ in it's place as I have.

Am wondering if anyone else is having this problem and if this is the best solution or if another command would be better in place of dofile. Any opinions?

I've found it a very useful script though. Thanks to the author for sharing it.


RecentChanges · preferences
edit · history
Last edited August 31, 2007 6:49 pm GMT (diff)