In my copy of Mathematica 11.1,
SyntaxInformation[f] = {"ColorEqualSigns" -> {1, 1}}
colors like wrong options:
How do I make it not color like wrong options?
So I remembered running into this while answering an old SyntaxInformation
based question, but here's a more systematic way to get at it.
Note that this has been pointed out on the StackExchange both by Szabolcs, by jkuczm answering pretty much this exact question, and by Jacob Akkerboom citing jkuczm.
We can get all of the standard SyntaxInformation
patterns like so:
siData =
ToExpression[
Names["*"],
StandardForm,
Function[Null,
If[Length[Quiet[OwnValues[#]]] === 0 && !
System`Private`HasOwnCodeQ[#],
Thread[ToString[Unevaluated[#]] -> Keys@SyntaxInformation[#]],
{}
],
HoldAllComplete
]
] // Flatten // GroupBy[Last -> First];
Then look at the keys:
siData // Keys
{"ArgumentsPattern", "LocalVariables", "ColorEqualSigns", \
"OptionNames"}
And we see that curious, undocumented "OptionNames"
thing.
We can see what functions have that:
withOpsNames = siData["OptionNames"]
{"CDFDeploy", "Cell", "ChoiceDialog", "CoefficientArrays", \
"CopyFile", "CreateDialog", "CreateDocument", "CreateNotebook", \
"CreatePalette", "CreateScheduledTask", "CreateWindow", \
"DefineInputStreamMethod", "DialogInput", "DialogNotebook", \
"DirectedEdges", "DocumentNotebook", "DumpSave", "Dynamic", \
"DynamicBox", "DynamicModuleBox", "DynamicWrapper", \
"DynamicWrapperBox", "ExpressionCell", "GraphAssortativity", \
"GroebnerBasis", "Input", "InputString", "LibraryFunctionLoad", \
"MessageDialog", "Notebook", "NotebookPut", "NotebookRead", \
"Notebooks", "PaletteNotebook", "PopupWindow", "Printout3D", \
"Rasterize", "ResetScheduledTask", "RunScheduledTask", "Style", \
"StyleBox", "SystemOpen", "TextCell", "URLBuild", "URLFetch", \
"URLFetchAsynchronous", "URLParse", "URLQueryDecode", \
"URLQueryEncode", "URLResponseTime", "URLSave", \
"URLSaveAsynchronous", "WaitAsynchronousTask", "WhenEvent", \
"$FrontEndSession"}
And then just for fun we'll find those options that are in the syntax info, but aren't in the basic Options
list and vice versa:
opsNamesComplement =
Block[{
$Context = "Global`",
$ContextPath = {"BoxForm`", "System`", "Global`"}
},
AssociationThread[
withOpsNames ->
ToExpression[withOpsNames, StandardForm,
{
Complement[Keys@Options[#],
ToExpression@Lookup[SyntaxInformation[#], "OptionNames", {}]],
Complement[
ToExpression@
Lookup[SyntaxInformation[#], "OptionNames", {}],
Keys@Options[#]
]
} &
]
]
];
And here's some fun stuff from there:
Select[opsNamesComplement,
Length@#[[2]] > 0 && Length@Flatten@# < 10 &]
<|"Cell" -> {{Clickable, FillForm, Name,
VariableChangesAreEdits}, {BoxForm`Clickable, BoxForm`FillForm,
BoxForm`Name, BoxForm`VariableChangesAreEdits}},
"CopyFile" -> {{OverwriteTarget}, {"MIMEType", Automatic}},
"NotebookRead" -> {{CellContext}, {"WrapBoxesWithBoxData"}},
"StyleBox" -> {{Clickable, FillForm,
VariableChangesAreEdits}, {BoxForm`Clickable, BoxForm`FillForm,
BoxForm`VariableChangesAreEdits}}|>
Which pops out, e.g., "MIMType"
for CopyFile
(an option I use all the time to make things auto-downloading in the cloud).
And note, too, what the standard CopyFile
sytax info is:
SyntaxInformation[CopyFile]
{"ArgumentsPattern" -> {_, _, OptionsPattern[]},
"OptionNames" -> {Automatic, "\"MIMEType\""}}
Which I think shows us a way to prevent that red coloring (I'm gonna bet the Automatic
is just inheriting the base options):
SyntaxInformation[f] = {
"ColorEqualSigns" -> {1, 1},
"OptionNames" -> {Automatic, "Option1", "Option2", "Option3"}
}
So if you know the potential names of the options, you don't need to set Options
at all. If you don't know the potential names and have no way of guessing them... Well then we have a problem.
Options[f] = {myOption->..., mySecondOption->...}
is not an answer? $\endgroup$f
actually takes bunch of arbitrary rules as its argument. While syntactically equivalent to options, there isn't a finite set of possibilities for the lhs of the rules. $\endgroup$