2 -- ion/query/mod_query.lua -- Some common queries for Ion
4 -- Copyright (c) Tuomo Valkonen 2004-2007.
6 -- Ion is free software; you can redistribute it and/or modify it under
7 -- the terms of the GNU Lesser General Public License as published by
8 -- the Free Software Foundation; either version 2.1 of the License, or
9 -- (at your option) any later version.
13 -- This is a slight abuse of the package.loaded variable perhaps, but
14 -- library-like packages should handle checking if they're loaded instead of
15 -- confusing the user with require/include differences.
16 if package.loaded["mod_query"] then return end
18 if not ioncore.load_module("mod_query") then
22 local mod_query=_G["mod_query"]
27 local DIE_TIMEOUT_ERRORCODE=10 -- 10 seconds
28 local DIE_TIMEOUT_NO_ERRORCODE=2 -- 2 seconds
31 -- Generic helper functions {{{
35 -- Low-level query routine. \var{mplex} is the \type{WMPlex} to display
36 -- the query in, \var{prompt} the prompt string, and \var{initvalue}
37 -- the initial contents of the query box. \var{handler} is a function
38 -- that receives (\var{mplex}, result string) as parameter when the
39 -- query has been succesfully completed, \var{completor} the completor
40 -- routine which receives a (\var{cp}, \var{str}, \var{point}) as parameters.
41 -- The parameter \var{str} is the string to be completed and \var{point}
42 -- cursor's location within it. Completions should be eventually,
43 -- possibly asynchronously, set with \fnref{WComplProxy.set_completions}
45 function mod_query.query(mplex, prompt, initvalue, handler, completor,
47 local function handle_it(str)
50 local function cycle(wedln)
51 wedln:complete('next', 'normal')
54 -- Check that no other queries are open in the mplex.
55 local ok=mplex:managed_i(function(r)
56 return not obj_is(r, "WEdln")
62 local wedln=mod_query.do_query(mplex, prompt, initvalue,
63 handle_it, completor, cycle)
65 wedln:set_context(context)
73 -- This function query will display a query with prompt \var{prompt} in
74 -- \var{mplex} and if the user answers affirmately, call \var{handler}
75 -- with \var{mplex} as parameter.
76 function mod_query.query_yesno(mplex, prompt, handler)
77 local function handler_yesno(mplex, str)
78 if str=="y" or str=="Y" or str=="yes" then
82 return mod_query.query(mplex, prompt, nil, handler_yesno, nil,
89 local function maybe_finish(pid)
92 if t and t.closed and t.dietime then
94 local tmd=os.difftime(t.dietime, t.starttime)
95 --if tmd<DIE_TIMEOUT_ERRORCODE and t.signaled then
96 -- local msg=TR("Program received signal ")..t.termsig.."\n"
97 -- mod_query.warn(t.mplex, msg..(t.errs or ""))
99 if ((tmd<DIE_TIMEOUT_ERRORCODE and (t.hadcode or t.signaled)) or
100 (tmd<DIE_TIMEOUT_NO_ERRORCODE)) and t.errs then
101 mod_query.warn(t.mplex, t.errs)
107 local badsig_={4, 5, 6, 7, 8, 11}
109 for _, v in pairs(badsig_) do
113 local function chld_handler(p)
114 local t=errdata[p.pid]
117 t.signaled=(p.signaled and badsig[p.termsig])
119 t.hadcode=(p.exited and p.exitstatus~=0)
124 ioncore.get_hook("ioncore_sigchld_hook"):add(chld_handler)
126 function mod_query.exec_on_merr(mplex, cmd)
129 local function monitor(str)
134 t.errs=(t.errs or "")..str
143 local function timeout()
147 pid=ioncore.exec_on(mplex, cmd, monitor)
153 local tmr=ioncore.create_timer();
154 local tmd=math.max(DIE_TIMEOUT_NO_ERRORCODE, DIE_TIMEOUT_ERRORCODE)
156 tmr:set(tmd*1000, timeout)
158 errdata[pid]={tmr=tmr, mplex=mplex, starttime=now}
162 function mod_query.file_completor(wedln, str)
163 local ic=ioncore.lookup_script("ion-completefile")
165 mod_query.popen_completions(wedln,
166 ic.." "..string.shell_safe(str))
171 function mod_query.get_initdir(mplex)
172 --if mod_query.last_dir then
173 -- return mod_query.last_dir
175 local wd=(ioncore.get_dir_for(mplex) or os.getenv("PWD"))
178 elseif string.sub(wd, -1)~="/" then
185 function mod_query.query_execfile(mplex, prompt, prog)
187 local function handle_execwith(mplex, str)
188 mod_query.exec_on_merr(mplex, prog.." "..string.shell_safe(str))
190 return mod_query.query(mplex, prompt, mod_query.get_initdir(mplex),
191 handle_execwith, mod_query.file_completor,
196 function mod_query.query_execwith(mplex, prompt, dflt, prog, completor,
198 local function handle_execwith(frame, str)
199 if not str or str=="" then
202 local args=(noquote and str or string.shell_safe(str))
203 mod_query.exec_on_merr(mplex, prog.." "..args)
205 return mod_query.query(mplex, prompt, nil, handle_execwith, completor,
213 -- Completion helpers {{{
217 mod_query.COLLECT_THRESHOLD=2000
220 -- This function can be used to read completions from an external source.
221 -- The parameter \var{cp} is the completion proxy to be used,
222 -- and the string \var{cmd} the shell command to be executed. To its stdout,
223 -- the command should on the first line write the \var{common_beg}
224 -- parameter of \fnref{WComplProxy.set_completions} (which \var{fn} maybe used
225 -- to override) and a single actual completion on each of the successive lines.
226 -- The function \var{reshnd} may be used to override a result table
228 function mod_query.popen_completions(cp, cmd, fn, reshnd)
230 local pst={cp=cp, maybe_stalled=0}
233 reshnd = function(rs, a)
234 if not rs.common_beg then
242 local function rcv(str)
249 if pst.maybe_stalled>=2 then
255 totallen=totallen+string.len(str)
256 if totallen>ioncore.RESULT_DATA_LIMIT then
257 error(TR("Too much result data"))
261 data=string.gsub(data..str, "([^\n]*)\n",
268 if lines>mod_query.COLLECT_THRESHOLD then
273 str=coroutine.yield()
276 if not results.common_beg then
277 results.common_beg=beg
280 (fn or WComplProxy.set_completions)(cp, results)
288 local found_clean=false
290 for k, v in pairs(pipes) do
292 if v.maybe_stalled<2 then
293 v.maybe_stalled=v.maybe_stalled+1
299 if not found_clean then
301 ioncore.popen_bgread(cmd, coroutine.wrap(rcv))
306 local function mk_completion_test(str, sub_ok, casei_ok)
308 return function(s) return true end
311 local function mk(str, sub_ok)
313 return function(s) return string.find(s, str, 1, true) end
315 local len=string.len(str)
316 return function(s) return string.sub(s, 1, len)==str end
320 local casei=(casei_ok and mod_query.get().caseicompl)
323 return mk(str, sub_ok)
325 local fn=mk(string.lower(str), sub_ok)
326 return function(s) return fn(string.lower(s)) end
331 local function mk_completion_add(entries, str, sub_ok, casei_ok)
332 local tst=mk_completion_test(str, sub_ok, casei_ok)
336 table.insert(entries, s)
342 function mod_query.complete_keys(list, str, sub_ok, casei_ok)
344 local test_add=mk_completion_add(results, str, sub_ok, casei_ok)
346 for m, _ in pairs(list) do
354 function mod_query.complete_name(str, iter)
355 local sub_ok_first=true
358 local tst_add=mk_completion_add(entries, str, sub_ok_first, casei_ok)
365 if #entries==0 and not sub_ok_first then
366 local tst_add2=mk_completion_add(entries, str, true, casei_ok)
377 function mod_query.make_completor(completefn)
378 local function completor(cp, str, point)
379 cp:set_completions(completefn(str, point))
388 -- Simple queries for internal actions {{{
391 function mod_query.call_warn(mplex, fn)
392 local err = collect_errors(fn)
394 mod_query.warn(mplex, err)
400 function mod_query.complete_clientwin(str)
401 return mod_query.complete_name(str, ioncore.clientwin_i)
405 function mod_query.complete_workspace(str)
406 local function iter(fn)
407 return ioncore.region_i(function(obj)
408 return (not obj_is(obj, "WGroupWS")
412 return mod_query.complete_name(str, iter)
416 function mod_query.complete_region(str)
417 return mod_query.complete_name(str, ioncore.region_i)
421 function mod_query.gotoclient_handler(frame, str)
422 local cwin=ioncore.lookup_clientwin(str)
425 mod_query.warn(frame, TR("Could not find client window %s.", str))
432 function mod_query.attachclient_handler(frame, str)
433 local cwin=ioncore.lookup_clientwin(str)
436 mod_query.warn(frame, TR("Could not find client window %s.", str))
440 local reg=cwin:manager()
443 if not obj_is(reg, "WGroupCW") then
449 managed = {{ reg = cwin, bottom = true }}
454 frame:attach(reg, { switchto = true })
458 if frame:rootwin_of()~=reg:rootwin_of() then
459 mod_query.warn(frame, TR("Cannot attach: different root windows."))
460 elseif reg:manager()==frame then
463 mod_query.call_warn(frame, attach)
468 function mod_query.workspace_handler(mplex, name)
469 local ws=ioncore.lookup_region(name, "WGroupWS")
473 local function create_handler(mplex_, layout)
474 if not layout or layout=="" then
478 if not ioncore.getlayout(layout) then
479 mod_query.warn(mplex_, TR("Unknown layout"))
481 local scr=mplex:screen_of()
483 local function mkws()
484 local tmpl={name=name, switchto=true}
485 if not ioncore.create_ws(scr, tmpl, layout) then
486 error(TR("Unknown error"))
490 mod_query.call_warn(mplex, mkws)
494 local function compl_layout(str)
495 local los=ioncore.getlayout(nil, true)
496 return mod_query.complete_keys(los, str, true, true)
499 mod_query.query(mplex, TR("New workspace layout (default):"), nil,
500 create_handler, mod_query.make_completor(compl_layout),
507 -- This query asks for the name of a client window and attaches
508 -- it to the frame the query was opened in. It uses the completion
509 -- function \fnref{ioncore.complete_clientwin}.
510 function mod_query.query_gotoclient(mplex)
511 mod_query.query(mplex, TR("Go to window:"), nil,
512 mod_query.gotoclient_handler,
513 mod_query.make_completor(mod_query.complete_clientwin),
518 -- This query asks for the name of a client window and switches
519 -- focus to the one entered. It uses the completion function
520 -- \fnref{ioncore.complete_clientwin}.
521 function mod_query.query_attachclient(mplex)
522 mod_query.query(mplex, TR("Attach window:"), nil,
523 mod_query.attachclient_handler,
524 mod_query.make_completor(mod_query.complete_clientwin),
530 -- This query asks for the name of a workspace. If a workspace
531 -- (an object inheriting \type{WGroupWS}) with such a name exists,
532 -- it will be switched to. Otherwise a new workspace with the
533 -- entered name will be created and the user will be queried for
534 -- the type of the workspace.
535 function mod_query.query_workspace(mplex)
536 mod_query.query(mplex, TR("Go to or create workspace:"), nil,
537 mod_query.workspace_handler,
538 mod_query.make_completor(mod_query.complete_workspace),
544 -- This query asks whether the user wants to exit Ion (no session manager)
545 -- or close the session (running under a session manager that supports such
546 -- requests). If the answer is 'y', 'Y' or 'yes', so will happen.
547 function mod_query.query_shutdown(mplex)
548 mod_query.query_yesno(mplex, TR("Exit Ion/Shutdown session (y/n)?"),
554 -- This query asks whether the user wants restart Ioncore.
555 -- If the answer is 'y', 'Y' or 'yes', so will happen.
556 function mod_query.query_restart(mplex)
557 mod_query.query_yesno(mplex, TR("Restart Ion (y/n)?"), ioncore.restart)
562 -- This function asks for a name new for the frame where the query
564 function mod_query.query_renameframe(frame)
565 mod_query.query(frame, TR("Frame name:"), frame:name(),
566 function(frame, str) frame:set_name(str) end,
572 -- This function asks for a name new for the workspace \var{ws},
573 -- or the one on which \var{mplex} resides, if it is not set.
574 -- If \var{mplex} is not set, one is looked for.
575 function mod_query.query_renameworkspace(mplex, ws)
578 mplex=ioncore.find_manager(ws, "WMPlex")
581 ws=ioncore.find_manager(mplex, "WGroupWS")
586 mod_query.query(mplex, TR("Workspace name:"), ws:name(),
587 function(mplex, str) ws:set_name(str) end,
599 -- Asks for a file to be edited. This script uses
600 -- \command{run-mailcap --mode=edit} by default, but you may provide an
601 -- alternative script to use. The default prompt is "Edit file:" (translated).
602 function mod_query.query_editfile(mplex, script, prompt)
603 mod_query.query_execfile(mplex,
604 prompt or TR("Edit file:"),
605 script or "run-mailcap --action=edit")
610 -- Asks for a file to be viewed. This script uses
611 -- \command{run-mailcap --action=view} by default, but you may provide an
612 -- alternative script to use. The default prompt is "View file:" (translated).
613 function mod_query.query_runfile(mplex, script, prompt)
614 mod_query.query_execfile(mplex,
615 prompt or TR("View file:"),
616 script or "run-mailcap --action=view")
621 local function isspace(s)
622 return string.find(s, "^%s*$")~=nil
626 local function break_cmdline(str, no_ws)
627 local st, en, beg, rest, ch, rem
630 local function ins(str)
632 if string.find(res[n], "^%s+$") then
633 table.insert(res, str)
639 local function ins_space(str)
643 table.insert(res, "")
646 if isspace(res[n]) then
649 table.insert(res, str)
654 -- Handle terminal startup syntax
655 st, en, beg, ch, rest=string.find(str, "^(%s*)(:+)(.*)")
657 if string.len(beg)>0 then
666 st, en, beg, rest, ch=string.find(str, "^(.-)(([%s'\"\\|])(.*))")
678 st, en, beg, rest=string.find(str, "^(\\.)(.*)")
680 st, en, beg, rest=string.find(str, "^(\".-[^\\]\")(.*)")
683 st, en, beg, rest=string.find(str, "^(\"\")(.*)")
686 st, en, beg, rest=string.find(str, "^('.-')(.*)")
694 st, en, beg, rest=string.find(str, "^.(%s*)(.*)")
715 local function unquote(str)
716 str=string.gsub(str, "^['\"]", "")
717 str=string.gsub(str, "([^\\])['\"]", "%1")
718 str=string.gsub(str, "\\(.)", "%1")
723 local function quote(str)
724 return string.gsub(str, "([%(%)\"'\\%*%?%[%]%| ])", "\\%1")
728 local function find_point(strs, point)
729 for i, s in ipairs(strs) do
730 point=point-string.len(s)
739 function mod_query.exec_completor(wedln, str, point)
740 local parts=break_cmdline(str)
741 local complidx=find_point(parts, point+1)
743 local s_compl, s_beg, s_end="", "", ""
745 if complidx==1 and string.find(parts[1], "^:+$") then
749 if string.find(parts[complidx], "[^%s]") then
750 s_compl=unquote(parts[complidx])
753 for i=1, complidx-1 do
754 s_beg=s_beg..parts[i]
757 for i=complidx+1, #parts do
758 s_end=s_end..parts[i]
762 if complidx==1 or (complidx==2 and isspace(parts[1])) then
764 elseif string.find(parts[1], "^:+$") then
767 elseif string.find(parts[2], "^%s*$") then
774 local function set_fn(cp, res)
775 res=table.map(quote, res)
776 res.common_beg=s_beg..(res.common_beg or "")
777 res.common_end=(res.common_end or "")..s_end
778 cp:set_completions(res)
781 local function filter_fn(res, s)
782 if not res.common_beg then
793 local ic=ioncore.lookup_script("ion-completefile")
795 mod_query.popen_completions(wedln,
796 ic..wp..string.shell_safe(s_compl),
802 local cmd_overrides={}
806 -- Define a command override for the \fnrefx{mod_query}{query_exec} query.
807 function mod_query.defcmd(cmd, fn)
808 cmd_overrides[cmd]=fn
812 function mod_query.exec_handler(mplex, cmdline)
813 local parts=break_cmdline(cmdline, true)
814 local cmd=table.remove(parts, 1)
816 if cmd_overrides[cmd] then
817 cmd_overrides[cmd](mplex, table.map(unquote, parts))
819 mod_query.exec_on_merr(mplex, cmdline)
825 -- This function asks for a command to execute with \file{/bin/sh}.
826 -- If the command is prefixed with a colon (':'), the command will
827 -- be run in an XTerm (or other terminal emulator) using the script
828 -- \file{ion-runinxterm}. Two colons ('::') will ask you to press
829 -- enter after the command has finished.
830 function mod_query.query_exec(mplex)
831 mod_query.query(mplex, TR("Run:"), nil, mod_query.exec_handler,
832 mod_query.exec_completor,
843 mod_query.known_hosts={}
844 mod_query.hostnicks={}
845 mod_query.ssh_completions={}
848 function mod_query.get_known_hosts(mplex)
849 mod_query.known_hosts={}
851 local h=os.getenv("HOME")
853 f=io.open(h.."/.ssh/known_hosts")
856 warn(TR("Failed to open ~/.ssh/known_hosts"))
859 for l in f:lines() do
860 local st, en, hostname=string.find(l, "^([^%s,]+)")
862 table.insert(mod_query.known_hosts, hostname)
869 function mod_query.get_hostnicks(mplex)
870 mod_query.hostnicks={}
872 local substr, pat, patterns
873 local h=os.getenv("HOME")
876 f=io.open(h.."/.ssh/config")
879 warn(TR("Failed to open ~/.ssh/config"))
883 for l in f:lines() do
884 _, _, substr=string.find(l, "^%s*[hH][oO][sS][tT](.*)")
886 _, _, pat=string.find(substr, "^%s*[=%s]%s*(%S.*)")
889 elseif string.find(substr, "^[nN][aA][mM][eE]")
891 for s in string.gfind(patterns, "%S+") do
892 if not string.find(s, "[*?]") then
893 table.insert(mod_query.hostnicks, s)
903 function mod_query.complete_ssh(str)
904 local st, en, user, at, host=string.find(str, "^([^@]*)(@?)(.*)$")
906 if string.len(at)==0 and string.len(host)==0 then
907 host = user; user = ""
915 local tst = mk_completion_test(host, true, false)
917 for _, v in ipairs(mod_query.ssh_completions) do
919 table.insert(res, user .. v)
928 -- This query asks for a host to connect to with SSH.
929 -- Hosts to tab-complete are read from \file{\~{}/.ssh/known\_hosts}.
930 function mod_query.query_ssh(mplex, ssh)
931 mod_query.get_known_hosts(mplex)
932 mod_query.get_hostnicks(mplex)
934 for _, v in ipairs(mod_query.known_hosts) do
935 table.insert(mod_query.ssh_completions, v)
937 for _, v in ipairs(mod_query.hostnicks) do
938 table.insert(mod_query.ssh_completions, v)
943 local function handle_exec(mplex, str)
944 if not (str and string.find(str, "[^%s]")) then
948 mod_query.exec_on_merr(mplex, ssh.." "..string.shell_safe(str))
951 return mod_query.query(mplex, TR("SSH to:"), nil, handle_exec,
952 mod_query.make_completor(mod_query.complete_ssh),
962 function mod_query.man_completor(wedln, str)
963 local mc=ioncore.lookup_script("ion-completeman")
965 mod_query.popen_completions(wedln, (mc.." -complete "
966 ..string.shell_safe(str)))
972 -- This query asks for a manual page to display. By default it runs the
973 -- \command{man} command in an \command{xterm} using \command{ion-runinxterm},
974 -- but it is possible to pass another program as the \var{prog} argument.
975 function mod_query.query_man(mplex, prog)
976 local dflt=ioncore.progname()
977 mod_query.query_execwith(mplex, TR("Manual page (%s):", dflt),
978 dflt, prog or ":man",
979 mod_query.man_completor, "man",
980 true --[[ no quoting ]])
987 -- Lua code execution {{{
990 function mod_query.create_run_env(mplex)
991 local origenv=getfenv()
992 local meta={__index=origenv, __newindex=origenv}
995 _sub=mplex:current(),
998 setmetatable(env, meta)
1002 function mod_query.do_handle_lua(mplex, env, code)
1004 local function collect_print(...)
1008 tmp=tmp..tostring(arg[i])..(i==l and "\n" or "\t")
1010 print_res=(print_res and print_res..tmp or tmp)
1013 local f, err=loadstring(code)
1015 mod_query.warn(mplex, err)
1019 env.print=collect_print
1022 err=collect_errors(f)
1024 mod_query.warn(mplex, err)
1025 elseif print_res then
1026 mod_query.message(mplex, print_res)
1030 local function getindex(t)
1031 local mt=getmetatable(t)
1032 if mt then return mt.__index end
1036 function mod_query.do_complete_lua(env, str)
1037 -- Get the variable to complete, including containing tables.
1038 -- This will also match string concatenations and such because
1039 -- Lua's regexps don't support optional subexpressions, but we
1040 -- handle them in the next step.
1043 local _, _, tocomp=string.find(str, "([%w_.:]*)$")
1045 -- Descend into tables
1046 if tocomp and string.len(tocomp)>=1 then
1047 for t in string.gfind(tocomp, "([^.:]*)[.:]") do
1049 if string.len(t)==0 then
1052 if type(comptab[t])=="table" then
1054 elseif type(comptab[t])=="userdata" then
1055 comptab=getindex(comptab[t])
1064 if not comptab then return {} end
1068 -- Get the actual variable to complete without containing tables
1069 _, _, compl.common_beg, tocomp=string.find(str, "(.-)([%w_]*)$")
1071 local l=string.len(tocomp)
1076 if type(tab) == "table" then
1077 for k in pairs(tab) do
1078 if type(k)=="string" then
1079 if string.sub(k, 1, l)==tocomp then
1080 table.insert(compl, k)
1086 -- We only want to display full list of functions for objects, not
1087 -- the tables representing the classes.
1088 --if not metas then break end
1092 if not tab or seen[tab] then break end
1095 -- If there was only one completion and it is a string or function,
1096 -- concatenate it with "." or "(", respectively.
1098 if type(comptab[compl[1]])=="table" then
1099 compl[1]=compl[1] .. "."
1100 elseif type(comptab[compl[1]])=="function" then
1101 compl[1]=compl[1] .. "("
1110 -- This query asks for Lua code to execute. It sets the variable '\var{\_}'
1111 -- in the local environment of the string to point to the mplex where the
1112 -- query was created. It also sets the table \var{arg} in the local
1113 -- environment to \code{\{_, _:current()\}}.
1114 function mod_query.query_lua(mplex)
1115 local env=mod_query.create_run_env(mplex)
1117 local function complete(cp, code)
1118 cp:set_completions(mod_query.do_complete_lua(env, code))
1121 local function handler(mplex, code)
1122 return mod_query.do_handle_lua(mplex, env, code)
1125 mod_query.query(mplex, TR("Lua code:"), nil, handler, complete, "lua")
1134 -- This query can be used to create a query of a defined menu.
1135 function mod_query.query_menu(mplex, themenu, prompt)
1136 local _sub=mplex:current()
1137 local menu=ioncore.evalmenu(themenu, {mplex, _sub})
1138 local menuname=(type(themenu)=="string" and themenu or "?")
1141 mod_query.warn(mplex, TR("Unknown menu %s.", tostring(themenu)))
1146 prompt=menuname..":"
1151 local function xform_name(n, is_submenu)
1152 return (string.lower(string.gsub(n, "[-/%s]+", "-"))
1153 ..(is_submenu and "/" or ""))
1156 local function xform_menu(t, m, p)
1157 for _, v in ipairs(m) do
1159 local is_submenu=v.submenu_fn
1160 local n=p..xform_name(v.name, is_submenu)
1165 if is_submenu and not v.noautoexpand then
1166 local sm=v.submenu_fn()
1168 xform_menu(t, sm, n)
1170 ioncore.warn_traced(TR("Missing submenu ")
1179 local ntab=xform_menu({}, menu, "")
1181 local function complete(str)
1182 -- casei_ok false, because everything is already in lower case
1183 return mod_query.complete_keys(ntab, str, true, false)
1186 local function handle(mplex, str)
1190 local err=collect_errors(function()
1194 mod_query.warn(mplex, err)
1196 elseif e.submenu_fn then
1197 mod_query.query_menu(mplex, e.submenu_fn(),
1201 mod_query.warn(mplex, TR("No entry '%s'", str))
1205 mod_query.query(mplex, prompt, nil, handle,
1206 mod_query.make_completor(complete), "menu."..menuname)
1212 -- Miscellaneous {{{
1216 -- Display an "About Ion" message in \var{mplex}.
1217 function mod_query.show_about_ion(mplex)
1218 mod_query.message(mplex, ioncore.aboutmsg())
1223 -- Show information about a region tree
1224 function mod_query.show_tree(mplex, reg, max_depth)
1225 local function indent(s)
1227 return i..string.gsub(s, "\n", "\n"..i)
1230 local function get_info(reg, indent, d)
1232 return (indent .. "No region")
1235 local function n(s) return (s or "") end
1237 local s=string.format("%s%s \"%s\"", indent, obj_typename(reg),
1239 indent = indent .. " "
1240 if obj_is(reg, "WClientWin") then
1241 local i=reg:get_ident()
1242 s=s .. TR("\n%sClass: %s\n%sRole: %s\n%sInstance: %s\n%sXID: 0x%x",
1245 indent, n(i.instance),
1249 if (not max_depth or max_depth > d) and reg.managed_i then
1251 reg:managed_i(function(sub)
1253 s=s .. "\n" .. indent .. "---"
1256 s=s .. "\n" .. get_info(sub, indent, d+1)
1264 mod_query.message(mplex, get_info(reg, "", 0))
1270 dopath('mod_query_chdir')
1272 -- Mark ourselves loaded.
1273 package.loaded["mod_query"]=true
1276 -- Load configuration file
1277 dopath('cfg_query', true)