From 28825aa41a856cd523b38a89680572cc4ea60732 Mon Sep 17 00:00:00 2001 From: Mark Fowler Date: Tue, 17 Jan 2012 13:05:18 +0000 Subject: [PATCH] Added a TM_BUFFER_FILEPATH var that points to a temp file containing the contents of the current buffer --- SuperSnippetCommand.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/SuperSnippetCommand.py b/SuperSnippetCommand.py index 8a358b7..84ac9db 100644 --- a/SuperSnippetCommand.py +++ b/SuperSnippetCommand.py @@ -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