Created
October 18, 2012 21:53
-
-
Save chikatoike/3914988 to your computer and use it in GitHub Desktop.
Auto reload on save package files.
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
# 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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
プラグインのリロードは sublime_plugin.reload_plugin を呼び出しただけではリロードされませんでした。