Home Download Buy Blog Forum Support

Run a command when sublime is closed?

Run a command when sublime is closed?

Postby wasilto on Wed Nov 06, 2013 3:44 pm

I have a command to save all named files (not untitled) but named files.

How can I run this command, when Sublime closes?

No doubt i'll still get prompted if I have some untitled files, I run my command, then close sublime, and that's OK. I'll hit cancel. And deal with it.

But I want to be able to close sublime, and save those named files, without being prompted So I want to run my sublime command(which is written), but I want it to run when sublime is exited.
wasilto
 
Posts: 13
Joined: Sat Sep 07, 2013 10:53 pm

Re: Run a command when sublime is closed?

Postby skuroda on Thu Nov 07, 2013 5:00 am

If you are just trying to save files on exit, have you tried setting "hot_exit" to false?

The description of this setting is

// Exiting the application with hot_exit enabled will cause it to close
// immediately without prompting. Unsaved modifications and open files will
// be preserved and restored when next starting.

So if it's false, it follows that it would prompt you about unsaved modifications when closing.
skuroda
 
Posts: 676
Joined: Fri Oct 05, 2012 8:11 am

Re: Run a command when sublime is closed?

Postby adzenith on Thu Nov 07, 2013 5:39 pm

There's no callback when Sublime is closing.

As a workaround, you could bind cmd+q to call your function instead, and then your function could save everything and tell sublime to quit.
Also, if you set a view as scratch, then it won't ask you to save it when you close it. You could set all your untitled views to scratch mode and they would just be deleted when you close the program.
adzenith
 
Posts: 1214
Joined: Mon Oct 19, 2009 9:12 pm

Re: Run a command when sublime is closed?

Postby quodlibet on Fri Nov 08, 2013 11:14 am

I would be interested on running the project's Build command (edit: on exit), but only on a per-project setting. (Some of my text, but not code, projects, have a build command, which basically just commits all changes to the repo. Just so I can go back in time, in case I delete something useful my mistake.) Any thoughts on how I would implement this?

The @adzenith's method won't work, because it has to be per-project. (Also, I've disabled Ctrl+Q. I use my WM/OS functionality to close sublime.)

Alex
quodlibet
 
Posts: 500
Joined: Sat Jun 18, 2011 5:53 pm

Re: Run a command when sublime is closed?

Postby adzenith on Mon Nov 11, 2013 5:51 am

You could just use the same command, and have it check if a project is open before doing anything.
There's also on_pre_close, which gets fired per file... you could maybe have a counter and if enough files are closing then run your command? You could collect the filenames and run the command on the files on disk, because you aren't actually able to stop the views from closing.
adzenith
 
Posts: 1214
Joined: Mon Oct 19, 2009 9:12 pm

Re: Run a command when sublime is closed?

Postby quodlibet on Mon Nov 11, 2013 6:22 am

For what I asked about there's a plugin: https://sublime.wbond.net/packages/SublimeOnSaveBuild
quodlibet
 
Posts: 500
Joined: Sat Jun 18, 2011 5:53 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 2 guests