Skip to content

Commit

Permalink
Replace explicit creations of Edits with commands
Browse files Browse the repository at this point in the history
To support Sublime Text 3
  • Loading branch information
misfo committed Aug 16, 2013
1 parent 688542d commit 6586168
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions shell_turtlestein.py
Expand Up @@ -174,18 +174,26 @@ def process_region(self, active_view, selection, cwd, shell_cmd, outpt):
(success, output) = run_cmd(cwd, shell_cmd, True, input_str)
if success:
if outpt == '|':
edit = active_view.begin_edit()
active_view.replace(edit, selection, output)
active_view.end_edit(edit)
active_view.run_command("replace_with_text", {'region_start': selection.a,
'region_end': selection.b,
'text': output})
elif outpt == '>':
self.window.run_command("new_file")
new_view = self.window.active_view()
new_view.set_name(shell_cmd.strip())
edit = new_view.begin_edit()
new_view.insert(edit, 0, output)
new_view.end_edit(edit)
new_view.run_command("replace_with_text", {'text': output})


class ReplaceWithTextCommand(sublime_plugin.TextCommand):
"""
Replace the text in the specified region with the specified text
"""
def run(self, edit, region_start=None, region_end=None, text=None):
if region_start and region_end:
self.view.replace(edit, sublime.Region(region_start, region_end), text)
else:
self.view.insert(edit, 0, text)

class SubprocessInCwdCommand(sublime_plugin.WindowCommand):
"""
Launch a subprocess using the window's working directory
Expand Down

0 comments on commit 6586168

Please sign in to comment.