The front-end is great. I enjoy being able to play with it directly from my code. It's richly customizable and reasonably intuitive to work with. On the other hand, the subset of front-end functionality that is explicitly documented only covers like 60% of my desired use cases (and if I were to use it exactly as suggested it'd be slow)
In particular, one thing I've wanted to do recently is add in more autocompletions directly from my code.
To do basic function autocompletions, I'm using a method that I first heard about from Szabolcs which he posted here.
Functionality 1: Building .trie files
On the other hand, I would also like to be able to use a .trie file for these. This is clearly how these are handled internally. An example of what is contained in these tries can be found like so:
FrontEndExecute@CA`CADumpTriePacket@
FileNames["*.trie",
CurrentValue[$FrontEndSession, {PrivatePaths,
"AutoCompletionDataBase"}], 2][[1]]
{"Entities", "EntityCount", "Classes", "EntityClassCount", \
"SampleEntities", "SampleEntityClasses", "EntityCanonicalNames", \
"PropertyCanonicalNames", "EntityClassCanonicalNames", \
"RandomEntities", "RandomEntityClasses"}
Unfortunately I don't know how to build them. If someone could enlighten me I would appreciate it.
Functionality 2: Adding in custom function templates
The next part that I wanted to be able to control was the function templates. When one sets a usage message, a function template interface comes into being with it. For instance, we set a usage:
funcThatNoise::usage = "funcThatNoise[a, b, c] is a func";
And now typing funcThatNoise
and pressing Command-Shift-K will pop up a template for using the function:
I was hoping I could use FrontEnd`AddFunctionTemplateInformationToFunctions
to add these without defining a "usage"
message, but trying the obvious things (in the context of what I found about FrontEnd`AddUsedToGenerateSideEffectGraphicsFunctions
here), e.g. any of the following:
FrontEndExecute@
FrontEnd`AddFunctionTemplateInformationToFunctions[
{"Global`",
{
{
"myFunc",
FE`GetTemplateAndUsage["Plot"] /.
s_String :> StringReplace[s, "Plot" -> "myFunc"]
}
}
}
];
FrontEndExecute@
FrontEnd`AddFunctionTemplateInformationToFunctions[
{"Global`",
{
{
"myFunc",
FE`GetTemplateAndUsage["Plot"][[1]] /.
s_String :> StringReplace[s, "Plot" -> "myFunc"]
}
}
}
];
FrontEndExecute@
FrontEnd`AddFunctionTemplateInformationToFunctions[
FE`GetTemplateAndUsage["Plot"] /.
s_String :> StringReplace[s, "Plot" -> "myFunc"]
];
FrontEndExecute@
FrontEnd`AddFunctionTemplateInformationToFunctions[
FE`GetTemplateAndUsage["Plot"][[1]] /.
s_String :> StringReplace[s, "Plot" -> "myFunc"]
]
fails to provide me with any type of template. So how can I do this?
Functionality 3: Adding Option autocompletions
The final thing I want to know how to use is the OptionValue
autocompletions. I know there's a file I could tweak but that's a bit heavy. It's much nicer to be able to just do this on the fly. Again, I thought I had a possible option with FrontEnd`AddOptionInformationToFunctions
but it seems to only handle the option names. Even worse there's no way to remove the coloring it adds (it's clearly how the "OptionNames"
parameter to SyntaxInformation
works).
Obligatory note about undocumented functionality
Yes, I understand undocumented things aren't robust, tend to crash the FE, and are subject to change at any moment. Despite this, I think there are too many parts of Mathematica to just ignore the undocumented ones. Many of the best pieces of functionality in Mathematica are undocumented or minimally documented.
I'd appreciate anything anyone can tell me about how these work.