Reputation: 1305
Is there a way in Sublime Text to detect before window is closing to add a custom command?
I run a custom command with this shortcuts:
[
{ "keys": ["ctrl+shift+w"], "command": "custom_command"},
{ "keys": ["alt+f4"], "command": "custom_command"}
]
But there are other ways to close Sublime Text and makes sense that a before closing window event should cover all.
Upvotes: 1
Views: 498
Reputation: 3749
Maybe python's atexit
https://docs.python.org/3/library/atexit.html would work.
(I have not tried it - it is possible that python plugin API will not be fully working at the time atexit
functions are called)
Upvotes: 0
Reputation: 48
There is an event handler function that gets called before a view is closed. I think the name of the function you need is
on_pre_close(view)
All event handler functions are listed within the Sublime Text 3 API. I didn't find one for when the window is closed but I think when the window is going to close, it should close each view first, so using the above function should solve your problem. Here is the link to the Event Listeners section of the API. It should help you.
https://www.sublimetext.com/docs/3/api_reference.html#sublime_plugin.EventListener
Incase you are new to building plugins, Note that to use Event Listener functions you will need to have a plugin in which you have a class like this
class your_class_name(sublime_plugin.EventListener):
def on_pre_close(self,view):
#Your code here
Upvotes: 1