Skip to content

Instantly share code, notes, and snippets.

@math2001
Created November 29, 2016 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save math2001/68ccd6077f52358c4b9d63d2f61181c6 to your computer and use it in GitHub Desktop.
Save math2001/68ccd6077f52358c4b9d63d2f61181c6 to your computer and use it in GitHub Desktop.
# -*- encoding: utf-8 -*-
def main():
import os.path
import sublime
PATH_TO_REPLACE_COMMAND_FILE = os.path.join(sublime.packages_path(), 'replace_command.py')
if os.path.exists(PATH_TO_REPLACE_COMMAND_FILE):
return
code = """import sublime
import sublime_plugin
class ReplaceCommand(sublime_plugin.TextCommand):
def run(self, edit, region, text):
if len(region) != 2:
raise ValueError('ReplaceCommand: a region like should be a list with 2 items. Got {0}'.format(region))
self.view.replace(edit, sublime.Region(region[0], region[1]), text)"""
with open(PATH_TO_REPLACE_COMMAND_FILE, 'w') as fp:
fp.write(code)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment