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:
/** 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:
/** 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.
DVM
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/