Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: running do-files from vi


From   "Dimitriy V. Masterov" <[email protected]>
To   [email protected]
Subject   st: running do-files from vi
Date   Wed, 23 Jun 2004 14:24:41 -0500 (CDT)

I've been trying to find a way to run a do-file that I am editing in vi
from vi. I think I came up with a way to do this that you might find
useful. The advantage of this method is that it does not open a new Stata
session (unless there is not one open). It essentially turns F8 into a
save-n-do button like the one in the Stata Do-Editor.

This works for Stata SE on XP and gvim. It may work elsewhere with the
appropriate modifications.

Step 1
I used a free and open source program called AutoIt to create a script
that I run from vi. You can download the software from
http://www.hiddensoft.com/.

I created a file called do.au3 that contained the following code. You
might want to change the pathnames to suit your setup


; This program do.au3:
;
; (1) Opens a Stata session if one Is NOT yet open
; (2) Gets the do file path and then runs that file:
;
; Once you compiled the script to make do.exe:
; Syntax is "run c:/.../do.exe c:/.../dofile.do"
;
; DVM 6/22/04


If WinExists("Stata/SE 8.2") Then
	;Put in the pathname from the vi loop
	WinWaitActive("Stata/SE 8.2")
	Send("do " & '"' & $CmdLine[1] & '"' & "{Enter}")
Else
	;Run Stata
	Run("c:/program files/stata8/wsestata.exe")
	WinWaitActive("Stata/SE 8.2")
	Send("do " & '"' & $CmdLine[1] & '"' & "{Enter}")
EndIf



Step 2
Compile the do.au3 script using AutoIt2 program. This will make the do.exe
file.


Step 3
In your _gvimrc file, include the following lines. Make sure the pathnames
are correct.

" These 2 commands will map F8 to
" (1) save and run the current do-file in Stata
" (2) open a Stata session if one is not open and execute (1)

:map <F8> :<C-U>call RunIt() <Enter>
:imap <F8> <Esc>:<C-U>call RunIt() <Enter>
" <C-U> cancels the range in case you have a count pending in Normal mode
or if you use it from Visual mode.

fun! RunIt()
  w
  !start "c:/program files/autoIt3/examples/english/my programs/do.exe"
"%:p"
endfu


Step 4
Hit F8 to test of this works.



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