andrewheiss / SublimeStataEnhanced

Plugin that adds support for Stata 11–15 for Sublime Text 2 and 3
56 stars 22 forks source link

Hold focus on Stata when passing commands? #41

Closed nickeubank closed 8 years ago

nickeubank commented 8 years ago

(a) @andrewheiss, you're a hero for this package.

(b) there a trick to keeping focus on the Stata window when passing a selection of text as commands? seems to be jumping back to Sublime after execution for me. Doesn't happen when executing a full dofile.

andrewheiss commented 8 years ago

There's not an easily achievable way, from what I've found. The rationale behind this package (and I think the rational behind Stata's Applescript support in general) is to behave more like RStudio, where there's an editor and a console, with the editor sending commands to the console. This way you can run commands line by line and have them run in the background without having the focus change to Stata (like in R, you can press ⌘Enter over and over to run a bunch of individual lines in succession; if the focus switched, that wouldn't be possible).

Stata's Applescript support is wired to do this too, sending lines to Stata in the background. That way it replicates what happens when you use Stata's built-in .do file editor, which doesn't change focus to the main Stata window.

The reason the focus does switch to Stata when running the whole file is because that triggers a build in Sublime Text, which switches to external apps by default (like if you build an HTML file, it'll open in your browser).

The only way to make this plugin switch focus when running individual lines or selections would be to tinker with the Applescript in text_2_stata.py to return focus to Stata, but I'm not sure how that fits with the overall philosophy of the plugin to run stuff in the background…

nickeubank commented 8 years ago

@andrewheiss Thanks for the thoughts -- makes a lot of sense.

Perhaps at some point it mike make sense to add "leave stata active" as a setting (albeit not the default)? Sounds like wouldn't be hard to implement with a simple applescript activate command embedded in an if statement in text_2_stata.py? Not urgent, but when my life slows down a little I might try and do a PR on that.

andrewheiss commented 8 years ago

I added a switch_focus_to_stata setting that is false by default, but when enabled it switches the focus to Stata after sending a command. I just need to update the documentation and then alert Package Control.

andrewheiss commented 8 years ago

Documentation updated. Package Control should pick up on the updates in a few hours and roll out the latest update. Thanks for the suggestion!

andrewheiss commented 8 years ago

Important to note that this is only for Stata 13+ on OS X

nickeubank commented 8 years ago

@andrewheiss Thanks! FYI, I got to work fine on StataMP 12.