简体   繁体   中英

How can I automatically close files/tabs in sublime text 2 or 3 from the previous branch on git checkout of new branch?

How can I automatically close files/tabs in sublime text 2 or 3 from the previous branch on git checkout of new branch? I couldn't find any plugins for this. I have tried sublimegit, git,savvygit plugins. But whenever I change branch or checkout a new branch, the files (tabs) that don't exist in the new branch remain open and marked unsaved. I find this a little confusing. Any solutions?

The solution could be to write a plugin, which closes the views for which the corresponding file does not exists. This does not interact with svn or gut, but should have your desired behavior in the most cases. However be careful, that you don't have text only in ST without saving it in a file. Press Tools >> Developer >> New Plugin... and paste:

import os
import sublime_plugin


class CloseUnsavedFilesCommand(sublime_plugin.WindowCommand):
    def run(self):
        window = self.window
        for v in window.views():
            file_name = v.file_name()
            if file_name and not os.path.exists(file_name):
                print("Close: '{0}'".format(file_name))
                v.set_scratch(True)
                window.focus_view(v)
                window.run_command("close")

Now open the console ctrl+` and write window.run_command("close_unsaved_files") or create a keybinding for close_unsaved_files .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM