# openLastClosedFile plugin v1.0.2 # # example keybinding: # # # Known issues: # there has to be one tab open to make the keybinding work import sublime, sublimeplugin, os # we need to be able to load the filenames when command gets called class openLastClosedFileSecure(sublimeplugin.Plugin): def onClose(self, view): # untitled / not saved files have no filename if view.fileName() <> None: file = open(sublime.packagesPath()+"\\User\\openLastClosedFile.tmp", 'a') file.writelines(view.fileName()+"\n") file.close() print sublime.packagesPath() class openLastClosedFileCommand(sublimeplugin.TextCommand): def run(self, view, args): fileName = sublime.packagesPath()+"\\User\\openLastClosedFile.tmp" if os.path.isfile(fileName): readFile = open(fileName,"r") lines = readFile.readlines() readFile.close() length = len(lines) if length > 0: lastline = lines[length-1] lastline = lastline.rstrip("\n") view.window().openFile(lastline, 0, 0) writeFile = open(fileName, "w") writeFile.writelines([item for item in lines[0:length-1]]) writeFile.close()