Home Download Buy Blog Forum Support

Close tab after delete file?

Close tab after delete file?

Postby danghm on Wed Mar 20, 2013 12:51 pm

Can ST2 auto close tab after the file was deleted? I delete file because I don't need it anymore, but then I must close the tab manually. It's so annoying :shock:
danghm
 
Posts: 2
Joined: Wed Mar 20, 2013 12:29 pm

Re: Close tab after delete file?

Postby cutcopypaste on Fri Oct 18, 2013 7:29 pm

Totally agree!

I am constantly hitting save on deleted files by accident and thereby undeleting them. often don't realize I've done it for a while
cutcopypaste
 
Posts: 41
Joined: Tue Feb 21, 2012 9:43 pm

Re: Close tab after delete file?

Postby skuroda on Sat Oct 19, 2013 6:17 pm

You can do this with a plugin. I didn't really test this much, so you may want to test on non critical stuff first. It does just close the view, so worst case is that you lose some existing work. That being said, I'm pretty sure it works fine.

Code: Select all
import sublime_plugin
import os
class MyEvents(sublime_plugin.EventListener):
    def on_activated(self, view):
        if view.file_name():
            if not os.path.exists(view.file_name()):
                view.set_scratch(True)
                view.window().run_command("close")
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am

Re: Close tab after delete file?

Postby Evoken on Sat Oct 19, 2013 11:33 pm

I agree, it would be nice to have ST close the tab of a deleted file.
Evoken
 
Posts: 33
Joined: Sat Feb 16, 2013 3:31 pm

Re: Close tab after delete file?

Postby tobi73de on Wed Oct 23, 2013 1:48 pm

@skuroda cool, thx, works nice 8-)
tobi73de
 
Posts: 30
Joined: Tue Jan 29, 2013 8:02 pm

Re: Close tab after delete file?

Postby cutcopypaste on Tue Oct 29, 2013 2:24 am

How do I add this? Just make a new plugin folder?
cutcopypaste
 
Posts: 41
Joined: Tue Feb 21, 2012 9:43 pm

Re: Close tab after delete file?

Postby skuroda on Tue Oct 29, 2013 7:43 am

Go to "Tools -> New Plugin". Paste the content I posted above into the file. Save it into "Packages/User". You can choose whatever file name you want, just be sure the extension is ".py"
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am

Re: Close tab after delete file?

Postby tobi73de on Wed Nov 06, 2013 10:21 am

Theres a Problem with the plugin, i just found out that the Default-Settings-Files, also Default-Keymap, are not displayed anymore, they get instantly closed after opening.

So you can not view the default settings of Sublimetext or other Plugins.

I just upgraded the script a little bit. Now it checks first if the file is not a kind of "Default"-file.

Code: Select all
import sublime_plugin
import os

class MyEvents( sublime_plugin.EventListener ):
    def on_activated( self, view ):

        s = view.file_name()

        if s:
            if not os.path.exists( s ):

                if not "Default" in s:
                    view.set_scratch( True )
                    view.window().run_command( "close_file" )
tobi73de
 
Posts: 30
Joined: Tue Jan 29, 2013 8:02 pm

Re: Close tab after delete file?

Postby fusiongrokker on Wed Jan 22, 2014 10:48 pm

Any chance this plugin can be updated for ST3? Doesn't seem to work there for me.

Or maybe I'm doing something wrong? I've added it to packages/user as CloseDeletedTabs.py, and even went so far as to restart Sublime, but it doesn't seem to do anything. The tab stays open after deleting the file.
fusiongrokker
 
Posts: 2
Joined: Sun Dec 09, 2012 1:07 am

Re: Close tab after delete file?

Postby MarcinSz on Wed Jan 22, 2014 11:34 pm

So I hadn't ever looked at plugins in ST3 before, but I've done some research and found that in ST3 plugins don't run on the main thread, so you need to use sublime.set_timeout to run the close_file command on the main thread and avoid a crash.

This seems to work for me in ST3 on OSX:

Code: Select all
import sublime_plugin
import sublime
import os

class MyEvents( sublime_plugin.EventListener ):
   def on_activated( self, view ):
      s = view.file_name()

      if s:
         if not os.path.exists( s ):
            if not "Default" in s:
               view.set_scratch( True )
               sublime.set_timeout(lambda: view.window().run_command("close_file"), 0)
MarcinSz
 
Posts: 1
Joined: Wed Jan 22, 2014 11:32 pm


Return to General Discussion

Who is online

Users browsing this forum: violacase and 17 guests