1

I asked the following question before, but I do not think it has been fully answered.

By default, we use Shift+Enter to evaluate the current cell, and use Enter to get a new line. Is there a way to switch the two, i.e., use Enter to evaluate the current cell, and use Shift+Enter to get a new line (like in Maple)?

The answer is related to modifying the file "KeyEventTranslations.tr," part of which is

(* Evaluation *)
Item[KeyEvent["Enter"], "EvaluateCells"],
Item[KeyEvent["KeypadEnter"], "EvaluateCells"], 
Item[KeyEvent["Return", Modifiers -> {Shift}], "HandleShiftReturn"],
Item[KeyEvent["KeypadEnter", Modifiers -> {Shift}], "EvaluateNextCell"],    
Item[KeyEvent["Enter", Modifiers -> {Shift}], "EvaluateNextCell"], 
Item[KeyEvent["Return", Modifiers -> {Shift, Control}], Evaluate[All]],
Item[KeyEvent["Return", Modifiers -> {Option}], "SimilarCellBelow"], 
Item[KeyEvent["Escape"], "ShortNameDelimiter"], 

I tried many different ways to modify this file, but I never succeeded. I have many confusions about this file.

  1. The first item above is Item[KeyEvent["Enter"], "EvaluateCells"]. It seems that Enter is already used to evaluate cells, but it is not. I tried to modify this line as Item[KeyEvent["Enter"], "EvaluateNextCell"], Item[KeyEvent["Return"], "EvaluateCells"], and Item[KeyEvent["Return"], "EvaluateNextCell"], but in any case, Enter cannot evaluate the cell. (I am using a Windows laptop computer)

  2. If I switch EvaluateNextCell and Linebreak in Item[KeyEvent["Enter", Modifiers -> {Shift}], "EvaluateNextCell"] and Item[KeyEvent["Return"], "Linebreak"] (according to Jacob's answer), then both Shift+Enter and Enter are for a line break.

  3. What is difference between EvaluateCells and EvaluateNextCell? What does HandleShiftReturn mean? In a Windows laptop, does Return play a role?

  4. According to the link given by Szabolcs, we can evaluate the following in a notebook.

    SetOptions[EvaluationNotebook[], NotebookEventActions ->
    {"ReturnKeyDown" :>
    FrontEndTokenExecute["EvaluateCells"],
    {"MenuCommand", "HandleShiftReturn"} :>
    FrontEndTokenExecute["Linebreak"]}]
    

    This works for only one notebook in which the above command is evaluated, not for all notebooks. A puzzle to me is that even if we delete the above command, and reopen this notebook, the function of Enter and Shift+Enter is still switched (only for this notebook). I wonder where this information is stored.

Could you give a clear answer on how to modify the file "KeyEventTranslations.tr"?

renphysics
  • 1,560
  • 1
  • 10
  • 19
  • 1
    https://groups.google.com/d/msg/comp.soft-sys.math.mathematica/OzxQ70lH2rY/rzF9Pg3vJewJ – Szabolcs Mar 17 '14 at 20:02
  • 2
    SystemOpen@First@FileNames["KeyEventTranslations.tr", $InstallationDirectory, 8], items Item[KeyEvent["Enter", Modifiers -> {Shift}], "EvaluateNextCell"] and Item[KeyEvent["Return"], "Linebreak"]. Make a backup! – Jacob Akkerboom Mar 17 '14 at 20:11
  • On OS X, [Return] inserts a newline and [Enter], which is different key, produces evaluation. – m_goldberg Mar 17 '14 at 22:09
  • Related (or duplicate of): 7611, 4094, and/or 6224 and possibly many others. – Sjoerd C. de Vries Mar 17 '14 at 22:14
  • 1
    If you evaluate a cell, the cursor ismoved between the cells. And if there is another cell it will not be evaluated by "evaluateCells" but by "EvaluateNextCell" will. – Kuba Mar 28 '14 at 11:10
  • 1
    @renphysics, Regarding your flag, your update only mentions Szabolcs's link. I'll try to address the questions you ask in it: 1) It works only for that notebook because it explicitly sets it only for the EvaluationNotebook[]. You can set it for all notebooks by changing that to $FrontEnd 2) These settings are stored in the object's options and persists across sessions. See Options@EvaluationNotebook[]. – rm -rf Mar 28 '14 at 19:49
  • @rm -rf, Thanks, changing EvaluationNotebook[] to $FrontEnd works. However, my original question was only the quoted part at the beginning (I edited more times), and I am highly puzzled by 1-3, because I could not find any reference to explain the file "KeyEventTranslations.tr" (modifying this file should also be a way). Also, is there a reference that explains what the things like ReturnKeyDown and HandleShiftReturn mean in 4? – renphysics Mar 28 '14 at 22:03

0 Answers0