From 1d6de34384cd86f7bb3b3686fb81a1a45dbe2fe5 Mon Sep 17 00:00:00 2001 From: Stephen Judkins Date: Wed, 28 Sep 2011 16:45:26 -0700 Subject: [PATCH 1/3] Add "compile and show in new tab" support Sublime Text 2 plugin. --- .gitignore | 3 ++- Default (OSX).sublime-keymap | 5 +++++ Default.sublime-commands | 6 ++++++ coffee.py | 29 +++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 Default (OSX).sublime-keymap create mode 100644 Default.sublime-commands create mode 100644 coffee.py diff --git a/.gitignore b/.gitignore index f05fcdc..b110cc8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -*.cache \ No newline at end of file +*.cache +*.pyc \ No newline at end of file diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap new file mode 100644 index 0000000..5574ea8 --- /dev/null +++ b/Default (OSX).sublime-keymap @@ -0,0 +1,5 @@ +[{ + "keys": ["super+shift+r"], + "command": "coffee_compile", + "args": {} +}] \ No newline at end of file diff --git a/Default.sublime-commands b/Default.sublime-commands new file mode 100644 index 0000000..da96190 --- /dev/null +++ b/Default.sublime-commands @@ -0,0 +1,6 @@ +[ +{ + "caption": "CoffeeScript: Compile", + "command": "coffee_compile" +} +] \ No newline at end of file diff --git a/coffee.py b/coffee.py new file mode 100644 index 0000000..b9b489f --- /dev/null +++ b/coffee.py @@ -0,0 +1,29 @@ +import sublime +import sublime_plugin +import subprocess + +class CoffeeCompileCommand(sublime_plugin.TextCommand): + def run(self, edit): + process = subprocess.Popen(["coffee", "-b", "-s", "-c"], stderr = subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE) + (compiled, errors) = process.communicate(self.get_coffeescript()) + + if len(compiled) == 0: + output = errors + else: + output = compiled + + self.output_to_new_view(output) + + def get_coffeescript(self): + selection = self.view.sel()[0] + if selection.empty(): + selection = sublime.Region(0, self.view.size()) + return self.view.substr(selection) + + def output_to_new_view(self, output): + new_view = sublime.active_window().new_file() + new_view.set_name("(compiled CoffeeScript)") + new_view.set_scratch(True) + edit = new_view.begin_edit() + new_view.insert(edit, 0, output) + new_view.end_edit(edit) From 533bf798aae09b3e2476643a1c2eb269c86643c9 Mon Sep 17 00:00:00 2001 From: Lorin Tackett Date: Wed, 28 Sep 2011 17:33:27 -0700 Subject: [PATCH 2/3] Added syntax highlighting to outputted javascript --- coffee.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/coffee.py b/coffee.py index b9b489f..eea275e 100644 --- a/coffee.py +++ b/coffee.py @@ -22,7 +22,8 @@ def get_coffeescript(self): def output_to_new_view(self, output): new_view = sublime.active_window().new_file() - new_view.set_name("(compiled CoffeeScript)") + new_view.set_name("compiled_CoffeeScript.js") + new_view.set_syntax_file("Packages/JavaScript/JavaScript.tmLanguage") new_view.set_scratch(True) edit = new_view.begin_edit() new_view.insert(edit, 0, output) From 825254e989122d640e5a2ec1d6fec2a8c18f0cf4 Mon Sep 17 00:00:00 2001 From: Stephen Judkins Date: Wed, 28 Sep 2011 19:11:19 -0700 Subject: [PATCH 3/3] Change back new tab caption --- coffee.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coffee.py b/coffee.py index eea275e..8a460d6 100644 --- a/coffee.py +++ b/coffee.py @@ -22,7 +22,7 @@ def get_coffeescript(self): def output_to_new_view(self, output): new_view = sublime.active_window().new_file() - new_view.set_name("compiled_CoffeeScript.js") + new_view.set_name("(compiled CoffeeScript)") new_view.set_syntax_file("Packages/JavaScript/JavaScript.tmLanguage") new_view.set_scratch(True) edit = new_view.begin_edit()