Sublime Forum

Close a specific view?

#1

Hi, I’m returned a list of views from self.window.views_in_group() in WindowCommand. I’d currently like to iterate over the list of these views and based on certain criteria close them. I’m having a hard time determining how to close these views. How would I go about this?

As a bonus question: I can see that there is a ‘close’ command, but I’m unable to find any docs for this, nor am I able to locate this command so that I can find out what params I could pass it. I have been looking mainly in the Packages/Default folder. Is there a methodology I can use to find this info out?

1 Like

#2

I had to do this in the HexViewer plugin. Make sure you are focused in on the view you want to close and then issue the window command below.

self.window.focus_view(self.view) self.window.run_command("close_file")

If the view has unsaved changes, you will have a problem. If you want to close a view like this regardless of whether it has unsaved changes, I believe you can set scratch to true and then close it.

view.set_scratch(True)
1 Like

#3

Sorry for the late reply:

Thanks a lot for the tip. Works great!

1 Like

#4

I found this old thread while searching for the same thing.

Note that the ST v3 API now has an undocumented View class method called close() which closes a view; e.g. view.close(). Have a look at the View class methods in sublime.py.

A bit of dev build downloading later and I worked out that it was introduced in Sublime build 3024.

HTH.

3 Likes