Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Integrating Stata and JEdit


From   Ian Watson <[email protected]>
To   [email protected]
Subject   Re: st: Integrating Stata and JEdit
Date   Tue, 27 Jun 2006 08:37:03 -0700

Dimitriy V. Masterov wrote:
> Has anyone successfully integrated jEdit and Stata using AutoIt? I am
> trying to help a friend, but I am not sure how to configure the plugin
> in jEdit, if that is the appropriate terminology. I think I've gotten
> the script to run OK.


Yes, I've got JEdit and Stata working very well. My routine is to assign F9 to send the selected text to Stata, F8 to switch to Stata (using AutoIt), F9 inside Stata to run the selected text and F8 (using AutoIt again) to switch back to JEdit. After a while the sequence of F9 F8 F9 F8 becomes automatic.

The setup is outlined in detail below, with all my code included between snippet marks (===========). You've probably already worked most of this out, but I've gone into detail in case other Listers are interested.

It may seem complicated at first but it's worth the effort to get it working. Over the years I've used a number of Windows editors (Ultra Edit, TextPad, WinEdt) which were all much easier to configure to work with Stata, but JEdit is a much superior editor. Not only is it platform independent, but it can serve as an editor for all purposes. In my case, that's both Stata and LaTeX, and the same procedures listed below can be used to make all the LaTeX commands work as well (it also has a LaTeX plugin). From a Stata point of view, JEdit has folding (the ability to collapse code blocks) which is invaluable for editing long complex loops of Stata code. Anyway, enough of the sales blurb. The details follow:



FIRST STAGE: INSIDE JEDIT:

Part A

Unfortunately JEdit won't easily "map" a keystroke to an executable as with some other editors. Instead, you need to write a macro which runs the executable and then assign the macro to a keystroke ((using JEdit's Utilities Global Options). If your AutoIt script does everything you need for running Stata, jump to Part B. If you're interested in how I get a *selected* portion of my Stata code to run, read on.

Use a macro (written in Java) to select highlighted text and send it to a file called "marked.do" (or whatever you prefer). Here is the text of my macro (which I've called marked.bsh) to which I then assign the F9 key:

snip here======================================

import java.io.*;
// save existing file
buffer.save(view,null,true);
//... Create File objects.
File outFile = new File("d:/data/marked.do"); // write into second file

//... Enclose in try..catch because of possible io exceptions.
try {
//... Create reader and writer for text files.
BufferedWriter writer = new BufferedWriter(new FileWriter(outFile));

Selection[] selection = textArea.getSelection();
if(selection == null)
view.getToolkit().beep();
else
{
for(i = 0; i < selection.length; i++)
writer.write(textArea.getSelectedText(selection[i]));

writer.newLine(); // Write system dependent end of line.
//... Close reader and writer.
writer.close(); // Close to unlock and flush to disk.
}
} catch (IOException e) {
System.err.println(e);
System.exit(1);
}
// clear selection
textArea.goToPrevLine(false);
textArea.goToNextLine(false);

snip here=============================================

Part B

Running Executables inside JEdit just needs one line of code. In my case I use it for the process of switching to Stata. It sounds like in your case you can use this step to get your AutoIt script working:

snip here=================

Runtime.getRuntime().exec("switchtostata");

snip here================================


Again this is saved as a bsh file inside JEdit and assigned to the key F8. The actual executable is based on the following AutoIt script:

snip here===============================

Opt("SendKeyDelay", 1)
Opt("WinWaitDelay", 200)

WinActivate("Stata/SE 9.2")

snip here==================================


though you'll need to edit for the correct version of Stata.


SECOND STAGE: INSIDE STATA


Much simpler at this end.

Inside Stata's profile.do (located in the Stata root directory) include the lines:

snip here====================

global F8 "winexec d:/data/switchtojedit;"
global F9 "do d:/data/marked;"


snip here====================


The executable for switching back to JEdit is based on the followed AutoIt script:

snip here================

Opt("SendKeyDelay", 1)
Opt("WinWaitDelay", 200)

WinActivate("jEdit")

snip here==================



And that's it.

(For those Windows listers who don't know about AutoIt, check it out. It's a great little program for automating Windows commands which produces executables which can then be called from other applications. See http://www.autoitscript.com/autoit3/ )


Cheers

Ian Watson


University of Sydney
Australia





Dimitriy V. Masterov wrote:

Has anyone successfully integrated jEdit and Stata using AutoIt? I am
trying to help a friend, but I am not sure how to configure the plugin
in jEdit, if that is the appropriate terminology. I think I've gotten
the script to run OK.

I'm a Vim user, and in my _gvimrc file I have the following code to
map F8 to the AutoIt script:

:map <F8> :<C-U>call RunIt() <ENTER>
:imap <F8> <Esc>:<C-U>call RunIt() <ENTER>

fun! RunIt()
 w
 !start "C:\Program Files\Scripts\rundo.exe" "%:p" <Enter>
endfu

What is the analogue for this in jEdit?

Dimitriy
*
*   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/



*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index