Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # openLastClosedFile plugin v1.0.1
- #
- # example keybinding:
- # <binding key="shift+ctrl+t" command="openLastClosedFile"/>
- import sublime, sublimeplugin, os
- from ctypes import wintypes, windll
- # portable solution, should work with win2000 and later
- CSIDL_APPDATA = 26
- _SHGetFolderPath = windll.shell32.SHGetFolderPathA
- _SHGetFolderPath.argtypes = [wintypes.HWND,
- wintypes.c_int,
- wintypes.HANDLE,
- wintypes.DWORD, wintypes.LPCSTR]
- appdataPath = wintypes.create_string_buffer(wintypes.MAX_PATH)
- result = _SHGetFolderPath(0, CSIDL_APPDATA, 0, 0, appdataPath)
- if result <> 0:
- print "[Error] SHGetFolderPath returned: " + str(result)
- # 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(appdataPath.value+"\\sublime text\\Packages\\User\\openLastClosedFile.tmp", 'a')
- file.writelines(view.fileName()+"\n")
- file.close()
- class openLastClosedFileCommand(sublimeplugin.TextCommand):
- def run(self, view, args):
- fileName = appdataPath.value+"\\sublime text\\Packages\\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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement