Skip to content

Instantly share code, notes, and snippets.

@michaelkc
Created February 20, 2018 20:12
Show Gist options
  • Save michaelkc/8e6f67853b4d507c46f261802ce16ef8 to your computer and use it in GitHub Desktop.
Save michaelkc/8e6f67853b4d507c46f261802ce16ef8 to your computer and use it in GitHub Desktop.
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