Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Stata with MacVim


From   Phil Schumm <pschumm@uchicago.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Stata with MacVim
Date   Mon, 1 Aug 2011 18:33:19 -0500

On Jul 31, 2011, at 12:14 PM, Gabi Huiber wrote:
> Has anybody managed to integrate Stata with MacVim? I have made an attempt but I am stuck, as follows:
> 
> There is an old Statalist post by Dimitriy Masterov about getting Stata to launch from Vim on Windows, here:


You'll need to communicate with Stata via Apple events, which is most easily done via Applescript.  For example, to send the file you are currently editing to Stata, you could create the following (executable) shell script (note that you'll need to modify the Bundle identifier if you're using Stata 12):


----------------------- do-file -----------------------
#!/bin/bash
osascript -e "tell application id \"com.stata.stata11\"
	open POSIX file \"${1}\"
end tell"
-------------------------------------------------------


Place the script on your path, and then, while editing a do-file in vim, do


    :! do-file %


Similarly, if you wish to send a visual selection to Stata, create a script like the following:


--------------------------------- do-selection --------------------------------
#!/bin/bash
TMPFILE=".stata-$$.do"
if [ ! -e "$TMPFILE" ]
then
    cat > "$TMPFILE"
    osascript <<-APPLESCRIPT
        tell application id "com.stata.stata11" to open POSIX file "${TMPFILE}"
        delay 0.5  -- avoid deleting file before Stata reads it
        do shell script "rm \"${TMPFILE}\""
APPLESCRIPT
else
	echo "Can't create temporary file $TMPFILE (already exists)"
fi
-------------------------------------------------------------------------------


Select the lines in vim you want to execute, and do


    :'<,'>w !do-selection


I'm afraid I don't have time right now to test this code, or to give additional details.  Moreover, I'm a novice vim user (I use it for remote system administration only), so I can only help you on the Applescript part.  If you run into trouble, let me know.


-- Phil


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index