How to make the variables in init.minit.m not impact the autocompletion

The autocompletion is very convient in Mathematica,but it will make one annoying sometimes when you have a ton variables.I give a scene I encounter.I usually make many custom functions in my init.m,for example


But when I launch my Mathematica as soon as there are many variables prompt to this

So my question is how to make the variables in init.m not impact the autocompletion



1 Answer


Don’t put symbols you don’t want to show up in auto-completion into the Global` context. Use the same mechanism you would for a package.

myfun; (* create in Global` *)
myfun[x_] := Module[{y=x^2}, y^2]

I noticed you are putting your function into the System` context. This seems like a bad idea. The System` context is for builtins.

What I do personally is that I create a complete package and load it with Needs in init.m. This way the package lives in its own separate context, i.e. neither in System or Global.

If the package is very simple, it can also be inlines in init.m: just put the same code that would go in the package file into init.m

If these definitions need to be accessible from subkernels (when parallelizing), then use the Autoload directory instead of init.m.



Upvote.The System` can prevent my custom function losing its definition from Clear[“`*”]
– yode
Jun 24 at 17:27



@yode So can any other context. Clear[“`*”] only clears Global`
– Szabolcs
Jun 24 at 17:28



You save me again.
– yode
Jun 24 at 17:42



@Szabolcs But lower case functions are sometimes useful in the System` context: you can use them in other packages without trouble. Withy your Global`myfun you will have to use the longname explicitly in any package. So why not Begin[“MyPrivateInitContext`”]; System`testFunction[variablea_] := Module[{variableb = variablea}, variableb + 1]; End[]; ?
– Rolf Mertig
Jun 24 at 20:18



@Rolf Actually I am not advocating using Global. I think the right way is to use a custom context. If we want to use this in packages, we can always add it to the $ContextPath with one line after BeginPackage. Even better, just put the definitions in a proper package and load the package in init.m. Inside another package, load it with Needs or BeginPackage. What I do personally is that I put the definitions in a package and put the package in Autoload. This way I can also use it from subkernels when parallelizing.
– Szabolcs
Jun 24 at 20:23