Advertisement
Guest User

Sublime text reopen closed tab plugin

a guest
Mar 26th, 2010
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement