Skip to content

Instantly share code, notes, and snippets.

@twome
Forked from michaelkonecny/close_deleted_files.py
Last active January 30, 2019 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twome/961b1381bce959e1f90ef6f53739ff67 to your computer and use it in GitHub Desktop.
Save twome/961b1381bce959e1f90ef6f53739ff67 to your computer and use it in GitHub Desktop.
Sublime Text plugin - close tabs containing deleted files on refocus
"""
When a view is focused, goes through all open tabs and closes those, whose files don't exist anymore.
Tested in Sublime Text 3.0 macOS 10.14.2
"""
import sublime_plugin
import sublime
import time
import os
class MyEvents(sublime_plugin.EventListener):
def on_activated(self, view):
window = view.window()
open_views = window.views()
for v in open_views:
s = v.file_name()
if s:
if not os.path.exists(s):
print("Closing view", s)
v.set_scratch(True)
window.focus_view(v)
window.run_command("close_file")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment