2 -- ion/query/mod_query.lua -- Some common queries for Ion
4 -- Copyright (c) Tuomo Valkonen 2004-2007.
6 -- See the included file LICENSE for details.
10 -- This is a slight abuse of the package.loaded variable perhaps, but
11 -- library-like packages should handle checking if they're loaded instead of
12 -- confusing the user with require/include differences.
13 if package.loaded["mod_query"] then return end
15 if not ioncore.load_module("mod_query") then
19 local mod_query=_G["mod_query"]
24 local DIE_TIMEOUT_ERRORCODE=10 -- 10 seconds
25 local DIE_TIMEOUT_NO_ERRORCODE=2 -- 2 seconds
28 -- Generic helper functions {{{
32 -- Display an error message box in the multiplexer \var{mplex}.
33 function mod_query.warn(mplex, str)
34 ioncore.unsqueeze(mod_query.do_warn(mplex, str))
39 -- Display a message in \var{mplex}.
40 function mod_query.message(mplex, str)
41 ioncore.unsqueeze(mod_query.do_message(mplex, str))
46 -- Low-level query routine. \var{mplex} is the \type{WMPlex} to display
47 -- the query in, \var{prompt} the prompt string, and \var{initvalue}
48 -- the initial contents of the query box. \var{handler} is a function
49 -- that receives (\var{mplex}, result string) as parameter when the
50 -- query has been succesfully completed, \var{completor} the completor
51 -- routine which receives a (\var{cp}, \var{str}, \var{point}) as parameters.
52 -- The parameter \var{str} is the string to be completed and \var{point}
53 -- cursor's location within it. Completions should be eventually,
54 -- possibly asynchronously, set with \fnref{WComplProxy.set_completions}
56 function mod_query.query(mplex, prompt, initvalue, handler, completor,
58 local function handle_it(str)
61 local function cycle(wedln)
62 wedln:complete('next', 'normal')
64 local function bcycle(wedln)
65 wedln:complete('prev', 'normal')
68 -- Check that no other queries are open in the mplex.
69 local ok=mplex:managed_i(function(r)
70 return not obj_is(r, "WEdln")
76 local wedln=mod_query.do_query(mplex, prompt, initvalue,
77 handle_it, completor, cycle, bcycle)
80 ioncore.unsqueeze(wedln)
83 wedln:set_context(context)
92 -- This function query will display a query with prompt \var{prompt} in
93 -- \var{mplex} and if the user answers affirmately, call \var{handler}
94 -- with \var{mplex} as parameter.
95 function mod_query.query_yesno(mplex, prompt, handler)
96 local function handler_yesno(mplex, str)
97 if str=="y" or str=="Y" or str=="yes" then
101 return mod_query.query(mplex, prompt, nil, handler_yesno, nil,
108 local function maybe_finish(pid)
111 if t and t.closed and t.dietime then
113 local tmd=os.difftime(t.dietime, t.starttime)
114 --if tmd<DIE_TIMEOUT_ERRORCODE and t.signaled then
115 -- local msg=TR("Program received signal ")..t.termsig.."\n"
116 -- mod_query.warn(t.mplex, msg..(t.errs or ""))
118 if ((tmd<DIE_TIMEOUT_ERRORCODE and (t.hadcode or t.signaled)) or
119 (tmd<DIE_TIMEOUT_NO_ERRORCODE)) and t.errs then
120 mod_query.warn(t.mplex, t.errs)
126 local badsig_={4, 5, 6, 7, 8, 11}
128 for _, v in pairs(badsig_) do
132 local function chld_handler(p)
133 local t=errdata[p.pid]
136 t.signaled=(p.signaled and badsig[p.termsig])
138 t.hadcode=(p.exited and p.exitstatus~=0)
143 ioncore.get_hook("ioncore_sigchld_hook"):add(chld_handler)
145 function mod_query.exec_on_merr(mplex, cmd)
148 local function monitor(str)
153 t.errs=(t.errs or "")..str
162 local function timeout()
166 pid=ioncore.exec_on(mplex, cmd, monitor)
172 local tmr=ioncore.create_timer();
173 local tmd=math.max(DIE_TIMEOUT_NO_ERRORCODE, DIE_TIMEOUT_ERRORCODE)
175 tmr:set(tmd*1000, timeout)
177 errdata[pid]={tmr=tmr, mplex=mplex, starttime=now}
181 function mod_query.file_completor(wedln, str)
182 local ic=ioncore.lookup_script("ion-completefile")
184 mod_query.popen_completions(wedln,
185 ic.." "..string.shell_safe(str))
190 function mod_query.get_initdir(mplex)
191 --if mod_query.last_dir then
192 -- return mod_query.last_dir
194 local wd=(ioncore.get_dir_for(mplex) or os.getenv("PWD"))
197 elseif string.sub(wd, -1)~="/" then
204 function mod_query.query_execfile(mplex, prompt, prog)
206 local function handle_execwith(mplex, str)
207 mod_query.exec_on_merr(mplex, prog.." "..string.shell_safe(str))
209 return mod_query.query(mplex, prompt, mod_query.get_initdir(mplex),
210 handle_execwith, mod_query.file_completor,
215 function mod_query.query_execwith(mplex, prompt, dflt, prog, completor,
217 local function handle_execwith(frame, str)
218 if not str or str=="" then
221 local args=(noquote and str or string.shell_safe(str))
222 mod_query.exec_on_merr(mplex, prog.." "..args)
224 return mod_query.query(mplex, prompt, nil, handle_execwith, completor,
232 -- Completion helpers {{{
236 mod_query.COLLECT_THRESHOLD=2000
239 -- This function can be used to read completions from an external source.
240 -- The parameter \var{cp} is the completion proxy to be used,
241 -- and the string \var{cmd} the shell command to be executed. To its stdout,
242 -- the command should on the first line write the \var{common_beg}
243 -- parameter of \fnref{WComplProxy.set_completions} (which \var{fn} maybe used
244 -- to override) and a single actual completion on each of the successive lines.
245 -- The function \var{reshnd} may be used to override a result table
247 function mod_query.popen_completions(cp, cmd, fn, reshnd)
249 local pst={cp=cp, maybe_stalled=0}
252 reshnd = function(rs, a)
253 if not rs.common_beg then
261 local function rcv(str)
268 if pst.maybe_stalled>=2 then
274 totallen=totallen+string.len(str)
275 if totallen>ioncore.RESULT_DATA_LIMIT then
276 error(TR("Too much result data"))
280 data=string.gsub(data..str, "([^\n]*)\n",
287 if lines>mod_query.COLLECT_THRESHOLD then
292 str=coroutine.yield()
295 if not results.common_beg then
296 results.common_beg=beg
299 (fn or WComplProxy.set_completions)(cp, results)
307 local found_clean=false
309 for k, v in pairs(pipes) do
311 if v.maybe_stalled<2 then
312 v.maybe_stalled=v.maybe_stalled+1
318 if not found_clean then
320 ioncore.popen_bgread(cmd, coroutine.wrap(rcv))
325 local function mk_completion_test(str, sub_ok, casei_ok)
327 return function(s) return true end
330 local function mk(str, sub_ok)
332 return function(s) return string.find(s, str, 1, true) end
334 local len=string.len(str)
335 return function(s) return string.sub(s, 1, len)==str end
339 local casei=(casei_ok and mod_query.get().caseicompl)
342 return mk(str, sub_ok)
344 local fn=mk(string.lower(str), sub_ok)
345 return function(s) return fn(string.lower(s)) end
350 local function mk_completion_add(entries, str, sub_ok, casei_ok)
351 local tst=mk_completion_test(str, sub_ok, casei_ok)
355 table.insert(entries, s)
361 function mod_query.complete_keys(list, str, sub_ok, casei_ok)
363 local test_add=mk_completion_add(results, str, sub_ok, casei_ok)
365 for m, _ in pairs(list) do
373 function mod_query.complete_name(str, iter)
374 local sub_ok_first=true
377 local tst_add=mk_completion_add(entries, str, sub_ok_first, casei_ok)
384 if #entries==0 and not sub_ok_first then
385 local tst_add2=mk_completion_add(entries, str, true, casei_ok)
396 function mod_query.make_completor(completefn)
397 local function completor(cp, str, point)
398 cp:set_completions(completefn(str, point))
407 -- Simple queries for internal actions {{{
410 function mod_query.call_warn(mplex, fn)
411 local err = collect_errors(fn)
413 mod_query.warn(mplex, err)
419 function mod_query.complete_clientwin(str)
420 return mod_query.complete_name(str, ioncore.clientwin_i)
424 function mod_query.complete_workspace(str)
425 local function iter(fn)
426 return ioncore.region_i(function(obj)
427 return (not obj_is(obj, "WGroupWS")
431 return mod_query.complete_name(str, iter)
435 function mod_query.complete_region(str)
436 return mod_query.complete_name(str, ioncore.region_i)
440 function mod_query.gotoclient_handler(frame, str)
441 local cwin=ioncore.lookup_clientwin(str)
444 mod_query.warn(frame, TR("Could not find client window %s.", str))
451 function mod_query.attachclient_handler(frame, str)
452 local cwin=ioncore.lookup_clientwin(str)
455 mod_query.warn(frame, TR("Could not find client window %s.", str))
459 local reg=cwin:groupleader_of()
461 local function attach()
462 frame:attach(reg, { switchto = true })
465 if frame:rootwin_of()~=reg:rootwin_of() then
466 mod_query.warn(frame, TR("Cannot attach: different root windows."))
467 elseif reg:manager()==frame then
470 mod_query.call_warn(frame, attach)
475 function mod_query.workspace_handler(mplex, name)
476 local ws=ioncore.lookup_region(name, "WGroupWS")
480 local function create_handler(mplex_, layout)
481 if not layout or layout=="" then
485 if not ioncore.getlayout(layout) then
486 mod_query.warn(mplex_, TR("Unknown layout"))
488 local scr=mplex:screen_of()
490 local function mkws()
491 local tmpl={name=name, switchto=true}
492 if not ioncore.create_ws(scr, tmpl, layout) then
493 error(TR("Unknown error"))
497 mod_query.call_warn(mplex, mkws)
501 local function compl_layout(str)
502 local los=ioncore.getlayout(nil, true)
503 return mod_query.complete_keys(los, str, true, true)
506 mod_query.query(mplex, TR("New workspace layout (default):"), nil,
507 create_handler, mod_query.make_completor(compl_layout),
514 -- This query asks for the name of a client window and switches
515 -- focus to the one entered. It uses the completion function
516 -- \fnref{ioncore.complete_clientwin}.
517 function mod_query.query_gotoclient(mplex)
518 mod_query.query(mplex, TR("Go to window:"), nil,
519 mod_query.gotoclient_handler,
520 mod_query.make_completor(mod_query.complete_clientwin),
525 -- This query asks for the name of a client window and attaches
526 -- it to the frame the query was opened in. It uses the completion
527 -- function \fnref{ioncore.complete_clientwin}.
528 function mod_query.query_attachclient(mplex)
529 mod_query.query(mplex, TR("Attach window:"), nil,
530 mod_query.attachclient_handler,
531 mod_query.make_completor(mod_query.complete_clientwin),
537 -- This query asks for the name of a workspace. If a workspace
538 -- (an object inheriting \type{WGroupWS}) with such a name exists,
539 -- it will be switched to. Otherwise a new workspace with the
540 -- entered name will be created and the user will be queried for
541 -- the type of the workspace.
542 function mod_query.query_workspace(mplex)
543 mod_query.query(mplex, TR("Go to or create workspace:"), nil,
544 mod_query.workspace_handler,
545 mod_query.make_completor(mod_query.complete_workspace),
551 -- This query asks whether the user wants to exit Ion (no session manager)
552 -- or close the session (running under a session manager that supports such
553 -- requests). If the answer is 'y', 'Y' or 'yes', so will happen.
554 function mod_query.query_shutdown(mplex)
555 mod_query.query_yesno(mplex, TR("Exit Ion/Shutdown session (y/n)?"),
561 -- This query asks whether the user wants restart Ioncore.
562 -- If the answer is 'y', 'Y' or 'yes', so will happen.
563 function mod_query.query_restart(mplex)
564 mod_query.query_yesno(mplex, TR("Restart Ion (y/n)?"), ioncore.restart)
569 -- This function asks for a name new for the frame where the query
571 function mod_query.query_renameframe(frame)
572 mod_query.query(frame, TR("Frame name:"), frame:name(),
573 function(frame, str) frame:set_name(str) end,
579 -- This function asks for a name new for the workspace \var{ws},
580 -- or the one on which \var{mplex} resides, if it is not set.
581 -- If \var{mplex} is not set, one is looked for.
582 function mod_query.query_renameworkspace(mplex, ws)
585 mplex=ioncore.find_manager(ws, "WMPlex")
588 ws=ioncore.find_manager(mplex, "WGroupWS")
593 mod_query.query(mplex, TR("Workspace name:"), ws:name(),
594 function(mplex, str) ws:set_name(str) end,
606 -- Asks for a file to be edited. This script uses
607 -- \command{run-mailcap --mode=edit} by default, but you may provide an
608 -- alternative script to use. The default prompt is "Edit file:" (translated).
609 function mod_query.query_editfile(mplex, script, prompt)
610 mod_query.query_execfile(mplex,
611 prompt or TR("Edit file:"),
612 script or "run-mailcap --action=edit")
617 -- Asks for a file to be viewed. This script uses
618 -- \command{run-mailcap --action=view} by default, but you may provide an
619 -- alternative script to use. The default prompt is "View file:" (translated).
620 function mod_query.query_runfile(mplex, script, prompt)
621 mod_query.query_execfile(mplex,
622 prompt or TR("View file:"),
623 script or "run-mailcap --action=view")
628 local function isspace(s)
629 return string.find(s, "^%s*$")~=nil
633 local function break_cmdline(str, no_ws)
634 local st, en, beg, rest, ch, rem
637 local function ins(str)
639 if string.find(res[n], "^%s+$") then
640 table.insert(res, str)
646 local function ins_space(str)
650 table.insert(res, "")
653 if isspace(res[n]) then
656 table.insert(res, str)
661 -- Handle terminal startup syntax
662 st, en, beg, ch, rest=string.find(str, "^(%s*)(:+)(.*)")
664 if string.len(beg)>0 then
673 st, en, beg, rest, ch=string.find(str, "^(.-)(([%s'\"\\|])(.*))")
685 st, en, beg, rest=string.find(str, "^(\\.)(.*)")
687 st, en, beg, rest=string.find(str, "^(\".-[^\\]\")(.*)")
690 st, en, beg, rest=string.find(str, "^(\"\")(.*)")
693 st, en, beg, rest=string.find(str, "^('.-')(.*)")
701 st, en, beg, rest=string.find(str, "^.(%s*)(.*)")
722 local function unquote(str)
723 str=string.gsub(str, "^['\"]", "")
724 str=string.gsub(str, "([^\\])['\"]", "%1")
725 str=string.gsub(str, "\\(.)", "%1")
730 local function quote(str)
731 return string.gsub(str, "([%(%)\"'\\%*%?%[%]%| ])", "\\%1")
735 local function find_point(strs, point)
736 for i, s in ipairs(strs) do
737 point=point-string.len(s)
746 function mod_query.exec_completor(wedln, str, point)
747 local parts=break_cmdline(str)
748 local complidx=find_point(parts, point+1)
750 local s_compl, s_beg, s_end="", "", ""
752 if complidx==1 and string.find(parts[1], "^:+$") then
756 if string.find(parts[complidx], "[^%s]") then
757 s_compl=unquote(parts[complidx])
760 for i=1, complidx-1 do
761 s_beg=s_beg..parts[i]
764 for i=complidx+1, #parts do
765 s_end=s_end..parts[i]
769 if complidx==1 or (complidx==2 and isspace(parts[1])) then
771 elseif string.find(parts[1], "^:+$") then
774 elseif string.find(parts[2], "^%s*$") then
781 local function set_fn(cp, res)
782 res=table.map(quote, res)
783 res.common_beg=s_beg..(res.common_beg or "")
784 res.common_end=(res.common_end or "")..s_end
785 cp:set_completions(res)
788 local function filter_fn(res, s)
789 if not res.common_beg then
800 local ic=ioncore.lookup_script("ion-completefile")
802 mod_query.popen_completions(wedln,
803 ic..wp..string.shell_safe(s_compl),
809 local cmd_overrides={}
813 -- Define a command override for the \fnrefx{mod_query}{query_exec} query.
814 function mod_query.defcmd(cmd, fn)
815 cmd_overrides[cmd]=fn
819 function mod_query.exec_handler(mplex, cmdline)
820 local parts=break_cmdline(cmdline, true)
821 local cmd=table.remove(parts, 1)
823 if cmd_overrides[cmd] then
824 cmd_overrides[cmd](mplex, table.map(unquote, parts))
826 mod_query.exec_on_merr(mplex, cmdline)
832 -- This function asks for a command to execute with \file{/bin/sh}.
833 -- If the command is prefixed with a colon (':'), the command will
834 -- be run in an XTerm (or other terminal emulator) using the script
835 -- \file{ion-runinxterm}. Two colons ('::') will ask you to press
836 -- enter after the command has finished.
837 function mod_query.query_exec(mplex)
838 mod_query.query(mplex, TR("Run:"), nil, mod_query.exec_handler,
839 mod_query.exec_completor,
850 mod_query.known_hosts={}
851 mod_query.hostnicks={}
852 mod_query.ssh_completions={}
855 function mod_query.get_known_hosts(mplex)
856 mod_query.known_hosts={}
858 local h=os.getenv("HOME")
860 f=io.open(h.."/.ssh/known_hosts")
863 warn(TR("Failed to open ~/.ssh/known_hosts"))
866 for l in f:lines() do
867 local st, en, hostname=string.find(l, "^([^%s,]+)")
869 table.insert(mod_query.known_hosts, hostname)
876 function mod_query.get_hostnicks(mplex)
877 mod_query.hostnicks={}
879 local substr, pat, patterns
880 local h=os.getenv("HOME")
883 f=io.open(h.."/.ssh/config")
886 warn(TR("Failed to open ~/.ssh/config"))
890 for l in f:lines() do
891 _, _, substr=string.find(l, "^%s*[hH][oO][sS][tT](.*)")
893 _, _, pat=string.find(substr, "^%s*[=%s]%s*(%S.*)")
896 elseif string.find(substr, "^[nN][aA][mM][eE]")
898 for s in string.gfind(patterns, "%S+") do
899 if not string.find(s, "[*?]") then
900 table.insert(mod_query.hostnicks, s)
910 function mod_query.complete_ssh(str)
911 local st, en, user, at, host=string.find(str, "^([^@]*)(@?)(.*)$")
913 if string.len(at)==0 and string.len(host)==0 then
914 host = user; user = ""
922 local tst = mk_completion_test(host, true, false)
924 for _, v in ipairs(mod_query.ssh_completions) do
926 table.insert(res, user .. v)
935 -- This query asks for a host to connect to with SSH.
936 -- Hosts to tab-complete are read from \file{\~{}/.ssh/known\_hosts}.
937 function mod_query.query_ssh(mplex, ssh)
938 mod_query.get_known_hosts(mplex)
939 mod_query.get_hostnicks(mplex)
941 for _, v in ipairs(mod_query.known_hosts) do
942 table.insert(mod_query.ssh_completions, v)
944 for _, v in ipairs(mod_query.hostnicks) do
945 table.insert(mod_query.ssh_completions, v)
950 local function handle_exec(mplex, str)
951 if not (str and string.find(str, "[^%s]")) then
955 mod_query.exec_on_merr(mplex, ssh.." "..string.shell_safe(str))
958 return mod_query.query(mplex, TR("SSH to:"), nil, handle_exec,
959 mod_query.make_completor(mod_query.complete_ssh),
969 function mod_query.man_completor(wedln, str)
970 local mc=ioncore.lookup_script("ion-completeman")
971 local icase=(mod_query.get().caseicompl and " -icase" or "")
974 mod_query.popen_completions(wedln, (mc..icase..mid.." -complete "
975 ..string.shell_safe(str)))
981 -- This query asks for a manual page to display. By default it runs the
982 -- \command{man} command in an \command{xterm} using \command{ion-runinxterm},
983 -- but it is possible to pass another program as the \var{prog} argument.
984 function mod_query.query_man(mplex, prog)
985 local dflt=ioncore.progname()
986 mod_query.query_execwith(mplex, TR("Manual page (%s):", dflt),
987 dflt, prog or ":man",
988 mod_query.man_completor, "man",
989 true --[[ no quoting ]])
996 -- Lua code execution {{{
999 function mod_query.create_run_env(mplex)
1000 local origenv=getfenv()
1001 local meta={__index=origenv, __newindex=origenv}
1004 _sub=mplex:current(),
1007 setmetatable(env, meta)
1011 function mod_query.do_handle_lua(mplex, env, code)
1013 local function collect_print(...)
1017 tmp=tmp..tostring(arg[i])..(i==l and "\n" or "\t")
1019 print_res=(print_res and print_res..tmp or tmp)
1022 local f, err=loadstring(code)
1024 mod_query.warn(mplex, err)
1028 env.print=collect_print
1031 err=collect_errors(f)
1033 mod_query.warn(mplex, err)
1034 elseif print_res then
1035 mod_query.message(mplex, print_res)
1039 local function getindex(t)
1040 local mt=getmetatable(t)
1041 if mt then return mt.__index end
1045 function mod_query.do_complete_lua(env, str)
1046 -- Get the variable to complete, including containing tables.
1047 -- This will also match string concatenations and such because
1048 -- Lua's regexps don't support optional subexpressions, but we
1049 -- handle them in the next step.
1052 local _, _, tocomp=string.find(str, "([%w_.:]*)$")
1054 -- Descend into tables
1055 if tocomp and string.len(tocomp)>=1 then
1056 for t in string.gfind(tocomp, "([^.:]*)[.:]") do
1058 if string.len(t)==0 then
1061 if type(comptab[t])=="table" then
1063 elseif type(comptab[t])=="userdata" then
1064 comptab=getindex(comptab[t])
1073 if not comptab then return {} end
1077 -- Get the actual variable to complete without containing tables
1078 _, _, compl.common_beg, tocomp=string.find(str, "(.-)([%w_]*)$")
1080 local l=string.len(tocomp)
1085 if type(tab) == "table" then
1086 for k in pairs(tab) do
1087 if type(k)=="string" then
1088 if string.sub(k, 1, l)==tocomp then
1089 table.insert(compl, k)
1095 -- We only want to display full list of functions for objects, not
1096 -- the tables representing the classes.
1097 --if not metas then break end
1101 if not tab or seen[tab] then break end
1104 -- If there was only one completion and it is a string or function,
1105 -- concatenate it with "." or "(", respectively.
1107 if type(comptab[compl[1]])=="table" then
1108 compl[1]=compl[1] .. "."
1109 elseif type(comptab[compl[1]])=="function" then
1110 compl[1]=compl[1] .. "("
1119 -- This query asks for Lua code to execute. It sets the variable '\var{\_}'
1120 -- in the local environment of the string to point to the mplex where the
1121 -- query was created. It also sets the table \var{arg} in the local
1122 -- environment to \code{\{_, _:current()\}}.
1123 function mod_query.query_lua(mplex)
1124 local env=mod_query.create_run_env(mplex)
1126 local function complete(cp, code)
1127 cp:set_completions(mod_query.do_complete_lua(env, code))
1130 local function handler(mplex, code)
1131 return mod_query.do_handle_lua(mplex, env, code)
1134 mod_query.query(mplex, TR("Lua code:"), nil, handler, complete, "lua")
1143 -- This query can be used to create a query of a defined menu.
1144 function mod_query.query_menu(mplex, sub, themenu, prompt)
1145 if type(sub)=="string" then
1146 -- Backwards compat. shift
1152 local menu=ioncore.evalmenu(themenu, mplex, sub)
1153 local menuname=(type(themenu)=="string" and themenu or "?")
1156 mod_query.warn(mplex, TR("Unknown menu %s.", tostring(themenu)))
1161 prompt=menuname..":"
1166 local function xform_name(n, is_submenu)
1167 return string.lower(string.gsub(n, "[-/%s]+", "-"))
1170 local function xform_menu(t, m, p)
1171 for _, v in ipairs(m) do
1173 local is_submenu=v.submenu_fn
1174 local n=p..xform_name(v.name)
1176 while t[n] or t[n..'/'] do
1186 if is_submenu and not v.noautoexpand then
1187 local sm=v.submenu_fn()
1189 xform_menu(t, sm, n)
1191 ioncore.warn_traced(TR("Missing submenu ")
1200 local ntab=xform_menu({}, menu, "")
1202 local function complete(str)
1203 -- casei_ok false, because everything is already in lower case
1204 return mod_query.complete_keys(ntab, str, true, false)
1207 local function handle(mplex, str)
1211 local err=collect_errors(function()
1215 mod_query.warn(mplex, err)
1217 elseif e.submenu_fn then
1218 mod_query.query_menu(mplex, e.submenu_fn(),
1222 mod_query.warn(mplex, TR("No entry '%s'", str))
1226 mod_query.query(mplex, prompt, nil, handle,
1227 mod_query.make_completor(complete), "menu."..menuname)
1233 -- Miscellaneous {{{
1237 -- Display an "About Ion" message in \var{mplex}.
1238 function mod_query.show_about_ion(mplex)
1239 mod_query.message(mplex, ioncore.aboutmsg())
1244 -- Show information about a region tree
1245 function mod_query.show_tree(mplex, reg, max_depth)
1246 local function indent(s)
1248 return i..string.gsub(s, "\n", "\n"..i)
1251 local function get_info(reg, indent, d)
1253 return (indent .. "No region")
1256 local function n(s) return (s or "") end
1258 local s=string.format("%s%s \"%s\"", indent, obj_typename(reg),
1260 indent = indent .. " "
1261 if obj_is(reg, "WClientWin") then
1262 local i=reg:get_ident()
1263 s=s .. TR("\n%sClass: %s\n%sRole: %s\n%sInstance: %s\n%sXID: 0x%x",
1266 indent, n(i.instance),
1270 if (not max_depth or max_depth > d) and reg.managed_i then
1272 reg:managed_i(function(sub)
1274 s=s .. "\n" .. indent .. "---"
1277 s=s .. "\n" .. get_info(sub, indent, d+1)
1285 mod_query.message(mplex, get_info(reg, "", 0))
1291 dopath('mod_query_chdir')
1293 -- Mark ourselves loaded.
1294 package.loaded["mod_query"]=true
1297 -- Load configuration file
1298 dopath('cfg_query', true)