ClearAll [“Global` *”]自动插入

时间:2014-06-27 01:38:38

标签: variables wolfram-mathematica clear

我不知道在哪里可以找到并调整配置文件,让Mathematica插入ClearAll [" Global` *"] 在每个新笔记本的开头。我怎么能这样做,而不是每次打开新笔记本时都要输入它?

1 个答案:

答案 0 :(得分:0)

AFAIK无法更改默认的新笔记本。但是可以添加自定义键盘快捷键和/或菜单命令,这将创建新的Notebook,其中包含您需要的任何内容。例如,您可以添加菜单项" New my Notebook"在"文件 - >下新"子菜单并指定Ctrl+Shift+N键盘快捷键来评估它(此修改仅在当前FrontEndSession期间保留),方法是评估以下内容(取自herehere):

FrontEndExecute[
 FrontEnd`AddMenuCommands[
  "New", {MenuItem["My new Notebook", 
    System`KernelExecute[
     CreateDocument[ExpressionCell[Defer@ClearAll["Global`*"], "Input"]]], 
    FrontEnd`MenuKey["N", FrontEnd`Modifiers -> {"Control", "Shift"}],
     System`MenuEvaluator -> Automatic]}]]

现在按Ctrl+Shift+N将打开新的Notebook窗口,其中"Input"单元格已包含ClearAll["Global`*"]。如果您将FrontEnd`Modifiers -> {"Control", "Shift"}替换为FrontEnd`Modifiers -> {"Command"},则键盘组合将为Alt+N

有关如何使此更改成为永久更改的信息,请参阅this MathGroups帖子:

  

您可以使用...

完全重置菜单      

FrontEndExecute [FrontEnd`ResetMenusPacket [{自动}]]

     

你会得到一些丑陋的闪烁,但那会有效。你也可以   可以找到的前端init.m中的AddMenuCommands函数   ConfigurationPath选项中指定的路径上的某个位置。在   在这种情况下,init.m文件将在FE启动时被执行,   而不是内核,因此它不会影响您启动或启动多少内核   退出。

所以你需要在init.m选项给出的路径之一中创建ConfigurationPath文件:

Options[$FrontEnd, ConfigurationPath][[1, 2]]
{FrontEnd`FileName[{$InstallationDirectory, "Configuration", "FrontEnd"}], 
 FrontEnd`FileName[{$UserBaseDirectory, "Autoload", _, "Configuration", "FrontEnd"}], 
 FrontEnd`FileName[{$BaseDirectory, "Autoload", _, "Configuration", "FrontEnd"}], 
 FrontEnd`FileName[{$InstallationDirectory, "AddOns", "Autoload", _, "Configuration", "FrontEnd"}]}

其中一些路径包含空白(_),这是空的,但似乎意味着任何名称(我没有检查过这个)。

另一种永久更改此方式的方法是修改MenuSetup.tr文件,但该文件为not recommended

P.S。我建议您将来在专用网站上询问您的 Mathematica 相关问题,他们会在那里得到更多关注:

https://mathematica.stackexchange.com/