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$
3
  • $\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$ Commented Aug 23, 2014 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
    Commented Aug 23, 2014 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$ Commented Aug 23, 2014 at 22:19

1 Answer 1

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.

$\endgroup$
7
  • $\begingroup$ (+1) I confirm that it works without crashing FrontEnd in v.10.0.0 under Win7 x64. $\endgroup$ Commented Aug 24, 2014 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
    Commented Aug 25, 2014 at 17:28
  • 1
    $\begingroup$ I implemented a Ctrl Q shortcut for quitting the kernel in V10. See here $\endgroup$ Commented Dec 11, 2014 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
    Commented Dec 12, 2014 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$ Commented Dec 12, 2014 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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