Why doesn't running ClearAll["Global`*"] from a custom Palette update local variables colors?
Asked Answered
B

1

4

I created a custom palette, with an ActionMenu that executes ClearAll["Global`*"]. It performs the desired action, but the frontend doesn't instantly update the colors from black to blue (standard), as it happens when ClearAll["Global`*"] is executed directly from a notebook cell (it only updates after something else has been executed). Is there a way to initiate a refresh of the frontend display status?

EDIT: Apparently, the same happens when I load a package from a palette (blue doesn’t immediately update to black).

Biysk answered 11/8, 2011 at 7:51 Comment(2)
I think that the notebook can't check the status of symbols all the time - so it only does it when it knows it's in use, like when you move the cursor. Is this issue a big problem for you? (Aside: all SO posts are automatically signed with your name in the bottom-right corner, so it's preferred if you don't add it to the post.)Disciple
Not an enormous problem, but I sometime use the ClearAll to find instances of my functions, and so this palette would simplify my actions, but not greatly if I need to do something else to get the different color. reRemoved my signature (I thought I was losing my mind when you first removed because I was certain I had putted it there…)Biysk
L
6

Not exactly elegant, but it works (the main loop has to be called once after ClearAll):

ActionMenu["Clear", 
   {"Clear global variables" :> (ClearAll["Global`*"]; 
         Block[{nb}, nb = CreateDocument[ExpressionCell[42, "Input"], 
                Visible -> False]; SelectionMove[nb, All, Notebook]; 
            SelectionEvaluate[nb]; NotebookDelete[nb];])}]

Of course, one should use the new Mathematica 8 NotebookEvaluate function, but it seems not to work here (i.e.,

ActionMenu["Clear", 
   {"Clear global variables" :> (ClearAll["Global`*"]; 
         Block[{nb}, nb = CreateDocument[ExpressionCell[42, "Input"], 
                Visible -> False]; NotebookEvaluate[nb]; 
     NotebookDelete[nb];])}]

gives an error message

Could not process unknown packet "1".
Lily answered 11/8, 2011 at 9:54 Comment(1)
Rolf, welcome to StackOverflow! Always good to get another knowledgeable Mathematica user in our community. Hope you'll enjoy it here. As to your answer: I get the same error for the second piece. The first one works, but also generates messages: "ClearAll::clloc: Cannot clear local variable result. >>"Waters

© 2022 - 2024 — McMap. All rights reserved.