在 Mathematica 7 中取消/注释代码的键盘快捷键?
用于注释/取消注释一段代码的键盘快捷键在 Java、.Net 等语言的其他编程 IDE 中很常见。我发现在通过反复试验进行试验时,临时注释和取消注释行、单词和部分代码以找出有效和无效的内容是一种非常有用的技术。
我在版本 7 的 Mathematica 前端找不到任何这样的键盘快捷键。我知道可以通过选择代码、单击鼠标右键并从出现的菜单中选择取消/注释来注释代码,但这太慢了编码。
我尝试使用键盘上的 菜单键 菜单 来访问它但与其他应用程序不同,Mathematica 前端不会响应或识别此键,这可能允许使用组合键进行注释。其他人可以验证这不是我的机器所独有的,并且该密钥未被mathematica识别。我查看了这个 问题 并查看了 KeyEventTranslations.tr 文件,但我认为没有任何问题创建快捷方式来执行此操作的方法(?)。我应该忍受它吗?
还有其他建议吗?
(我见过有一个 Emacs 版本的 mathematica,我从来没有尝试过 Emacs 或这个 Mma 版本,并想象它会有这种能力,但宁愿不去安装它的麻烦和不确定性。而且我猜想Wolfram Workbench 可以做到这一点,但可能不值得为此进行投资。)
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.
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.
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?
Any other suggestions?
(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.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您愿意编辑 Mathematica 系统文件
MenuSetup.tr
,则可以在 Mathematica 7.0.x 中安装该快捷方式。您可以在与KeyEventTranslations.tr
文件相同的位置找到它(即在“SystemFiles/FrontEnd/TextResources/platform”下的安装中)。在MenuSetup.tr
中,在“编辑”菜单的定义下找到以下行:在该行的正下方插入以下内容:
取消/注释选择 em> 命令现在可以在编辑菜单下使用,使用键盘快捷键Cmd-/或Alt-< kbd>/ 取决于您的平台 - 就像在 Mathematica 8 中预安装了此命令一样。
请阅读有关破解 Mathematica 安装文件的常见免责声明 - 不提供任何保证:)
我不知道有什么方法可以将此功能映射到涉及 Menu 键的某些快捷方式。
快捷键,无菜单
前面的步骤通过安装新菜单项来模仿 Mathematica 8 的操作。如果您希望保持菜单不变,则可以在
KeyEventTranslations.tr
中安装快捷方式。添加以下行:如果它不是列表中的最后一项,则需要在该行末尾加一个逗号。
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 theKeyEventTranslations.tr
file (i.e. in the installation under "SystemFiles/FrontEnd/TextResources/platform"). InMenuSetup.tr
, locate the following line under the definition of the Edit menu:Immediately below that line, insert the following:
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.
Please take as read the usual disclaimers about hacking the Mathematica installation files -- no warranty is offered :)
I do not know of any way to map this function to some shortcut involving the Menu key.
Shortcut Key, No Menu
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:You'll need a comma on the end of that line if it is not the last item in the list.
选择代码并按以下键之一:
注意:
Select the code and press one of the following:
Notes:
以下是
KeyEventTranslations.tr
文件的代码,它将注释掉代码。我还在为另一半努力。这会将其绑定到 Alt+/,就像在 Mathematica 8 中一样。
Here is code for your
KeyEventTranslations.tr
file that will comment out code. I am still working on the other half.This binds it to Alt+/ as it is in Mathematica 8.