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.

Is it possible in v9 to autocomplete the short symbol names when one is operating in a context other than Global`? I.e. after evaluating the following:

Begin["MyContext`"];
xyz=5;

Starting to write MyCon... will autocomplete and give MyContext`xyz as an option. That's not what I want. I want to write x and get autocomplete to suggest xyz. I tried adding MyContext` to $ContextPath but that doesn't do anything. Of course if I were to exit MyContext` and return to Global` I don't expect it to autocomplete the short name anymore. Also, I noticed that the symbol coloring is off too, so that xyz appears to have no value assigned (blue colored) even though it obviously does have a value.

share|improve this question
    
In M9 all defined variables are autocompleted - is it not what you need? –  Vitaliy Kaurov Apr 3 '13 at 18:12
    
Yes, it autocompletes for me too. Re: your second question, you can do SetOptions[$FrontEnd, AutoStyleOptions -> {"SymbolContextStyles" -> {"MyContext`" -> Green}}] –  rm -rf Apr 3 '13 at 18:15
    
That's strange. It doesn't autocomplete for me, and I tried it both on Mac and PC, and using 9.0.1... I do exactly what I said above, and unless I type MyCon... nothing happens. If I just starting typing x it just sits there. –  Mohammed AlQuraishi Apr 3 '13 at 18:23
    
Hmm.. I think I can reproduce it if I do Begin[...] and work in it without calling End[]. The problem is that the FrontEnd has not yet recognized the new context (which it does when you call End[]) and my guess is that when you call it with the full context, it is the kernel that is providing this information. If you instead do Begin[...];AppendTo[$ContextPath,...];End[]; Begin[...], it works i.e., create your context and add it to the path, close it so that the FE recognizes it and then switch to it again. Enter those in separate lines, not as one. –  rm -rf Apr 3 '13 at 18:29
    
Does it auto-complete if you just do xyz=5; ? –  Vitaliy Kaurov Apr 3 '13 at 18:34

1 Answer 1

Paraphrasing the insights of rm -rf:

  • To make highlighting and autocompletion work in new contexts you have to run: 1) Begin[...]; 2) AppendTo[$ContextPath,...] and 3) End[]. Then you have to open your context again: Begin[...];
  • Be sure to put each of (1), (2) and (3) in the previous bullet point in separate cells. They have to be evaluated separately or it won't work.
share|improve this answer
    
Thanks for the answer, but could you please provide a working example, because my auto-completion still does not work, when I repeat what you say. –  Szczypawka Jul 29 at 13:28

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.