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]

Re: st: Stata with MacVim


From   Gabi Huiber <[email protected]>
To   [email protected]
Subject   Re: st: Stata with MacVim
Date   Mon, 27 Feb 2012 11:08:28 -0500

Today I received an e-mail from a Stata user who ran into trouble with
my Vim function, runIt(), as originally defined.

Turns out Vim -- and MacVim -- will escape parentheses in file names.
If you have a file named "hello (world).do", using runIt() as
originally written, Vim and MacVim will direct Stata to "hello
\(world\).do" instead.

That file will not be found, of course, and the operating system will
complain before you even reach Stata. I had no idea.

This alternative definition of runIt() should fix it:

function RunIt()
  let a=shellescape(expand("%:p"))
  wa
  "!do-file "%:p"
  execute '!do-file ' . a
endfunction

Gabi

On Wed, Sep 14, 2011 at 6:02 AM, Gabi Huiber <[email protected]> wrote:
> I am happy to report that, thanks to Phil Schumm's help, I finally
> managed to integrate MacVim with Stata 12 on Mac OS X Lion. The
> process has three steps:
>
> 1. Save the bash scripts below as /usr/local/bin/do-file and
> /usr/local/bin/do-selection respectively:
>
> ----------------------------------------- start do-file
> #!/bin/bash
> osascript -e "tell application id \"com.stata.stata12\"
>       open POSIX file \"${1}\"
> end tell"
> ----------------------------------------- start do-selection
> #!/bin/bash
> TMPFILE=".stata-$$.do"
> if [ ! -e "$TMPFILE" ]
> then
>   cat > "$TMPFILE"
>   osascript <<-APPLESCRIPT
>       tell application id "com.stata.stata12" 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
> ------------------------------------------ end bash scripts
>
> Both scripts above are almost identical to how Phil wrote them. I just
> changed stata11 to stata12. Don't forget to check their permissions.
> They should both be executable.
>
> 2. Add the following two functions to .gvimrc:
>
> ------------------------------------------ start .gvimrc additions
> function RunIt()
>  wa
>  !do-file "%:p"
> endfunction
>
> :map <F5> :<C-U>call RunIt()<CR><CR>
> :imap <F5> <Esc>:<C-U>call RunIt()<CR><CR>
>
> function RunDoLines()
>  '<,'>w !do-selection
> endfunction
>
> :vmap <F6> :<C-U>call RunDoLines()<CR><CR>
> -------------------------------------------- end .gvimrc additions
>
> 3. Uncheck  "Edit do-files opened from the Finder in Do-file Editor"
> as instructed below:
>
> On Thu, Sep 8, 2011 at 10:40 AM, Phil Schumm <[email protected]> wrote:
> There is a new setting (in Stata for OS X) under
>>
>>    General Preferences... -> Do-file Editor -> Advanced
>>
>> called "Edit do-files opened from the Finder in Do-file Editor."  I believe that this is checked by default.  You need to uncheck it if you want an Open File Apple Event to execute a do-file instead of opening it in the do-file editor.  Note that for those people (like myself) who use an external editor, most will have set the Finder to use that editor (rather than Stata) to open a do-file when double-clicking on it.  Thus for them, this option is essentially superfluous (but must be unchecked if you wish to use an Open File AE to execute code in Stata from your editor).
>>
>>
>> -- Phil
>
> Thanks again,
> 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