How could user-defined function symbol such as f in
f[x_] = 2 x
or variable symbols such as lotto in
lotto = Table[2, {10}];
be colored automatically ?
In Syntax coloring on M8 no option is offered for this.
Only Local Variables or Global symbols that have no values assigned.
This is not exactly what you asked for, but it may be useful to you.
You can highlight symbols by context, using this method:
SetOptions[$FrontEndSession,
AutoStyleOptions -> {"SymbolContextStyles" -> {"highlight`" -> Green}}
]
AppendTo[$ContextPath, "highlight`"];
Now, when you create a symbol in the context highlight`
it will automatically be colored green:
highlight`lotto ;
and since highlight`
was appended to $ContextPath
, after that the symbol can be used plainly:
lotto
If you want all the symbols you create to automatically be highlighted, then set:
$Context = "highlight`"
After that, all new symbols you create will belong to the context highlight`
and will receive the color.
New means ones that have not been previously used in the session, or have been Remove
d.
It occurs to me that a better way to accomplish this, that avoids a possible "shadowing" problem, may be to set highlighting for the Global`
context itself. I have not considered the ramifications of this, but it can be done with this alone:
SetOptions[$FrontEndSession,
AutoStyleOptions -> {"SymbolContextStyles" -> {"Global`" -> Green}}
]
The context highlight`
is completely arbitrary, and you can have multiple contexts highlighted with different colors.
You can color the contexts of packages such as Units`
to distinguish which symbols belong to that package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With