zoukankan      html  css  js  c++  java
  • Mathematica 定制快捷键

    和汉化的原理是一致的

    来源:http://stackoverflow.com/questions/5604837/keyboard-shortcut-to-un-comment-out-code-in-mathematica-7

    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.)

    2 Answers

    You can install the shortcut in Mathematica 7.0.x if you are willing to edit the Mathematica system fileMenuSetup.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"],
    

    The Un/Comment Selection command is now available under the Edit menu, with the keyboard shortcutCmd-/ 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:

    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.

  • 相关阅读:
    工作
    失败
    理想和一些未来的计划
    安静
    重新开始
    如何度过周末
    放假
    WPF学习笔记-数据采集与监控项目01-登录界面
    VS2017-断点感叹号问题,调试代码显示“当前无法命中断点,还没有为该文档加载任何符号”
    WPF-MVVM模式-表现层的UI框架【学习笔记】
  • 原文地址:https://www.cnblogs.com/dabaopku/p/2012870.html
Copyright © 2011-2022 走看看