Skip to content

Instantly share code, notes, and snippets.

@chikatoike
Created October 18, 2012 21:53
Show Gist options
  • Save chikatoike/3914988 to your computer and use it in GitHub Desktop.
Save chikatoike/3914988 to your computer and use it in GitHub Desktop.
Auto reload on save package files.
# package_file_reload.py
import os
import time
import sublime
import sublime_plugin
class PackageFileReloader(sublime_plugin.EventListener):
"""Auto reload on save package files. """
def on_post_save(self, view):
fname = view.file_name()
if os.path.dirname(os.path.dirname(fname)) == sublime.packages_path():
if view.scope_name(view.sel()[0].a).startswith('source.python'):
sublime_plugin.reload_plugin(fname)
elif fname.endswith('.sublime-keymap'):
touch(os.path.join(sublime.packages_path(), 'Default', 'Default (Windows).sublime-keymap'))
elif fname.endswith('.sublime-settings'):
# TODO not work
touch(os.path.join(sublime.packages_path(), 'Default', 'Preferences (Windows).sublime-settings'))
def touch(fname):
atime = mtime = time.time()
os.utime(fname, (atime, mtime))
@chikatoike
Copy link
Author

プラグインのリロードは sublime_plugin.reload_plugin を呼び出しただけではリロードされませんでした。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment