Skip to content

Instantly share code, notes, and snippets.

@jbrooksuk
Created December 4, 2012 10:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jbrooksuk/4202578 to your computer and use it in GitHub Desktop.
Save jbrooksuk/4202578 to your computer and use it in GitHub Desktop.
Sublime Text Insert Numbers
[
{ "keys": ["ctrl+alt+n"], "command": "prompt_insert_nums" }
]
import sublime, sublime_plugin
import random
class PromptInsertNumsCommand(sublime_plugin.WindowCommand):
def run(self):
self.window.show_input_panel('Enter a starting number, step, random.', '1 1 N', self.on_done, None, None)
pass
def on_done(self, text):
try:
(current, step, dorand) = map(str, text.split(" "))
if self.window.active_view():
self.window.active_view().run_command("insert_nums", {"current" : current, "step" : step, "dorand" : dorand} )
except ValueError:
pass
class InsertNumsCommand(sublime_plugin.TextCommand):
def run(self, edit, current, step, dorand):
current = int(current)
for region in self.view.sel():
sublime.status_message("Inserting #" + str(current))
self.view.replace(edit, region, str(current))
if dorand == "Y":
current = random.randint(1, 100)
else:
current = current + int(step)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment