7

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?

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
egwene sedai
  • 2,355
  • 16
  • 24

1 Answers1

6

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 :)

Kuba
  • 136,707
  • 13
  • 279
  • 740
  • 1
    Works like a charm for me :-) Thanks! (tested on Mathematica ver. 10.0.2.0 on windows) – egwene sedai May 27 '15 at 14:55
  • 1
    @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. – Kuba May 27 '15 at 14:57