Is there a command / menu entry / keyboard shortcut to evaluate all cells above / up to the current cursor position? I have the feeling I am missing something elementary here...
Addendum: In fact, it is more about selection of those cells, evaluation is not the problem as such.
Answer
One possibility is to modify your personal KeyEventTranslations.tr
(only tested on Windows). Evaluate the following, then restart Mathematica, then Ctrl+Shift+Home will select all cells above the insertion point.
For 9.0.1. use: Import["http://www.mertig.com/shortcuts.m"]
mymenuitems="
(* Select all cells upwards *)
Item[KeyEvent[\"Home\", Modifiers -> {Control, Shift}],
KernelExecute[
Module[{ enb = EvaluationNotebook[],
tag = StringJoin[\"tmp\", ToString[Round[AbsoluteTime[]/$TimeUnit]]],editable
},
editable = ReplaceAll[Editable, Options[enb, Editable]];
SetOptions[enb, Editable -> False];
SelectionMove[enb, Previous, Cell, AutoScroll -> False];
MathLink`CallFrontEnd[FrontEnd`SelectionAddCellTags[enb, {tag}]];
SelectionMove[enb, Before, Notebook, AutoScroll -> False];
SelectionMove[enb, Next, Cell, AutoScroll -> False];
While[FreeQ[ReplaceAll[CellTags,Options[NotebookSelection[]]], tag],
MathLink`CallFrontEnd[FrontEnd`SelectionAddCellTags[enb, {tag}]];
SelectionMove[enb, Next, Cell, AutoScroll -> False]
];
NotebookFind[enb, tag, All, CellTags, AutoScroll -> False];
MathLink`CallFrontEnd[FrontEnd`SelectionRemoveCellTags[enb, {tag}]];
SetOptions[enb, Editable -> editable]
]
], MenuEvaluator -> Automatic ]
";
With[{os = Switch[$OperatingSystem,"MacOSX","Macintosh","Windows","Windows","Unix","X"]},
Quiet@CreateDirectory@FileNameJoin[{$UserBaseDirectory,"SystemFiles","FrontEnd","TextResources",os}];
mykeyeventtrans=FileNameJoin[{$UserBaseDirectory,"SystemFiles","FrontEnd","TextResources",os,"KeyEventTranslations.tr"}];
(*If[FileExistsQ[mykeyeventtrans],DeleteFile@mykeyeventtrans];*)
If[!FileExistsQ[mykeyeventtrans],
CopyFile[FileNameJoin[{$InstallationDirectory,"SystemFiles","FrontEnd","TextResources",os,"KeyEventTranslations.tr"}],mykeyeventtrans]
]];
keytext=Import[mykeyeventtrans,"Text"];
mykeytext=StringReplace[keytext,"EventTranslations[{":>StringJoin["EventTranslations[{\n(* User defined *)\n",mymenuitems,",\n"]];
Export[mykeyeventtrans,mykeytext,"Text"];
Comments
Post a Comment