# How can I overload autocompletion to work with full contexts?

I would like for the autocomplete feature to search through contexts, for example if I have a symbol named ABCMyFunction, when I type A and press "cmd + shift + k" it will complete it.

Edit

To be clear, I don't want to have to type the path because it's usually very long, and I don't want to have to type the function name again, even if the path itself gets auto completed. I want the following:

If I have these functions:

VeryLongContextForMyFunction1
VeryLongContextForMyFunction2
...


I want to be able to type Very and then press CMD+Shift+k, to get a dropdown menu saying exactly

VeryLongContextForMyFunction1
VeryLongContextForMyFunction2
...

-
I assume you mean cmd-k, since cmd-shift-k inserts a template. –  Brett Champion Jun 15 '12 at 2:06

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 FEFC.

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 FEnames.)

(* Nice little hack to have command completion (cmd-k) include contexts *)
Unprotect[FEFC];
ClearAll[FEFC]

FEFC[FEnameString_, FEignoreCase_:False] /; $Notebooks:= MathLinkCallFrontEnd[FrontEndCompletionsListPacket[ FEnames[FEnameString<>"*"], FEignoreCase], FENoResult] FEnames[FEstr_, FEignoreCase_:False] := Join[FEshortContexts[FEstr], Names[FEstr, IgnoreCase -> FEignoreCase]]; FEshortContexts[FEpatt_]:= With[{FEbrettclen = Length[StringSplit[FEpatt, ""]]}, Union[StringJoin[ Riffle[Take[#, Min[FEbrettclen, Length[#]]], "", {2, -1, 2}]] & /@ StringSplit[Contexts[FEpatt], ""]] ] Protect[FEFC];  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}  - wow, I have somehow missed autocomplete for the last 5 years.... thanks for this! – tkott Jun 15 '12 at 15:25 Exactly! I knew I wasn't crazy. – M.R. Jun 15 '12 at 19:52 add comment One option is to put the context on the path: $ContextPath = AppendTo[$ContextPath, "ABC"]  - I don't think this works. After appending to the$ContextPath, if you type "CMD+Shift+k", after typing "A", you don't get a list with ABC(functions) as items to complete, as you would if you typed "MapThre"... –  M.R. Jun 14 '12 at 22:58
@Mike, expanding MyF+Shift+k works just fine. If you want something else, I suggest to state that more clearly in your question. –  user21 Jun 14 '12 at 23:00
@Mike, just that we are on the same page: adding ABCMyFunction ABC`MyFunction2 give a list of items. Maybe I don't get what you want. –  user21 Jun 14 '12 at 23:07
Sorry for the confusion! I just updated the question a bit. –  M.R. Jun 14 '12 at 23:10