This is obsolete in Mathematica 9, which automatically includes contexts in completions.
Undocumented function: use at your own risk, subject to change in future versions, etc....
The function you're interested in is FE`FC
.
It's been around for a while (here's a Mathematica Journal article that references it, near the end) although it has changed argument structure at least once that I'm aware of.
Anyway, here's the code I currently use to a similar end as what Mike would like. (Most of this is boilerplate from the original definition; the main difference is the use of a new function FE`names
.)
(* Nice little hack to have command completion (cmd-k) include contexts *)
Unprotect[FE`FC];
ClearAll[FE`FC]
FE`FC[FE`nameString_, FE`ignoreCase_:False] /; $Notebooks:=
MathLink`CallFrontEnd[FrontEnd`CompletionsListPacket[
FE`names[FE`nameString<>"*"], FE`ignoreCase],
FE`NoResult]
FE`names[FE`str_, FE`ignoreCase_:False] :=
Join[FE`shortContexts[FE`str], Names[FE`str, IgnoreCase -> FE`ignoreCase]];
FE`shortContexts[FE`patt_]:=
With[{FE`brettclen = Length[StringSplit[FE`patt, "`"]]},
Union[StringJoin[
Riffle[Take[#, Min[FE`brettclen, Length[#]]], "`", {2, -1, 2}]] & /@
StringSplit[Contexts[FE`patt], "`"]]
]
Protect[FE`FC];
The end result is that when I use command completion, I get contexts that match in addition to symbols. This isn't quite the same as Mike's request, since it gives the contexts one at a time:
since otherwise the list can get a bit overwhelming. For example, if you typed Int
and then tried to complete to IntegerPart
, there's a factor of ten difference:
In[5]:= {Length[Names["Int*"]] + Length[Contexts["Int*"]],
Length[Names["Int*`*"]]}
Out[5]= {41, 419}
cmd-k
, sincecmd-shift-k
inserts a template. $\endgroup$