5
$\begingroup$

I'm actively developing a large codebase that I load every time I use Mathematica. I frequently quit my kernel and reload the codebase to incorporate new changes. I've created a custom menu by editing MenuSetup.tr to include menu items and keyboard shortcuts that allow me to quit the kernel and reload my codebase quickly and easily.

Unfortunately, the 'Quit' functionality no longer works in Mathematica 10. Both the "EvaluatorQuit" FrontEndToken and manually running KernelExecute[ToExpression["Quit[]"]] from a MenuItem cause the FrontEnd to crash (the code used in my MenuItem is derived from this thread). The same bits of code work fine when run directly from the FrontEnd.

There clearly still exists a viable method of quitting a kernel from a menu, because the 'Quit Kernel' submenu in the 'Evaluation' menu still functions fine without crashing the FrontEnd. Unfortunately, the way this is done seems to be hidden behind the "MenuListQuitEvaluators" token used to generate that submenu.

Any advice on how to get around this bothersome crashing behavior would be most welcome.

$\endgroup$
  • $\begingroup$ Was "EvaluatorQuit" working in version 9? I suspect that the issue is somewhat connected with introducing the service kernel in v.9: are you sure in which of two kernels the command Quit[] will be evaluated? $\endgroup$ – Alexey Popkov Aug 23 '14 at 21:25
  • $\begingroup$ "EvaulatorQuit" did not crash the FrontEnd in version 9 even when run from within a MenuItem. I wasn't aware of the distinction between the service kernel and the user kernel(s), but it certainly seems that "EvaluatorQuit" was operating on the user kernel rather than on the service kernel. The state of the user kernel is reset when the command is run (or Up/Down/OwnValues are lost at least). Has something changed w.r.t. the service/user kernel distinction in Mathematica 10? $\endgroup$ – bdot Aug 23 '14 at 22:05
  • $\begingroup$ I do not know for sure but it seems that the main user kernel now is more deeply involved in communication with the FrontEnd than it was earlier. This communication is needed for syntax highlighting, autocomplete suggestions etc. But the issue with "EvaluatorQuit" looks like a bug in any case. The Documentation page seems misleading: it states that ""EvaluatorQuit" requires a parameter, which can be the name of a kernel (evaluator) or Automatic for the default kernel," but the example given has no parameter. $\endgroup$ – Alexey Popkov Aug 23 '14 at 22:19
2
$\begingroup$

Please try using this:

FrontEndExecute[
 FrontEnd`AddMenuCommands[
  "MenuListQuitEvaluators", {MenuItem["AddMenu &Quit", "EvaluatorQuit", 
    MenuKey["q", Modifiers -> {"Control"}], System`MenuEvaluator -> Automatic]}]]

For version 10.0.0 under Windows using the menu item added by this does not crash the front end.

| improve this answer | |
$\endgroup$
  • $\begingroup$ (+1) I confirm that it works without crashing FrontEnd in v.10.0.0 under Win7 x64. $\endgroup$ – Alexey Popkov Aug 24 '14 at 11:28
  • $\begingroup$ Yep, this works for me as well. It's not quite as convenient as constructing my entire menu as a unit within MenuSetup.tr, but it will work. Thanks! $\endgroup$ – bdot Aug 25 '14 at 17:28
  • 1
    $\begingroup$ I implemented a Ctrl Q shortcut for quitting the kernel in V10. See here $\endgroup$ – Rolf Mertig Dec 11 '14 at 21:08
  • $\begingroup$ @Rolf I have been successfully using this simple code for that shortcut: Item[KeyEvent["q", Modifiers -> {Control}], "EvaluatorQuit"] (In KeyEventTranslations.tr.) $\endgroup$ – Mr.Wizard Dec 12 '14 at 16:27
  • $\begingroup$ @Mr.Wizard Sure, but that is not the same: it asks you if you want to quit. I do not want to get asked ... $\endgroup$ – Rolf Mertig Dec 12 '14 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.