Created
January 5, 2012 21:34
-
-
Save qur2/1567442 to your computer and use it in GitHub Desktop.
SublimeText shuffle selection command
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, random | |
class ShuffleCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
regions = self.view.sel() | |
selections = [self.view.substr(s) for s in regions] | |
selections = [shuffle_string(s) for s in selections] | |
for i in range(len(selections)): | |
self.view.replace(edit, regions[i], selections[i]) | |
def shuffle_string(s): | |
return ''.join(shuffle_list(list(s))) | |
# need to be used from sort.py, but how to import that file ? | |
def shuffle_list(l): | |
random.shuffle(l) | |
return l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment