Skip to content

Instantly share code, notes, and snippets.

@amitchhajer
Forked from dtao/increment_decrement.py
Created April 8, 2013 11:35
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 amitchhajer/5336162 to your computer and use it in GitHub Desktop.
Save amitchhajer/5336162 to your computer and use it in GitHub Desktop.
import sublime
import sublime_plugin
class NumberCommand(sublime_plugin.TextCommand):
def run(self, edit):
selection = self.view.sel()
for region in selection:
try:
value = int(self.view.substr(region))
self.view.replace(edit, region, str(self.op(value)))
except ValueError:
pass
def is_enabled(self):
return len(self.view.sel()) > 0
class IncrementCommand(NumberCommand):
def op(self, value):
return value + 1
class DecrementCommand(NumberCommand):
def op(self, value):
return value - 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment