4
$\begingroup$

The example below shows that the symbol test`MyFunction is still in blue, which suggests that it is not defined. The color is defined in menu Edit > Preferences> Appearance > SyntaxColoring > Global symbols that have no value assigned.

context`MyFunction[x : _] := x^2
$ContextAliases["test`"] = "context`"
test`MyFunction[5]

Symbol Coloring

How can the front-end be informed about $ContextAliases so that test`MyFunction is black instead of blue?

Note that AppendTo[$ContextPath,"context`"] does not help.

$\endgroup$

1 Answer 1

2
$\begingroup$

As a trying of possible solutions, there is an ad-hoc method from the definition of DeclareKnownSymbols,

MathLink`CallFrontEnd@FrontEnd`UpdateKernelSymbolContexts[
    "test`",
    {},
    {{"test`",{},{},"MyFunction",{}}},
    Directory[],
    <||>
]

then

enter image description here

To automate the coloring you can further build a function by

  1. get all the symbols of context`* by Names["context`*"];
  2. color them by UpdateKernelSymbolContexts;
  3. dynamically evaluate this function by monitoring Names["context`*"].
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.