Sublime Text 3 Api to close view?

Is there a sublime text 3 api to close the view ??? close tab

Yes, the above line completely describes my problem. But it doesn't seem to fit the requirements of this site.

+3


source to share


2 answers


I'm not sure if I am making the difference between a view and a tab.

Anyway, to close the view: view.close ()
To close the window: win.run_command ('close_window')

If you want to close the window with modified buffers, you can undo those changes by scratching the view as shown below:



for win in sublime.windows():
    for view in win.views():
        view.set_scratch(True)
    win.run_command('close_window')

      

Hope this helps.

+4


source


I found this works in Sublime 2 to close the currently active view in the window:

view.window().run_command('close_file')

      



It probably works in Sublime 3. I guessed the name of the command just by seeing that the File menu has the options Close Window (command name in the other answer) and Close File.

Doing something like view.window().open_file(view.file_name())

or view.window().focus_view(view)

before the above will probably allow you to close an arbitrary file, not just the one active before the command is executed.

+1


source







All Articles