Sublime Forum

Disable save when close file with certain name, on_close eventlistner

#1

So in ST4, if we close an “Untitled” tab without any text, then the save change prompt
image
will not show up.

However, if that “Untitled” tab has text or the name of the tab is something else, then the previous prompt will show up.

I am trying to create a eventlistner to disable the save prompt when the tab name is “Query Result”.

class closeFile(sublime_plugin.EventListener):
    def on_close(self, view):
        print("Run")
        if "Query Result" in view.name():
            print("Closed")
            view.close()

I created something like this, looks it runs when I close the file, but it will not close directly without show the save prompt

I also try the on_pre_close, it still doesn’t work…

Any thought on this? Thank y’all so much !

0 Likes

#2

What you want to do is set the file to be a scratch buffer. Scratch buffers don’t prompt when closing.

1 Like

#3

This is exactly what I need. Thanks for sharing!

0 Likes