diff --git a/SublimeOnSaveBuild.py b/SublimeOnSaveBuild.py index 2f3c444..5c5b0af 100644 --- a/SublimeOnSaveBuild.py +++ b/SublimeOnSaveBuild.py @@ -1,12 +1,12 @@ import sublime import sublime_plugin import re +import os class SublimeOnSaveBuild(sublime_plugin.EventListener): def on_post_save(self, view): global_settings = sublime.load_settings(self.__class__.__name__+'.sublime-settings') - # See if we should build. A project level build_on_save setting # takes precedence. To be backward compatible, we assume the global # build_on_save to be true if not defined. @@ -15,10 +15,25 @@ def on_post_save(self, view): # Load filename filter. Again, a project level setting takes precedence. filename_filter = view.settings().get('filename_filter', global_settings.get('filename_filter', '.*')) + # filename_ignore + filename_ignore = view.settings().get('filename_ignore', global_settings.get('filename_ignore')) + if not should_build: return if not re.search(filename_filter, view.file_name()): return + if filename_ignore and re.search(filename_ignore, os.path.basename(view.file_name())): + return + view.window().run_command('build') + + + +class SublimeOnSaveBuildToggleCommand(sublime_plugin.TextCommand): + def run(self, view, enable=True): + setting_filename = "SublimeOnSaveBuild.sublime-settings" + settings = sublime.load_settings(setting_filename) + settings.set('build_on_save', enable) + sublime.save_settings(setting_filename) \ No newline at end of file diff --git a/SublimeOnSaveBuild.sublime-commands b/SublimeOnSaveBuild.sublime-commands new file mode 100644 index 0000000..692f793 --- /dev/null +++ b/SublimeOnSaveBuild.sublime-commands @@ -0,0 +1,21 @@ +[ + { + "caption": "SublimeOnSaveBuild: Setting", + "command": "open_file", + "args": {"file": "${packages}/User/SublimeOnSaveBuild.sublime-settings"} + }, + { + "caption": "SublimeOnSaveBuild: Enable", + "command": "sublime_on_save_build_toggle", + "args": { + "enable": true + } + }, + { + "caption": "SublimeOnSaveBuild: Disable", + "command": "sublime_on_save_build_toggle", + "args": { + "enable": false + } + } +] diff --git a/SublimeOnSaveBuild.sublime-settings b/SublimeOnSaveBuild.sublime-settings index 0370322..595d341 100644 --- a/SublimeOnSaveBuild.sublime-settings +++ b/SublimeOnSaveBuild.sublime-settings @@ -1,4 +1,5 @@ { "filename_filter": "\\.(css|js|sass|less|scss)$", + "filename_ignore" : "^_+", "build_on_save": 1 } \ No newline at end of file