Last active
November 24, 2019 17:00
-
-
Save NickWoodhams/434e185ce543ca1c8a99 to your computer and use it in GitHub Desktop.
Close Deleted File - Sublime 3 Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sublime_plugin | |
import sublime | |
import time | |
import os | |
class MyEvents(sublime_plugin.EventListener): | |
def on_deactivated_async(self, view): | |
s = view.file_name() | |
if s: | |
time.sleep(0.1) # Give the file time to be removed from the filesystem | |
if not os.path.exists(s): | |
print("Closing view", s) | |
view.set_scratch(True) | |
view.window().run_command("close_file") |
Hi, Michael!
Here is improved version:
import sublime_plugin
import os
class WatcherEvents(sublime_plugin.EventListener):
def on_activated(self, view):
for view in view.window().views():
s_file = view.file_name()
if s_file and not os.path.exists(s_file) and not s_file.endswith('-settings'):
print("File was disappeared " + s_file)
view.set_scratch(True)
view.close()
It resolved conflict with settings editor.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's my version that seems to work fine in Sublime 3.0: