Skip to content

Instantly share code, notes, and snippets.

@puterleat
Created February 14, 2013 15:26
Show Gist options
  • Save puterleat/4953529 to your computer and use it in GitHub Desktop.
Save puterleat/4953529 to your computer and use it in GitHub Desktop.
sublime text 2 plugin to run selection in Stata
import subprocess
import os
import sublime
import sublime_plugin
class RunInStataCommand(sublime_plugin.TextCommand):
def run(self, edit):
CURR, _ = os.path.split(self.view.file_name())
sel = self.view.sel()
text = [self.view.substr(i) for i in sel]
text = [i.split("//")[0] for i in text] #kill comments
text = '\n'.join(text)
tmpdofile = os.path.join(CURR, '.tostata.do')
with open(tmpdofile, 'w') as f:
f.write(text)
subprocess.check_call(["open", tmpdofile])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment