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, in the directory
243 -- To its stdout, the command should on the first line write the \var{common_beg}
244 -- parameter of \fnref{WComplProxy.set_completions} (which \var{fn} maybe used
245 -- to override) and a single actual completion on each of the successive lines.
246 -- The function \var{reshnd} may be used to override a result table
248 function mod_query.popen_completions(cp, cmd, fn, reshnd, wd)
250 local pst={cp=cp, maybe_stalled=0}
253 reshnd = function(rs, a)
254 if not rs.common_beg then
262 local function rcv(str)
269 if pst.maybe_stalled>=2 then
275 totallen=totallen+string.len(str)
276 if totallen>ioncore.RESULT_DATA_LIMIT then
277 error(TR("Too much result data"))
281 data=string.gsub(data..str, "([^\n]*)\n",
288 if lines>mod_query.COLLECT_THRESHOLD then
293 str=coroutine.yield()
296 if not results.common_beg then
297 results.common_beg=beg
300 (fn or WComplProxy.set_completions)(cp, results)
308 local found_clean=false
310 for k, v in pairs(pipes) do
312 if v.maybe_stalled<2 then
313 v.maybe_stalled=v.maybe_stalled+1
319 if not found_clean then
321 ioncore.popen_bgread(cmd, coroutine.wrap(rcv), nil, wd)
326 local function mk_completion_test(str, sub_ok, casei_ok)
328 return function(s) return true end
331 local function mk(str, sub_ok)
333 return function(s) return string.find(s, str, 1, true) end
335 local len=string.len(str)
336 return function(s) return string.sub(s, 1, len)==str end
340 local casei=(casei_ok and mod_query.get().caseicompl)
343 return mk(str, sub_ok)
345 local fn=mk(string.lower(str), sub_ok)
346 return function(s) return fn(string.lower(s)) end
351 local function mk_completion_add(entries, str, sub_ok, casei_ok)
352 local tst=mk_completion_test(str, sub_ok, casei_ok)
356 table.insert(entries, s)
362 function mod_query.complete_keys(list, str, sub_ok, casei_ok)
364 local test_add=mk_completion_add(results, str, sub_ok, casei_ok)
366 for m, _ in pairs(list) do
374 function mod_query.complete_name(str, iter)
375 local sub_ok_first=true
378 local tst_add=mk_completion_add(entries, str, sub_ok_first, casei_ok)
385 if #entries==0 and not sub_ok_first then
386 local tst_add2=mk_completion_add(entries, str, true, casei_ok)
397 function mod_query.make_completor(completefn)
398 local function completor(cp, str, point)
399 cp:set_completions(completefn(str, point))
408 -- Simple queries for internal actions {{{
411 function mod_query.call_warn(mplex, fn)
412 local err = collect_errors(fn)
414 mod_query.warn(mplex, err)
420 function mod_query.complete_clientwin(str)
421 return mod_query.complete_name(str, ioncore.clientwin_i)
425 function mod_query.complete_workspace(str)
426 local function iter(fn)
427 return ioncore.region_i(function(obj)
428 return (not obj_is(obj, "WGroupWS")
432 return mod_query.complete_name(str, iter)
436 function mod_query.complete_region(str)
437 return mod_query.complete_name(str, ioncore.region_i)
441 function mod_query.gotoclient_handler(frame, str)
442 local cwin=ioncore.lookup_clientwin(str)
445 mod_query.warn(frame, TR("Could not find client window %s.", str))
452 function mod_query.attachclient_handler(frame, str)
453 local cwin=ioncore.lookup_clientwin(str)
456 mod_query.warn(frame, TR("Could not find client window %s.", str))
460 local reg=cwin:groupleader_of()
462 local function attach()
463 frame:attach(reg, { switchto = true })
466 if frame:rootwin_of()~=reg:rootwin_of() then
467 mod_query.warn(frame, TR("Cannot attach: different root windows."))
468 elseif reg:manager()==frame then
471 mod_query.call_warn(frame, attach)
476 function mod_query.workspace_handler(mplex, name)
477 local ws=ioncore.lookup_region(name, "WGroupWS")
481 local function create_handler(mplex_, layout)
482 if not layout or layout=="" then
486 if not ioncore.getlayout(layout) then
487 mod_query.warn(mplex_, TR("Unknown layout"))
489 local scr=mplex:screen_of()
491 local function mkws()
493 name=(name~="" and name),
496 if not ioncore.create_ws(scr, tmpl, layout) then
497 error(TR("Unknown error"))
501 mod_query.call_warn(mplex, mkws)
505 local function compl_layout(str)
506 local los=ioncore.getlayout(nil, true)
507 return mod_query.complete_keys(los, str, true, true)
510 mod_query.query(mplex, TR("New workspace layout (default):"), nil,
511 create_handler, mod_query.make_completor(compl_layout),
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_gotoclient(mplex)
522 mod_query.query(mplex, TR("Go to window:"), nil,
523 mod_query.gotoclient_handler,
524 mod_query.make_completor(mod_query.complete_clientwin),
529 -- This query asks for the name of a client window and attaches
530 -- it to the frame the query was opened in. It uses the completion
531 -- function \fnref{ioncore.complete_clientwin}.
532 function mod_query.query_attachclient(mplex)
533 mod_query.query(mplex, TR("Attach window:"), nil,
534 mod_query.attachclient_handler,
535 mod_query.make_completor(mod_query.complete_clientwin),
541 -- This query asks for the name of a workspace. If a workspace
542 -- (an object inheriting \type{WGroupWS}) with such a name exists,
543 -- it will be switched to. Otherwise a new workspace with the
544 -- entered name will be created and the user will be queried for
545 -- the type of the workspace.
546 function mod_query.query_workspace(mplex)
547 mod_query.query(mplex, TR("Go to or create workspace:"), nil,
548 mod_query.workspace_handler,
549 mod_query.make_completor(mod_query.complete_workspace),
555 -- This query asks whether the user wants to exit Ion (no session manager)
556 -- or close the session (running under a session manager that supports such
557 -- requests). If the answer is 'y', 'Y' or 'yes', so will happen.
558 function mod_query.query_shutdown(mplex)
559 mod_query.query_yesno(mplex, TR("Exit Ion/Shutdown session (y/n)?"),
565 -- This query asks whether the user wants restart Ioncore.
566 -- If the answer is 'y', 'Y' or 'yes', so will happen.
567 function mod_query.query_restart(mplex)
568 mod_query.query_yesno(mplex, TR("Restart Ion (y/n)?"), ioncore.restart)
573 -- This function asks for a name new for the frame where the query
575 function mod_query.query_renameframe(frame)
576 mod_query.query(frame, TR("Frame name:"), frame:name(),
577 function(frame, str) frame:set_name(str) end,
583 -- This function asks for a name new for the workspace \var{ws},
584 -- or the one on which \var{mplex} resides, if it is not set.
585 -- If \var{mplex} is not set, one is looked for.
586 function mod_query.query_renameworkspace(mplex, ws)
589 mplex=ioncore.find_manager(ws, "WMPlex")
592 ws=ioncore.find_manager(mplex, "WGroupWS")
597 mod_query.query(mplex, TR("Workspace name:"), ws:name(),
598 function(mplex, str) ws:set_name(str) end,
610 -- Asks for a file to be edited. This script uses
611 -- \command{run-mailcap --mode=edit} by default, but you may provide an
612 -- alternative script to use. The default prompt is "Edit file:" (translated).
613 function mod_query.query_editfile(mplex, script, prompt)
614 mod_query.query_execfile(mplex,
615 prompt or TR("Edit file:"),
616 script or "run-mailcap --action=edit")
621 -- Asks for a file to be viewed. This script uses
622 -- \command{run-mailcap --action=view} by default, but you may provide an
623 -- alternative script to use. The default prompt is "View file:" (translated).
624 function mod_query.query_runfile(mplex, script, prompt)
625 mod_query.query_execfile(mplex,
626 prompt or TR("View file:"),
627 script or "run-mailcap --action=view")
632 local function isspace(s)
633 return string.find(s, "^%s*$")~=nil
637 local function break_cmdline(str, no_ws)
638 local st, en, beg, rest, ch, rem
641 local function ins(str)
643 if string.find(res[n], "^%s+$") then
644 table.insert(res, str)
650 local function ins_space(str)
654 table.insert(res, "")
657 if isspace(res[n]) then
660 table.insert(res, str)
665 -- Handle terminal startup syntax
666 st, en, beg, ch, rest=string.find(str, "^(%s*)(:+)(.*)")
668 if string.len(beg)>0 then
677 st, en, beg, rest, ch=string.find(str, "^(.-)(([%s'\"\\|])(.*))")
689 st, en, beg, rest=string.find(str, "^(\\.)(.*)")
691 st, en, beg, rest=string.find(str, "^(\".-[^\\]\")(.*)")
694 st, en, beg, rest=string.find(str, "^(\"\")(.*)")
697 st, en, beg, rest=string.find(str, "^('.-')(.*)")
705 st, en, beg, rest=string.find(str, "^.(%s*)(.*)")
726 local function unquote(str)
727 str=string.gsub(str, "^['\"]", "")
728 str=string.gsub(str, "([^\\])['\"]", "%1")
729 str=string.gsub(str, "\\(.)", "%1")
734 local function quote(str)
735 return string.gsub(str, "([%(%)\"'\\%*%?%[%]%| ])", "\\%1")
739 local function find_point(strs, point)
740 for i, s in ipairs(strs) do
741 point=point-string.len(s)
750 function mod_query.exec_completor_(wd, wedln, str, point)
751 local parts=break_cmdline(str)
752 local complidx=find_point(parts, point+1)
754 local s_compl, s_beg, s_end="", "", ""
756 if complidx==1 and string.find(parts[1], "^:+$") then
760 if string.find(parts[complidx], "[^%s]") then
761 s_compl=unquote(parts[complidx])
764 for i=1, complidx-1 do
765 s_beg=s_beg..parts[i]
768 for i=complidx+1, #parts do
769 s_end=s_end..parts[i]
773 if complidx==1 or (complidx==2 and isspace(parts[1])) then
775 elseif string.find(parts[1], "^:+$") then
778 elseif string.find(parts[2], "^%s*$") then
785 local function set_fn(cp, res)
786 res=table.map(quote, res)
787 res.common_beg=s_beg..(res.common_beg or "")
788 res.common_end=(res.common_end or "")..s_end
789 cp:set_completions(res)
792 local function filter_fn(res, s)
793 if not res.common_beg then
804 local ic=ioncore.lookup_script("ion-completefile")
806 mod_query.popen_completions(wedln,
807 ic..wp..string.shell_safe(s_compl),
808 set_fn, filter_fn, wd)
813 function mod_query.exec_completor(...)
814 mod_query.exec_completor_(nil, ...)
818 local cmd_overrides={}
822 -- Define a command override for the \fnrefx{mod_query}{query_exec} query.
823 function mod_query.defcmd(cmd, fn)
824 cmd_overrides[cmd]=fn
828 function mod_query.exec_handler(mplex, cmdline)
829 local parts=break_cmdline(cmdline, true)
830 local cmd=table.remove(parts, 1)
832 if cmd_overrides[cmd] then
833 cmd_overrides[cmd](mplex, table.map(unquote, parts))
835 mod_query.exec_on_merr(mplex, cmdline)
841 -- This function asks for a command to execute with \file{/bin/sh}.
842 -- If the command is prefixed with a colon (':'), the command will
843 -- be run in an XTerm (or other terminal emulator) using the script
844 -- \file{ion-runinxterm}. Two colons ('::') will ask you to press
845 -- enter after the command has finished.
846 function mod_query.query_exec(mplex)
847 local function compl(...)
848 local wd=ioncore.get_dir_for(mplex)
849 mod_query.exec_completor_(wd, ...)
851 mod_query.query(mplex, TR("Run:"), nil, mod_query.exec_handler,
862 mod_query.known_hosts={}
863 mod_query.hostnicks={}
864 mod_query.ssh_completions={}
867 function mod_query.get_known_hosts(mplex)
868 mod_query.known_hosts={}
870 local h=os.getenv("HOME")
872 f=io.open(h.."/.ssh/known_hosts")
875 warn(TR("Failed to open ~/.ssh/known_hosts"))
878 for l in f:lines() do
879 local st, en, hostname=string.find(l, "^([^%s,]+)")
881 table.insert(mod_query.known_hosts, hostname)
888 function mod_query.get_hostnicks(mplex)
889 mod_query.hostnicks={}
891 local substr, pat, patterns
892 local h=os.getenv("HOME")
895 f=io.open(h.."/.ssh/config")
898 warn(TR("Failed to open ~/.ssh/config"))
902 for l in f:lines() do
903 _, _, substr=string.find(l, "^%s*[hH][oO][sS][tT](.*)")
905 _, _, pat=string.find(substr, "^%s*[=%s]%s*(%S.*)")
908 elseif string.find(substr, "^[nN][aA][mM][eE]")
910 for s in string.gfind(patterns, "%S+") do
911 if not string.find(s, "[*?]") then
912 table.insert(mod_query.hostnicks, s)
922 function mod_query.complete_ssh(str)
923 local st, en, user, at, host=string.find(str, "^([^@]*)(@?)(.*)$")
925 if string.len(at)==0 and string.len(host)==0 then
926 host = user; user = ""
934 local tst = mk_completion_test(host, true, false)
936 for _, v in ipairs(mod_query.ssh_completions) do
938 table.insert(res, user .. v)
947 -- This query asks for a host to connect to with SSH.
948 -- Hosts to tab-complete are read from \file{\~{}/.ssh/known\_hosts}.
949 function mod_query.query_ssh(mplex, ssh)
950 mod_query.get_known_hosts(mplex)
951 mod_query.get_hostnicks(mplex)
953 for _, v in ipairs(mod_query.known_hosts) do
954 table.insert(mod_query.ssh_completions, v)
956 for _, v in ipairs(mod_query.hostnicks) do
957 table.insert(mod_query.ssh_completions, v)
962 local function handle_exec(mplex, str)
963 if not (str and string.find(str, "[^%s]")) then
967 mod_query.exec_on_merr(mplex, ssh.." "..string.shell_safe(str))
970 return mod_query.query(mplex, TR("SSH to:"), nil, handle_exec,
971 mod_query.make_completor(mod_query.complete_ssh),
981 function mod_query.man_completor(wedln, str)
982 local mc=ioncore.lookup_script("ion-completeman")
983 local icase=(mod_query.get().caseicompl and " -icase" or "")
986 mod_query.popen_completions(wedln, (mc..icase..mid.." -complete "
987 ..string.shell_safe(str)))
993 -- This query asks for a manual page to display. By default it runs the
994 -- \command{man} command in an \command{xterm} using \command{ion-runinxterm},
995 -- but it is possible to pass another program as the \var{prog} argument.
996 function mod_query.query_man(mplex, prog)
997 local dflt=ioncore.progname()
998 mod_query.query_execwith(mplex, TR("Manual page (%s):", dflt),
999 dflt, prog or ":man",
1000 mod_query.man_completor, "man",
1001 true --[[ no quoting ]])
1008 -- Lua code execution {{{
1011 function mod_query.create_run_env(mplex)
1012 local origenv=getfenv()
1013 local meta={__index=origenv, __newindex=origenv}
1016 _sub=mplex:current(),
1019 setmetatable(env, meta)
1023 function mod_query.do_handle_lua(mplex, env, code)
1025 local function collect_print(...)
1029 tmp=tmp..tostring(arg[i])..(i==l and "\n" or "\t")
1031 print_res=(print_res and print_res..tmp or tmp)
1034 local f, err=loadstring(code)
1036 mod_query.warn(mplex, err)
1040 env.print=collect_print
1043 err=collect_errors(f)
1045 mod_query.warn(mplex, err)
1046 elseif print_res then
1047 mod_query.message(mplex, print_res)
1051 local function getindex(t)
1052 local mt=getmetatable(t)
1053 if mt then return mt.__index end
1057 function mod_query.do_complete_lua(env, str)
1058 -- Get the variable to complete, including containing tables.
1059 -- This will also match string concatenations and such because
1060 -- Lua's regexps don't support optional subexpressions, but we
1061 -- handle them in the next step.
1064 local _, _, tocomp=string.find(str, "([%w_.:]*)$")
1066 -- Descend into tables
1067 if tocomp and string.len(tocomp)>=1 then
1068 for t in string.gfind(tocomp, "([^.:]*)[.:]") do
1070 if string.len(t)==0 then
1073 if type(comptab[t])=="table" then
1075 elseif type(comptab[t])=="userdata" then
1076 comptab=getindex(comptab[t])
1085 if not comptab then return {} end
1089 -- Get the actual variable to complete without containing tables
1090 _, _, compl.common_beg, tocomp=string.find(str, "(.-)([%w_]*)$")
1092 local l=string.len(tocomp)
1097 if type(tab) == "table" then
1098 for k in pairs(tab) do
1099 if type(k)=="string" then
1100 if string.sub(k, 1, l)==tocomp then
1101 table.insert(compl, k)
1107 -- We only want to display full list of functions for objects, not
1108 -- the tables representing the classes.
1109 --if not metas then break end
1113 if not tab or seen[tab] then break end
1116 -- If there was only one completion and it is a string or function,
1117 -- concatenate it with "." or "(", respectively.
1119 if type(comptab[compl[1]])=="table" then
1120 compl[1]=compl[1] .. "."
1121 elseif type(comptab[compl[1]])=="function" then
1122 compl[1]=compl[1] .. "("
1131 -- This query asks for Lua code to execute. It sets the variable '\var{\_}'
1132 -- in the local environment of the string to point to the mplex where the
1133 -- query was created. It also sets the table \var{arg} in the local
1134 -- environment to \code{\{_, _:current()\}}.
1135 function mod_query.query_lua(mplex)
1136 local env=mod_query.create_run_env(mplex)
1138 local function complete(cp, code)
1139 cp:set_completions(mod_query.do_complete_lua(env, code))
1142 local function handler(mplex, code)
1143 return mod_query.do_handle_lua(mplex, env, code)
1146 mod_query.query(mplex, TR("Lua code:"), nil, handler, complete, "lua")
1155 -- This query can be used to create a query of a defined menu.
1156 function mod_query.query_menu(mplex, sub, themenu, prompt)
1157 if type(sub)=="string" then
1158 -- Backwards compat. shift
1164 local menu=ioncore.evalmenu(themenu, mplex, sub)
1165 local menuname=(type(themenu)=="string" and themenu or "?")
1168 mod_query.warn(mplex, TR("Unknown menu %s.", tostring(themenu)))
1173 prompt=menuname..":"
1178 local function xform_name(n, is_submenu)
1179 return string.lower(string.gsub(n, "[-/%s]+", "-"))
1182 local function xform_menu(t, m, p)
1183 for _, v in ipairs(m) do
1185 local is_submenu=v.submenu_fn
1186 local n=p..xform_name(v.name)
1188 while t[n] or t[n..'/'] do
1198 if is_submenu and not v.noautoexpand then
1199 local sm=v.submenu_fn()
1201 xform_menu(t, sm, n)
1203 ioncore.warn_traced(TR("Missing submenu ")
1212 local ntab=xform_menu({}, menu, "")
1214 local function complete(str)
1215 -- casei_ok false, because everything is already in lower case
1216 return mod_query.complete_keys(ntab, str, true, false)
1219 local function handle(mplex, str)
1223 local err=collect_errors(function()
1227 mod_query.warn(mplex, err)
1229 elseif e.submenu_fn then
1230 mod_query.query_menu(mplex, e.submenu_fn(),
1234 mod_query.warn(mplex, TR("No entry '%s'", str))
1238 mod_query.query(mplex, prompt, nil, handle,
1239 mod_query.make_completor(complete), "menu."..menuname)
1245 -- Miscellaneous {{{
1249 -- Display an "About Ion" message in \var{mplex}.
1250 function mod_query.show_about_ion(mplex)
1251 mod_query.message(mplex, ioncore.aboutmsg())
1256 -- Show information about a region tree
1257 function mod_query.show_tree(mplex, reg, max_depth)
1258 local function indent(s)
1260 return i..string.gsub(s, "\n", "\n"..i)
1263 local function get_info(reg, indent, d)
1265 return (indent .. "No region")
1268 local function n(s) return (s or "") end
1270 local s=string.format("%s%s \"%s\"", indent, obj_typename(reg),
1272 indent = indent .. " "
1273 if obj_is(reg, "WClientWin") then
1274 local i=reg:get_ident()
1275 s=s .. TR("\n%sClass: %s\n%sRole: %s\n%sInstance: %s\n%sXID: 0x%x",
1278 indent, n(i.instance),
1282 if (not max_depth or max_depth > d) and reg.managed_i then
1284 reg:managed_i(function(sub)
1286 s=s .. "\n" .. indent .. "---"
1289 s=s .. "\n" .. get_info(sub, indent, d+1)
1297 mod_query.message(mplex, get_info(reg, "", 0))
1303 dopath('mod_query_chdir')
1305 -- Mark ourselves loaded.
1306 package.loaded["mod_query"]=true
1309 -- Load configuration file
1310 dopath('cfg_query', true)