Permalink
Browse files

Added a TM_BUFFER_FILEPATH var that points to a temp file containing …

…the contents of the current buffer
  • Loading branch information...
1 parent 536eba1 commit 28825aa41a856cd523b38a89680572cc4ea60732 @2shortplanks committed Jan 17, 2012
Showing with 17 additions and 2 deletions.
  1. +17 −2 SuperSnippetCommand.py
View
@@ -1,4 +1,4 @@
-import sublime, sublime_plugin, os, re
+import sublime, sublime_plugin, os, re, tempfile
from subprocess import Popen, PIPE
a_to_z = re.compile("^[A-Za-z0-9_-]*$")
@@ -57,8 +57,23 @@ def run_shell_command(self, cmd):
# to match the tab size of the document. See also TM_SOFT_TABS.
env['TM_TAB_SIZE'] = str(self.view.settings().get("tab_size"))
+ # write the entire buffer out to a temp file
+ buffer_file = tempfile.NamedTemporaryFile();
+ env['TM_BUFFER_FILEPATH'] = buffer_file.name;
+ size = self.view.size();
+ chunk = 1024
+ start_pos = 0
+
+ while start_pos < size:
+ text = self.view.substr( sublime.Region(start_pos, start_pos + chunk) )
+ buffer_file.write(text)
+ start_pos = start_pos + chunk
+ buffer_file.flush()
+
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, env=env, close_fds=True)
- return (p.stdout.read() + p.stderr.read()).rstrip("\n\r")
+ result = (p.stdout.read() + p.stderr.read()).rstrip("\n\r");
+
+ return result;
# TODO: Handle \ to esxape input. This probably will mean we
# need to recode to do a character by character scan

0 comments on commit 28825aa

Please sign in to comment.