-
-
Save sambenne/4202593 to your computer and use it in GitHub Desktop.
Sublime Text Insert Numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
[ | |
{ "keys": ["ctrl+alt+n"], "command": "prompt_insert_nums" } | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
start = 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(start, int(step)) | |
else: | |
current = current + int(step) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment