Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: Stata with MacVim


From   Gabi Huiber <[email protected]>
To   The Statalist <[email protected]>
Subject   st: Stata with MacVim
Date   Sun, 31 Jul 2011 12:14:21 -0500

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:
http://www.stata.com/statalist/archive/2006-06/msg00905.html.
Dimitriy's script makes use of rundo.exe, written by Friedrich Huebler
and described at http://huebler.info.

I know this works because I used it for Stata 10+Vim 7.3+Win 7 Pro.
Now I am trying to accomplish the same thing with Stata 12+MacVim+Mac
OS X Lion.

My Vim script is below:

" STATA DO-FILE SCRIPT

function RunIt()
  wa
  !open -a StataMP --args do "%:p"
endfunction

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

function RunDoLines()
  let selectedLines = getbufline('%', line("'<"), line("'>"))

 if col("'>") < strlen(getline(line("'>")))
   let selectedLines[-1] = strpart(selectedLines[-1], 0, col("'>"))
 endif
 if col("'<") != 1
   let selectedLines[0] = strpart(selectedLines[0], col("'<")-1)
 endif

 let temp = tempname() . ".do"
   call writefile(selectedLines, temp)

   exec "!open -a StataMP --args do " . temp

   " Delete the temp file after Vim closes
   au VimLeave * silent exe '!rm "'.$TEMP.'\*.do"'
endfunction

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

The trouble is, my script doesn't work as well. It can call either
RunDo() or RunDoLines() and it will correctly launch Stata with a do
command that applies either to the whole do-file being edited, or to
the selected lines, as expected. But it will do either action only
once. Subsequent calls to either RunDo() or RunDoLines() will be
ignored until Stata is restarted.

I would appreciate any ideas about how I could fix this.

Thank you,
Gabi
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index