http://stata.com/statalist/archive/2006-06/msg00844.html
I wanted to automate everything so that there's no switching between windows, and the solution I came up with is a bit different than what
Ian Watson suggested, though it is basically a modified version of his code.
(1) Create a Bean Shell macro file called rundo.bsh in your jEdit macro directory.
On my PC, the directory is C:\Documents and Settings\Dimitriy V. Masterov\.jedit\macros\
Rundo.bsh will save the current do-file and then run the whole thing.
Here's the code:
/************************************* rundo.bsh ****************************
/** This Bean Shell jEdit script
(a) Saves the current do-file
(b) Runs it using Stata and an AutoIt script called rundo.exe
AutoIt is available at http://www.autoitscript.com/autoit3/.
See F. Huebler's Script 1 at http://huebler.info/2005/20050310_Stata_editor.html for details on rundo.exe
**/
rundo() {
// Get the name of the current do-file
filename = buffer.getPath();
// Save the do-file
buffer.save(view,null,true);
// Runs the file. You many need to change the location of rundo.exe to suit your PC
String command="C:\\Program Files\\Scripts\\rundo.exe " + "\"" + filename + "\"";
exec(command);
}
rundo();
/*****************************************************************************
(2) To run only the highlighted part of the do-file, create another script called rundolines.bsh:
/************************** rundolines.bsh ************************************
/**
This Bean Shell jEdit script runs the highlighted part of a Stata
do-file using an AutoIt script called rundo.exe.
AutoIt is available at http://www.autoitscript.com/autoit3/.
See F. Huebler's Script 1 at
http://huebler.info/2005/20050310_Stata_editor.html for details on rundo.exe
**/
rundolines() {
// Copy selected text
String text = textArea.getSelectedText();
// Create a temp file
File temp = File.createTempFile("dofilelines", ".do");
// Delete temp file when program exits.
temp.deleteOnExit();
// Write to temp file
BufferedWriter out = new BufferedWriter(new FileWriter(temp));
out.write(text);
out.close();
// Run the temporary file in Stata
String command="C:\\Program Files\\Scripts\\rundo.exe " + "\"" + temp + "\"";
exec(command);
}
rundolines();
/*********************************************************************
(3) To map F8 and F9 to the scripts, go to Utilities, Global Options, Shortcuts, pick Macros from the drop down menu, select the script name, and assign the shortcut key.
These macros can also be added to the context menu so you see them when you right click.
Note: In order for the "rundolines" to work, you need to select the whole line.