Sublime Forum

Do now show the save popup when closing persisted file and having save_on_focus_lost": true

#1

I don’t really know if it is a feature or a bug but when I have a "save_on_focus_lost": true option set and close changed persisted file it is being saved because of that option and then I get the popup asking me if I want to save the file.

So current behavior is:

  1. Set save_on_focus_lost setting to true
  2. Open persisted file and make some changes
  3. Close the file (i.e. using shortcut CTRL + W)
  4. Get the Save changes to file before closing? popup.
  5. File is being saved because of lost focus

Proposed behavior is:

  1. Set save_on_focus_lost setting to true
  2. Open persisted file and make some changes
  3. Close the file (i.e. using shortcut CTRL + W)
  4. Just save the file and close the windows without any popups.

Thanks in advance.

0 Likes

#2

I don’t think that’s a bug because losing focus and explicitly closing a file are two different things; save_on_focus_lost saves the file when you switch the active view to a different file or switch to an entirely different application.

That said, its a simple matter to create a command that saves a file on close without prompting you first if that’s what you want to do. For example, save this in Packages\User\save_and_quit.py or something similar (the location and extension of the file is the important part):

import sublime
import sublime_plugin

class SaveAndCloseCommand(sublime_plugin.WindowCommand):
    def run(self):
        self.window.run_command ("save")
        self.window.run_command ("close")

Then you can remap Ctrl+W to the save_and_close command instead of the close command that it defaults to. This could be enhanced to check the state of the setting if you only want this to take effect on certain projects or whatever.

There may be a command that already does this; I did only a simple search to check, nothing overly exhaustive.

1 Like

#3
2 Likes

#4

I may have mis-parsed what you were saying there, in which case I apologize. The first part now looks like you’re saying that it saves the file even if you didn’t want to but the second part seems like you want to save and close in a single operation.

0 Likes

#5

No, you are actually right, I want to save file as often as possible and not to bother me with useless modal dialogs. Also thanks for save and close snippet.

The main advantage of this setting for me is from the one side I want editor to save everything that I type and from other - not to trigger any software that is watching filesystem (i.e. tests autorunner, auto build system, etc.). And from that perspective this setting is almost perfect.

0 Likes