Getting the Sublime Text recently closed file list with the API -


is there way list of closed files using sublime text api?

the where list of recent files stored? question says stored in session.sublime_session config file, although think file updated when st closes , files closed during current session in auto save session.sublime_session.

however .sublime_session files can not loaded using api's load_settings(base_name) method. not @ sure safe open .sublime_session file directly.

you can open closed files using following command (indexed 0)...

sublime.active_window().run_command('open_recent_file', {"index": 0}) 

...but there way of getting list of closed files instead (with api)?

if not, safe open auto save session.sublime_session reading?

thanks.

firstly, far can tell, safe open auto save session.sublime_session reading.

auto save session.sublime_session file has 'live' data in st v3; looks st v2 uses session.sublime_session , not use auto save equivalent.

the list of closed files stored in json using file_history key. more complex had realized. closed file lists held each individual window, can seen if there multiple st windows open, open recent in file menu show files have been closed in window only.

the closed file lists (note: plural) can retrieved using following:

win_index = 0 auto_save_session_path = "/path/to/auto save session.sublime_session" open(auto_save_session_path) session_data_file:     session_data = json.load(session_data_file)     recently_closed_files = session_data["windows"][win_index]["file_history"] 

clearly retrieves first window's file_history, them necessary loop through list of window entries held in windows key.

so window in json corresponds active st window?

unfortunately turns out more tricky i'd hoped. each entry in windows key list has helpful sounding window_id, e.g. "window_id": 425, value not correspond integer returned api's sublime.active_window().id() method. json "window_id": 425 entry in file corresponded window id() number 3. st holds (at least) 2 different ids each window, 1 .sublime_session files , 1 python api.

the way can see id active window using window's open buffers. each entry in json windows key list has buffers list holds open files in window, these compared files open in active window (which retrieved using api) determine window entry in json file contains closed file list of active st window.

this method have theoretical pitfalls. example wouldn't work if there 2 windows open no open files in them or if single file (the same one) open in 2 windows. of course in real world usage wouldn't happen; multiple windows opened users can have different files in them.

it turns out there problem; frequency auto save session.sublime_session updated. don't think there static fixed time interval. saving file triggers immediate update, opening , closing files , windows not, , there gap of @ least several minutes between updates.

this means plugin uses closed file list .sublime_session file can not guarantee contain closed file.

keith's suggestion monitor file closures , maintain independent list of closed files, done gotorecent, seem way forward, until such time st api adds ability closed files lists.

i hope helps looking issue or wants use .sublime_session file other data.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -