Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

When developing some new code (eg. a function to analyse something) I usually make a .m and .nb file. The code goes in to .m is then called from the .nb.

But sometimes I forget to run the package after saving and then spend some time wondering why my code changes don't have the desired effect.

Is there a way to run a package automatically after it's saved?

Basically I would like that when I press [Ctrl]+S the package is saved and that the effect of this button being pressed is achieved.

Mathematica graphics

Currently I put Import["MyPackage.m"] at the top of the evaluation cell I'm currently working on in the notebook. Perhaps I could also abuse $Pre for this, but then the package would get imported on every cell evaluation (which is a bit needles).

EDIT

Well, this is what I have so far based on Chirs'sChirs's answer

FrontEndExecute[ FrontEnd`AddMenuCommands[ "Save", {Delimiter, MenuItem["Save and Run &Package", FrontEnd`KernelExecute[NotebookSave[SelectedNotebook[]]; If[FileExtension[NotebookFileName[SelectedNotebook[]]] == "m",(*then*) Get[NotebookFileName[SelectedNotebook[]]]; ]; ], MenuKey["S", Modifiers -> {"Control"}], System`MenuEvaluator -> Automatic]}]] 

When developing some new code (eg. a function to analyse something) I usually make a .m and .nb file. The code goes in to .m is then called from the .nb.

But sometimes I forget to run the package after saving and then spend some time wondering why my code changes don't have the desired effect.

Is there a way to run a package automatically after it's saved?

Basically I would like that when I press [Ctrl]+S the package is saved and that the effect of this button being pressed is achieved.

Mathematica graphics

Currently I put Import["MyPackage.m"] at the top of the evaluation cell I'm currently working on in the notebook. Perhaps I could also abuse $Pre for this, but then the package would get imported on every cell evaluation (which is a bit needles).

EDIT

Well, this is what I have so far based on Chirs's answer

FrontEndExecute[ FrontEnd`AddMenuCommands[ "Save", {Delimiter, MenuItem["Save and Run &Package", FrontEnd`KernelExecute[NotebookSave[SelectedNotebook[]]; If[FileExtension[NotebookFileName[SelectedNotebook[]]] == "m",(*then*) Get[NotebookFileName[SelectedNotebook[]]]; ]; ], MenuKey["S", Modifiers -> {"Control"}], System`MenuEvaluator -> Automatic]}]] 

When developing some new code (eg. a function to analyse something) I usually make a .m and .nb file. The code goes in to .m is then called from the .nb.

But sometimes I forget to run the package after saving and then spend some time wondering why my code changes don't have the desired effect.

Is there a way to run a package automatically after it's saved?

Basically I would like that when I press [Ctrl]+S the package is saved and that the effect of this button being pressed is achieved.

Mathematica graphics

Currently I put Import["MyPackage.m"] at the top of the evaluation cell I'm currently working on in the notebook. Perhaps I could also abuse $Pre for this, but then the package would get imported on every cell evaluation (which is a bit needles).

EDIT

Well, this is what I have so far based on Chirs's answer

FrontEndExecute[ FrontEnd`AddMenuCommands[ "Save", {Delimiter, MenuItem["Save and Run &Package", FrontEnd`KernelExecute[NotebookSave[SelectedNotebook[]]; If[FileExtension[NotebookFileName[SelectedNotebook[]]] == "m",(*then*) Get[NotebookFileName[SelectedNotebook[]]]; ]; ], MenuKey["S", Modifiers -> {"Control"}], System`MenuEvaluator -> Automatic]}]] 
Edited the code
Source Link
Ajasja
  • 13.8k
  • 3
  • 48
  • 106

When developing some new code (eg. a function to analyse something) I usually make a .m and .nb file. The code goes in to .m is then called from the .nb.

But sometimes I forget to run the package after saving and then spend some time wondering why my code changes don't have the desired effect.

Is there a way to run a package automatically after it's saved?

Basically I would like that when I press [Ctrl]+S the package is saved and that the effect of this button being pressed is achieved.

Mathematica graphics

Currently I put Import["MyPackage.m"] at the top of the evaluation cell I'm currently working on in the notebook. Perhaps I could also abuse $Pre for this, but then the package would get imported on every cell evaluation (which is a bit needles).

EDIT

Well, this is what I have so far based on Chirs's answer

FrontEndExecute[ FrontEnd`AddMenuCommands[ "DuplicatePreviousOutput""Save", {Delimiter, MenuItem["Save and Run &Demo"&Package", FrontEnd`KernelExecute[NotebookSave[SelectedNotebook[]]; If[FileExtension[NotebookFileName[SelectedNotebook[]]] == "m",(*then*) Get[NotebookFileName[SelectedNotebook[]]]; ]; ], MenuKey["S", Modifiers -> {"Control"}], System`MenuEvaluator -> Automatic]}]] 

When developing some new code (eg. a function to analyse something) I usually make a .m and .nb file. The code goes in to .m is then called from the .nb.

But sometimes I forget to run the package after saving and then spend some time wondering why my code changes don't have the desired effect.

Is there a way to run a package automatically after it's saved?

Basically I would like that when I press [Ctrl]+S the package is saved and that the effect of this button being pressed is achieved.

Mathematica graphics

Currently I put Import["MyPackage.m"] at the top of the evaluation cell I'm currently working on in the notebook. Perhaps I could also abuse $Pre for this, but then the package would get imported on every cell evaluation (which is a bit needles).

EDIT

Well, this is what I have so far based on Chirs's answer

FrontEndExecute[ FrontEnd`AddMenuCommands[ "DuplicatePreviousOutput", {Delimiter, MenuItem["Save and Run &Demo", FrontEnd`KernelExecute[NotebookSave[SelectedNotebook[]]; If[FileExtension[NotebookFileName[SelectedNotebook[]]] == "m",(*then*) Get[NotebookFileName[SelectedNotebook[]]]; ]; ], MenuKey["S", Modifiers -> {"Control"}], System`MenuEvaluator -> Automatic]}]] 

When developing some new code (eg. a function to analyse something) I usually make a .m and .nb file. The code goes in to .m is then called from the .nb.

But sometimes I forget to run the package after saving and then spend some time wondering why my code changes don't have the desired effect.

Is there a way to run a package automatically after it's saved?

Basically I would like that when I press [Ctrl]+S the package is saved and that the effect of this button being pressed is achieved.

Mathematica graphics

Currently I put Import["MyPackage.m"] at the top of the evaluation cell I'm currently working on in the notebook. Perhaps I could also abuse $Pre for this, but then the package would get imported on every cell evaluation (which is a bit needles).

EDIT

Well, this is what I have so far based on Chirs's answer

FrontEndExecute[ FrontEnd`AddMenuCommands[ "Save", {Delimiter, MenuItem["Save and Run &Package", FrontEnd`KernelExecute[NotebookSave[SelectedNotebook[]]; If[FileExtension[NotebookFileName[SelectedNotebook[]]] == "m",(*then*) Get[NotebookFileName[SelectedNotebook[]]]; ]; ], MenuKey["S", Modifiers -> {"Control"}], System`MenuEvaluator -> Automatic]}]] 
added 609 characters in body
Source Link
Ajasja
  • 13.8k
  • 3
  • 48
  • 106

When developing some new code (eg. a function to analyse something) I usually make a .m and .nb file. The code goes in to .m is then called from the .nb.

But sometimes I forget to run the package after saving and then spend some time wondering why my code changes don't have the desired effect.

Is there a way to run a package automatically after it's saved?

Basically I would like that when I press [Ctrl]+S the package is saved and that the effect of this button being pressed is achieved.

Mathematica graphics

Currently I put Import["MyPackage.m"] at the top of the evaluation cell I'm currently working on in the notebook. Perhaps I could also abuse $Pre for this, but then the package would get imported on every cell evaluation (which is a bit needles).

EDIT

Well, this is what I have so far based on Chirs's answer

FrontEndExecute[ FrontEnd`AddMenuCommands[ "DuplicatePreviousOutput", {Delimiter, MenuItem["Save and Run &Demo", FrontEnd`KernelExecute[NotebookSave[SelectedNotebook[]]; If[FileExtension[NotebookFileName[SelectedNotebook[]]] == "m",(*then*) Get[NotebookFileName[SelectedNotebook[]]]; ]; ], MenuKey["S", Modifiers -> {"Control"}], System`MenuEvaluator -> Automatic]}]] 

When developing some new code (eg. a function to analyse something) I usually make a .m and .nb file. The code goes in to .m is then called from the .nb.

But sometimes I forget to run the package after saving and then spend some time wondering why my code changes don't have the desired effect.

Is there a way to run a package automatically after it's saved?

Basically I would like that when I press [Ctrl]+S the package is saved and that the effect of this button being pressed is achieved.

Mathematica graphics

Currently I put Import["MyPackage.m"] at the top of the evaluation cell I'm currently working on in the notebook. Perhaps I could also abuse $Pre for this, but then the package would get imported on every cell evaluation (which is a bit needles).

When developing some new code (eg. a function to analyse something) I usually make a .m and .nb file. The code goes in to .m is then called from the .nb.

But sometimes I forget to run the package after saving and then spend some time wondering why my code changes don't have the desired effect.

Is there a way to run a package automatically after it's saved?

Basically I would like that when I press [Ctrl]+S the package is saved and that the effect of this button being pressed is achieved.

Mathematica graphics

Currently I put Import["MyPackage.m"] at the top of the evaluation cell I'm currently working on in the notebook. Perhaps I could also abuse $Pre for this, but then the package would get imported on every cell evaluation (which is a bit needles).

EDIT

Well, this is what I have so far based on Chirs's answer

FrontEndExecute[ FrontEnd`AddMenuCommands[ "DuplicatePreviousOutput", {Delimiter, MenuItem["Save and Run &Demo", FrontEnd`KernelExecute[NotebookSave[SelectedNotebook[]]; If[FileExtension[NotebookFileName[SelectedNotebook[]]] == "m",(*then*) Get[NotebookFileName[SelectedNotebook[]]]; ]; ], MenuKey["S", Modifiers -> {"Control"}], System`MenuEvaluator -> Automatic]}]] 
Tweeted twitter.com/#!/StackMma/status/200680590230556673
Source Link
Ajasja
  • 13.8k
  • 3
  • 48
  • 106
Loading