在Mathematica 7中取消/注释掉代码的键盘快捷键? [英] Keyboard shortcut to Un/Comment out code in Mathematica 7?

查看:743
本文介绍了在Mathematica 7中取消/注释掉代码的键盘快捷键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用于注释/取消注释一段代码的键盘快捷方式在其他编程IDE中对于Java,.Net等语言是很常见的.在尝试反复试验以暂时注释掉和取消注释行,单词和代码部分以找出有效的方法和无效的方法时,我发现这是一种非常有用的技术.

A keyboard shortcut to comment/uncomment out a piece of code is common in other programming IDE's for languages like Java, .Net. I find it a very useful technique when experimenting through trial and error to temporarily comment out and uncomment lines, words and parts of the code to find out what is and isn't working.

我在版本7的Mathematica前端找不到任何此类键盘快捷键.我知道可以通过选择代码,右键单击鼠标并从出现的菜单中选择取消/注释"来注释掉代码,但这是编码时太慢.

I cannot find any such keyboard shortcut on the Mathematica front end in version 7. I know that it is possible to comment out code by selecting the code, right mouse click and select Un/Comment from the menu that appears but this is too slow while coding.

我尝试使用菜单键 菜单在键盘上,但是Mathematica前端不像其他应用程序那样响应或识别此键,这可能允许使用组合键进行注释.别人可以验证这不是我的机器独有的,并且该密钥不能被mathematica识别.我查看了这个问题,并查看了KeyEventTranslations.tr文件,但我认为没有任何问题创建快捷方式来执行此操作的方法(?).我应该忍受吗?

I tried to access this using the menu key Menu on the keyboard but Mathematica frontend doesn't respond to or recognise this key unlike other applications, this could have allowed a key combination for commenting. Can someone else verify that this isn't unique to my machine and that the key isn't recognised by mathematica. I looked at this question and looked in the KeyEventTranslations.tr file but I don't think there is any way to create a shortcut to do this(?). Should I just live with it?

还有其他建议吗?

(我已经看到有一个Emacs版本的mathematica,我从未尝试过Emacs或这个Mma版本,并想象它会具有这种能力,但是不希望麻烦安装它的麻烦和不确定性.另外,我会猜测Wolfram Workbench可以做到这一点,但这可能不值得为此投资.)

(I have seen there is an Emacs version of mathematica, I have never tried Emacs or this Mma version and imagine that it would have this ability but would prefer not to go to the trouble and uncertainty of installing it. Also I would guess that the Wolfram Workbench could do this, but that may not be worth the investment just for this.)

推荐答案

如果愿意编辑Mathematica系统文件MenuSetup.tr,则可以在Mathematica 7.0.x中安装快捷方式.您可以在KeyEventTranslations.tr文件所在的位置找到它(即,在"SystemFiles/FrontEnd/TextResources/平台"下的安装中).在MenuSetup.tr中,在 Edit 菜单的定义下找到以下行:

You can install the shortcut in Mathematica 7.0.x if you are willing to edit the Mathematica system file MenuSetup.tr. You can find it in the same location as the KeyEventTranslations.tr file (i.e. in the installation under "SystemFiles/FrontEnd/TextResources/platform"). In MenuSetup.tr, locate the following line under the definition of the Edit menu:

MenuItem["Check &Balance", "Balance", MenuKey["B", Modifiers->{"Control", "Shift"}]],

立即在该行下方插入以下内容:

Immediately below that line, insert the following:

MenuItem["Un/C&omment Selection", KernelExecute[FE`toggleComment[]], MenuKey["/", Modifiers->{"Command"}], MenuEvaluator -> Automatic, Method -> "Queued"],

Un/注释选择命令现在在 Edit 菜单下可用,键盘快捷键 Cmd -/ Alt -/取决于您的平台-就像在预先安装了此命令的Mathematica 8中一样.

The Un/Comment Selection command is now available under the Edit menu, with the keyboard shortcut Cmd-/ or Alt-/ depending on your platform -- just like in Mathematica 8 where this command comes pre-installed.

请阅读有关黑客入侵Mathematica安装文件的通常免责声明-不提供任何担保:)

Please take as read the usual disclaimers about hacking the Mathematica installation files -- no warranty is offered :)

我不知道有什么方法可以将此功能映射到涉及 Menu 键的某些快捷方式.

I do not know of any way to map this function to some shortcut involving the Menu key.

快捷键,无菜单

前面的步骤通过安装新的菜单项来模仿Mathematica 8的功能.如果您希望菜单保持不变,则可以将快捷方式安装在KeyEventTranslations.tr中.添加以下行:

The preceding steps mimic what Mathematica 8 does by installing a new menu item. If you prefer to leave the menus unchanged, then you can install the shortcut in KeyEventTranslations.tr instead. Add the following line:

Item[KeyEvent["/", Modifiers->{Command}], KernelExecute[ToExpression["FE`toggleComment[]"]], MenuEvaluator -> Automatic, Method -> "Queued"]

如果该行不是列表中的最后一项,则需要在该行的末尾添加一个逗号.

You'll need a comma on the end of that line if it is not the last item in the list.

这篇关于在Mathematica 7中取消/注释掉代码的键盘快捷键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆