# Prevent autocompletion for symbols in contexts other than “Private” [duplicate]

I've been working on a Mathematica package (call it QuantumDot) that has become huge. Right now, all the back-end helper functions are in context QuantumDotPrivate, and the WHOLE code is in one gigantic .m file.

I'd like to reorganize it so that QuantumDot has multiple sub-contexts corresponding, roughly, to each front-end function. I want to put all the back-end helper functions into these sub-contexts.

For example:

(*These are the main functions accessible to the user*)
QuantumDot
MainFunction[x,y,z]
ComplexRoutine[x,y]

(*These are the backend helper functions*)
QuantumDotMainFunction
internalFunction[a,b,c]
distribute[a,b,c]
...

QuantumDotComplexRoutine
step1function[a,b,c]
step2function[a,b,c]
reducer[a,b,c]
...


I can achieve this by replacing in my existing code Begin["Private"] with Begin["MainFunction"], Begin["ComplexRoutine "],... as necessary.

BeginPackage["QuantumDot"];
MainFunction::usage = "MainFunction[x,y,z] is a front-end function for users";

Begin["MainFunction"];  (*  was Begin["Private"];  *)

internalFunction[a_,b_,c_] := a^2 - b^2 - c^2;
addAndSubtract[a_,b_,c_] := a + b - c;
distribute[a,b,c] := a(b+c)//Expand;

End[];

Begin["ComplexRoutine"];
(*...*)
End[];

EndPackage[];


The problem is that the autocomplete picks up the back-end functions. (Apparently, there was something special with the "Private" context).

1. What can I do to prevent the autocompletion feature from displaying these internal functions?

2. I then intend to split my package into multiple .m files according to the main functions of the package. Is this a reasonable way to proceed?

## marked as duplicate by QuantumDot, m_goldberg, Community♦May 28 '17 at 23:30

• Would it be of any help if you wrapped all those subcontexts within a Private context instead? – MarcoB May 21 '16 at 15:26
• @MarcoB I thought about this a while back, and if I can't find a cleaner solution, I'll have to do what you suggest. – QuantumDot May 21 '16 at 15:54
• Yeah, that's sort of what the Private context is meant to be doing for you. Is there some specific reason why you don't want to use it? – Emilio Pisanty May 23 '16 at 15:01
• But Private can be included at any point in the context chain, so QuantumDotPrivateMainFunction  and QuantumDotMainFunctionPrivate  are both valid contexts (called using Begin["MainFunctionPrivate"] and its reverse), and neither of them gets displayed on autocomplete. That enables you to have further organization inside of Private contexts and still shield those symbols from eyes that shouldn't see them. – Emilio Pisanty May 23 '16 at 16:16
• @Emilio Shouldn't that be posted as an Answer? – Mr.Wizard May 24 '16 at 12:51

This is sort of what the Private context is meant to be doing for you. You write that you

just need more contexts that can behave like Private context for organizational purposes,

and this can be achieved using subcontexts that use a Private mark. My normal instinct would be to put the helper functions to MainFunction inside a Private branch of the MainFunction context branch,

Begin["MainFunctionPrivate"]


but you can also do it the other way around and have a master Private branch with lots of sub-branches, as

Begin["PrivateMainFunction"]

• (+1) This is a viable alternative, but I guess it doesn't technically answer the question. – QuantumDot May 26 '16 at 13:12
• ... which is why I posted it as a comment to see if there were specific reasons why it didn't fit the bill. – Emilio Pisanty May 26 '16 at 16:25