Loading ...
Sorry, an error occurred while loading the content.

Re: Launching an already open file

Expand Messages
  • Charles Campbell
    ... I m more curious than otherwise; have you considered using RunVIew with let b:runview_filtcmd= open -a StataMP --args do ? You may get a new version of
    Message 1 of 8 , Aug 5 8:09 AM
    • 0 Attachment
      ghuiber wrote:
      > I have a similar problem. I use Vim to edit Stata scripts (stata.com). These
      > scripts are called do-files. They are simple text files, but with a .do
      > extension, which Stata uses to recognize them as scripts. The Stata command
      > for executing such a script, say called filename.do, is "do filename".
      >
      > In Windows, there is a way to launch Stata from Vim to execute either a
      > do-file, or a set of selected lines in a do-file that is being edited in
      > Vim. This can be repeated as many times as you want, whether or not Stata is
      > already running, inside the same instance of Stata. I would like to get
      > MacVim to do the same.
      >
      > The Windows solution consists of two parts. The first is a rundo.exe file
      > written with an AutoIt script as described here --
      > http://s281191135.onlinehome.us/2008/20080427-stata.html. The second is a
      > Vim script as described here --
      > http://www.stata.com/statalist/archive/2006-06/msg00905.html.
      >
      > This Vim script goes into _gvimrc, and it describes two Vim functions:
      > RunIt() for making Stata execute a do-file being edited in Vim, and
      > RunDoLines() for making Stata execute a subset of selected lines of that
      > file.
      >
      > For my first attempt at getting this to work in MacVim, I modified the
      > script as shown 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()
      >
      >
      I'm more curious than otherwise; have you considered using RunVIew with
      let b:runview_filtcmd="open -a StataMP --args do"?

      You may get a new version of RunView from:

      http://mysite.verizon.net/astronaut/vim/index.html#RUNVIEW (beta)

      To install, simply:

      vim RunView.vba.gz
      :so %
      :q

      I don't have StataMP to test this out, so the b:runview_filtcmd may or
      may not be correct for RunView and StatMP.
      If it is correct, you'd want to have it in
      .vim/ftplugin/[pick-a-suffix].vim or
      .vim/ftplugin/[pick-a-suffix]/statmp.vim .

      Regards,
      Chip Campbell

      --
      You received this message from the "vim_mac" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Gabi Huiber
      In case anybody is curious, and for the sake of thorough documentation: I found a solution, with help from the Statalist. Rather than the Vim plugin Chip
      Message 2 of 8 , Sep 15, 2011
      • 0 Attachment
        In case anybody is curious, and for the sake of thorough
        documentation: I found a solution, with help from the Statalist.
        Rather than the Vim plugin Chip Campbell suggested, I ended up leaving
        it to the OS. Two very minimalistic Vim functions call a bash script
        each. This does the job.

        The whole conversation can be traced back from here:
        http://www.stata.com/statalist/archive/2011-09/msg00556.html. The
        entire code is shown as well.

        Best,
        Gabi


        On Fri, Aug 5, 2011 at 11:09 AM, Charles Campbell
        <Charles.E.Campbell@...> wrote:
        > ghuiber wrote:
        >>
        >> I have a similar problem. I use Vim to edit Stata scripts (stata.com).
        >> These
        >> scripts are called do-files. They are simple text files, but with a .do
        >> extension, which Stata uses to recognize them as scripts. The Stata
        >> command
        >> for executing such a script, say called filename.do, is "do filename".
        >>
        >> In Windows, there is a way to launch Stata from Vim to execute either a
        >> do-file, or a set of selected lines in a do-file that is being edited in
        >> Vim. This can be repeated as many times as you want, whether or not Stata
        >> is
        >> already running, inside the same instance of Stata. I would like to get
        >> MacVim to do the same.
        >>
        >> The Windows solution consists of two parts. The first is a rundo.exe file
        >> written with an AutoIt script as described here --
        >> http://s281191135.onlinehome.us/2008/20080427-stata.html. The second is a
        >> Vim script as described here --
        >> http://www.stata.com/statalist/archive/2006-06/msg00905.html.
        >>
        >> This Vim script goes into _gvimrc, and it describes two Vim functions:
        >> RunIt() for making Stata execute a do-file being edited in Vim, and
        >> RunDoLines() for making Stata execute a subset of selected lines of that
        >> file.
        >>
        >> For my first attempt at getting this to work in MacVim, I modified the
        >> script as shown 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()
        >>
        >>
        >
        > I'm more curious than otherwise; have you considered using RunVIew with let
        > b:runview_filtcmd="open -a StataMP --args do"?
        >
        > You may get a new version of RunView from:
        >
        >   http://mysite.verizon.net/astronaut/vim/index.html#RUNVIEW     (beta)
        >
        > To install, simply:
        >
        >   vim RunView.vba.gz
        >   :so %
        >   :q
        >
        > I don't have StataMP to test this out, so the b:runview_filtcmd may or may
        > not be correct for RunView and StatMP.
        > If it is correct, you'd want to have it in .vim/ftplugin/[pick-a-suffix].vim
        > or .vim/ftplugin/[pick-a-suffix]/statmp.vim .
        >
        > Regards,
        > Chip Campbell
        >
        > --
        > You received this message from the "vim_mac" maillist.
        > Do not top-post! Type your reply below the text you are replying to.
        > For more information, visit http://www.vim.org/maillist.php
        >

        --
        You received this message from the "vim_mac" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • Kelan Champagne
        ... Related to this, I just discovered that you can bring that existing window forward, if you know its servername. Just do: $ mvim --servername VIM
        Message 3 of 8 , May 9, 2012
        • 0 Attachment
          On Nov 3 2010, 11:19 am, björn <bjorn.winck...@...> wrote:
          > Finally, if you have a specific MacVim window that you wish to open a file in
          > then you should use the --servername and --remote family of arguments to the
          > "mvim" script, e.g.
          >
          > mvim --servername VIM --remote-silent filename

          Related to this, I just discovered that you can bring that existing window
          forward, if you know its servername. Just do:

          $ mvim --servername VIM --remote-expr "foreground()"

          This is useful if you want to avoid the warnings about the swap file already
          existing when you try to re-open the file, and would rather just bring that
          window to the front.

          -Kelan

          --
          You received this message from the "vim_mac" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        Your message has been successfully submitted and would be delivered to recipients shortly.