4
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ In M9 all defined variables are autocompleted - is it not what you need? $\endgroup$ – Vitaliy Kaurov Apr 3 '13 at 18:12
  • $\begingroup$ Yes, it autocompletes for me too. Re: your second question, you can do SetOptions[$FrontEnd, AutoStyleOptions -> {"SymbolContextStyles" -> {"MyContext`" -> Green}}] $\endgroup$ – rm -rf Apr 3 '13 at 18:15
  • $\begingroup$ 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. $\endgroup$ – Mohammed AlQuraishi Apr 3 '13 at 18:23
  • $\begingroup$ 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. $\endgroup$ – rm -rf Apr 3 '13 at 18:29
  • $\begingroup$ Does it auto-complete if you just do xyz=5; ? $\endgroup$ – Vitaliy Kaurov Apr 3 '13 at 18:34
1
$\begingroup$

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.
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Dr_Zaszuś Jul 29 '14 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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