4

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.

Domen
  • 23,608
  • 1
  • 27
  • 45
ScotMartin
  • 191
  • 5

1 Answers1

2

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`*"].
Lacia
  • 2,253
  • 3
  • 19