Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like for the autocomplete feature to search through contexts, for example if I have a symbol named A`B`C`MyFunction, 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:

Very`Long`Context`For`My`Function1
Very`Long`Context`For`My`Function2
...

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

Very`Long`Context`For`My`Function1
Very`Long`Context`For`My`Function2
...
share|improve this question
    
I assume you mean cmd-k, since cmd-shift-k inserts a template. –  Brett Champion Jun 15 '12 at 2:06
add comment

2 Answers 2

up vote 16 down vote accepted

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:

enter image description here

enter image description here

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}
share|improve this answer
    
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, "A`B`C`"]
share|improve this answer
    
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 A`B`C`(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 A`B`C`MyFunction A`B`C`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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.