I use the command

ClearAll["Global*"]

so much that I thought it would be nice to have a function that called it. Since by default ClearAll requires an argument, I decided to overload it and have it so when no arguments are passed to ClearAll it clears Global.

Unprotect[ClearAll]

ClearAll[]:=ClearAll["Global*"];

Protect[ClearAll]

However, mathematica still expects an argument to the function, resulting in this

It still works fine, but is there any way to remove the red arrow? I've tried

SyntaxInformation[ClearAll] := {"ArgumentsPattern" -> {___}} which should allow it to accept 0 arguments, but it still complains about it.

• But if you defined ClearAll[] in global context, would not then calling ClearAll[] first time clears your own ClearAll[] that you just defined? Since ClearAll from the system is in the system context Context[ClearAll]. I agree with you, it will be nice to have a system command to clear all, without having to specify the context. I always mixes up the * and the  order – Nasser Jul 16 '14 at 3:26
• In general, you might want to define it as ClearAll[] := ClearAll[$Context <> "*"] – rm -rf Jul 16 '14 at 3:36 • @rm-rf @Nasser I actually put my overloaded ClearAll[] into a package which is loaded on startup. As part of the ClearAll[] definition I reload that package after the clear. That information doesn't really have to do with the question though, so I left it out. – 1110101001 Jul 16 '14 at 3:40 • @Nasser Since ClearAll is in the System  context any definitions you attach to it will also be in the System  context. – Mr.Wizard Jul 16 '14 at 6:49 • @rm-rf "ClearAll::ssym:$Context<>* is not a symbol or a string. >>" -- you probably want ClearAll @@ {\$Context <> "*"} – Mr.Wizard Jul 16 '14 at 7:02

In version 10 under Windows I am unable to reproduce the problem you describe:

Unprotect[ClearAll];

ClearAll[] := ClearAll["Global*"]

SyntaxInformation[ClearAll] = {"ArgumentsPattern" -> {___}};

Protect[ClearAll]


In the Notebook:

Without the definition above:

• OP might have issued the SyntaxInformation.. command after doing the Protect like you did? – Nasser Jul 16 '14 at 6:59
• @Nasser No, I put it after Unprotect – 1110101001 Jul 16 '14 at 6:59
• corrected what I meant above. I typed it wrong. – Nasser Jul 16 '14 at 7:00
• It seems that typing all commands directly into the notebook works, but putting it into a .m file loaded at startup causes it to not work... – 1110101001 Jul 16 '14 at 7:01
• @user2612743 That actually makes some sense, as something later in the loading process may be resetting SyntaxInformation[ClearAll]. Have you confirmed that it is as you set it after Mathematica is up and running? – Mr.Wizard Jul 16 '14 at 7:03