8
$\begingroup$

By default, Mathematica displays variable names already assigned as black while new variables are displayed in blue. When executing Clear["Global`*"], variables that's already assigned will change from black to blue. However, if done via a Button:

CreatePalette[Button["Clear", Clear["Global`*"] ] ]

the variables will be cleared but their color will not be changed to blue, which looks confusing to me. How to remedy that?

$\endgroup$

1 Answer 1

6
$\begingroup$

I was digging around one day and I found appropriate function for this.

FrontEndExecute@FrontEnd`Private`GetUpdatedSymbolContexts[]; will help if you read a package or clear symbols from different place than the notebook interface.

CreatePalette[
 Button["Clear", 
   Clear["Global`*"]; 
   FrontEndExecute@FrontEnd`Private`GetUpdatedSymbolContexts[];
   ,
   ImageSize -> 100,
   Method    -> "Queued"

 ]
]

Keep in mind that it is undocumented so who knows what may happen :)

$\endgroup$
2
  • 1
    $\begingroup$ Works like a charm for me :-) Thanks! (tested on Mathematica ver. 10.0.2.0 on windows) $\endgroup$ Commented May 27, 2015 at 14:55
  • 1
    $\begingroup$ @egwenesedai By default Button is not queued so it may fail for more complex procedures by evaluating it prematurely. But it should be enough to use Method->"Queued". Depends of your needs and context ofc. Good luck. $\endgroup$ Commented May 27, 2015 at 14:57

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.