Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Sublime text reopen closed tab plugin

By: a guest on Mar 26th, 2010  |  syntax: Python  |  size: 1.20 KB  |  views: 241  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # openLastClosedFile plugin v1.0.2
  2. #
  3. # example keybinding:
  4. # <binding key="shift+ctrl+t" command="openLastClosedFile"/>
  5. #
  6. # Known issues:
  7. #       there has to be one tab open to make the keybinding work
  8.  
  9. import sublime, sublimeplugin, os
  10.  
  11. # we need to be able to load the filenames when command gets called
  12. class openLastClosedFileSecure(sublimeplugin.Plugin):
  13.         def onClose(self, view):
  14.                 # untitled / not saved files have no filename
  15.                 if view.fileName() <> None:
  16.                         file = open(sublime.packagesPath()+"\\User\\openLastClosedFile.tmp", 'a')
  17.                         file.writelines(view.fileName()+"\n")
  18.                         file.close()
  19.                
  20.                 print sublime.packagesPath()
  21.  
  22.  
  23. class openLastClosedFileCommand(sublimeplugin.TextCommand):
  24.         def run(self, view, args):
  25.                 fileName = sublime.packagesPath()+"\\User\\openLastClosedFile.tmp"
  26.  
  27.                 if os.path.isfile(fileName):
  28.                         readFile = open(fileName,"r")
  29.                         lines = readFile.readlines()
  30.                         readFile.close()
  31.  
  32.                         length = len(lines)
  33.                        
  34.                         if length > 0:
  35.                                 lastline = lines[length-1]
  36.                                 lastline = lastline.rstrip("\n")
  37.                                
  38.                                 view.window().openFile(lastline, 0, 0)
  39.                                
  40.                                 writeFile = open(fileName, "w")
  41.                                 writeFile.writelines([item for item in lines[0:length-1]])
  42.                                 writeFile.close()