1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
--
-- By Jeremy Hankins <nowan@nowan.org>
--
-- Time-stamp: <2005-03-06 21:10:00 nowan>
--
-- With these functions you can bind a key to start an application if
-- it's not already running, or go to it if it is. You can use it by
-- doing something like this in your bindings file:
--
-- kpress(MOD1.."C", "app.byname('xterm -title shell', 'shell')"),
-- kpress(MOD1.."T", "app.byclass('emacs', 'Emacs')"),
--
-- The byname function expects an executable and a window title, the
-- byclass expects a class.
--
-- For emacs users there's also app.emacs_eval, and app.query_editfile,
-- which interacts with any currently running emacs process (using
-- gnuclient), or starts emacs to run the given command.
-- app.query_editfile is a replacement for query_lib.query_editfile to
-- use the currently running emacs rather than ion-edit.
--
if _LOADED["app"] then return end
app={}
function app.match_class(class)
local wins = ioncore.clientwin_list()
local result = {}
for i, win in wins do
if class == win:get_ident().class then
table.insert(result, win)
end
end
return result
end
function app.byname(prog, name)
local win = ioncore.lookup_clientwin(name)
if win then
win:goto()
else
ioncore.exec(prog)
end
end
function app.byclass(prog, class)
local win = app.match_class(class)[1]
if win then
win:goto()
else
ioncore.exec(prog)
end
end
function app.emacs_eval(expr)
local emacswin = app.match_class("Emacs")[1]
if emacswin then
ioncore.exec("gnuclient -batch -eval '"..expr.."'")
emacswin:goto()
else
ioncore.exec("emacs -eval '"..expr.."'")
end
end
function app.query_editfile(mplex)
local function handler(file)
app.emacs_eval("(find-file \""..file.."\")")
end
mod_query.do_query(mplex,
'Edit file:',
mod_query.get_initdir(),
handler,
mod_query.file_completor)
end
_LOADED["app"]=true
|