Created
February 20, 2018 20:12
-
-
Save michaelkc/8e6f67853b4d507c46f261802ce16ef8 to your computer and use it in GitHub Desktop.
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, string, os | |
class saveunnamedbuffersCommand(sublime_plugin.TextCommand): | |
def run(self, edit): | |
print("Init") | |
for window in sublime.windows() : | |
for view in window.views() : | |
dirty = view.is_dirty() | |
filename = str(view.file_name()) | |
print(str(dirty) + " " + filename) | |
if dirty and filename == "None" : | |
print("Found dirty, unnamed buffer") | |
N = 50 | |
name = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(N)) | |
filename = os.path.normpath("d:/Temp/sublimebuffers/" + name + ".txt") | |
view.retarget(filename) | |
view.run_command("save") | |
view.close() | |
print("Dirty, unnamed buffer saved") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment