Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sublime Text 3 with STATA (Enhanced) - opens new instance of STATA for every command.

    Hello, I've been trying to make a third-party text editor work as do-file editor. I use Sublime Text for Latex, and it's just infinitely better at handling code than Statas own do-file editor.

    However, there is this problem, which seems to be a generel problem not just for Sublime Text, but also Textpad and maybe other editors. I'll describe the problem here in its specific Sublime Text variant, but I'm pretty sure it is a general one:

    I'm trying to make the STATA (Enhanced) plugin work, for Sublime Text 3. I'm on a W7 machine. The problem is, I've installed the plugin and edited the "STATA Enhanced (windows).sublime-settings file to look like this, as per instructions:
    { "stata_version": 13, "stata_name": "C:/Program Files (x86)/Stata13/StataMP-64.exe" }
    and also I've changed STATAs preferences so that STATA runs do-files automagically, also per instructions.
    And it works, with Ctrl+Enter STATA runs do-files from Sublime Text. However- every time I run a command, it opens a new instance of STATA. That's very impractical, but I don't know what to do about it. The readme doesn't mention this problem and haven't been able to find a solution on the net.

    there seems to be some kind of option missing, that tells STATA to run the command in the already-opened instance of the application and not open a new one. I think this is parallel to Stata opening a new instance if you open a do-file directly instead of through the already-opened instance of Stata.

    So I'm at a loss, do you know what to do about it?

    Thank you in advance, Emil

  • #2
    Ok this is a general problem. I'm keeping my post in here, hoping that someone has another good editor which doesn't have this problem?
    https://github.com/andrewheiss/Subli...nced/issues/19

    Comment


    • #3
      It will not do what you want because it is not possible. It is not a problem of your TextEditor. It is not problem of Stata.
      You need to understand the difference between MDI applications and SDI applications.

      What you want is possible with OLE provided that your commands run instantaneously. Otherwise, what do you want to happen if Stata is busy?

      Best, Sergiy Radyakin

      Comment


      • #4
        You double-posted on StackOverFlow, but, contrary to the FAQ, did not link the posts to one-another. A common result of this practice is that someone wastes their time largely duplicating an answer provided in the other location. That's not happened to you so far, but please cross-link now.
        Last edited by Steve Samuels; 18 Aug 2014, 19:57.
        Steve Samuels
        Statistical Consulting
        [email protected]

        Stata 14.2

        Comment


        • #5
          To extend on Sergiy's answer:

          It *is* in the roadmap for the package SublimeStataEnhanced:
          Stata 13 for Windows has support for Automation APIs. It would be cool to use those instead of temporary files (like how the OS X version of the plugin uses temporary files for Stata 11–12, but the API for 13).
          https://github.com/andrewheiss/SublimeStataEnhanced

          But the author uses OSX so I don't expect this to be added very soon (it works on macs though). Any volunteers to implement this?


          Comment


          • #6
            Thanks a lot for your very insightfull comments. It's nice to know that it isn't just me, but the state of the plugin as such at this state. Here's hoping that someone with the skills to do it will take advantage of the Automation API for Windows.

            Oh yeah I forgot about that, here's the link for the stackexhange question (although noone there had a qualified answer which is why I went here instead)

            Comment


            • #7
              Sorry for hi-jacking the thread, but I have a related problem. I'm writing a VBScript to use automation to run a do-file (to eventually be able to use Sublime Text as an editor but without using the workaround in Stata Enhanced mentioned in the OP). This can be done in a simple VBScript:

              dim stataobj
              set stataobj=CreateObject("stata.StataOLEApp")
              stataobj.DoCommand("do some_dofile.do")

              However, as soon as the script is done, Stata closes. Is there any way to keep Stata running after the script has executed?

              Thanks!

              Comment


              • #8
                I've just come across this same issue, having tried SublimeText 3.0 (beta) and Windows StataMP 13.

                If you're interested in an editor that doesn't close Stata after running and re-runs do files within the original, single Stata window, I know that the gVim, Cream package will do this after doing some modifications: http://cream.sourceforge.net/home.html
                First, you need to get and install the rundo and rundolines from the following URL: http://huebler.blogspot.com/2008/04/stata.html
                In the example below, I've placed the rundo files in a ~/.cream/stata/ folder and edited the rundo ini file to point to the correct location of StataMP for my computer.

                Pressing F8 -- or -- Selecting Text and pressing F9 runs .do file contents direct into Stata.

                Cream/VIM comes stock with stata syntax, but you do need to edit your ~/.cream/cream-user.vim to include the following:

                " STATA DO-FILE SCRIPTS

                fun! RunIt()
                wa
                " *** CHANGE PATH AND NAME TO REFLECT YOUR SETUP ***
                !start "C:\Users\<MY_USER_FOLDER>\.cream\stata\rundo. exe" "%:p"
                endfun

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

                fun! 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)

                " *** CHANGE PATH AND NAME TO REFLECT YOUR SETUP. USE \\ INSTEAD OF \ ***
                exec "!start C:\\Users\\<MY_USER_FOLDER>\\.cream\\stata\\rundo. exe " . temp

                " Delete the temp file after Vim closes
                au VimLeave * exe "!del -y" temp
                endfun

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

                Comment

                Working...
                X