diff --git a/README.md b/README.md index 7e10fdd..c57f5f7 100644 --- a/README.md +++ b/README.md @@ -39,14 +39,17 @@ There are a number of configuration options available to customize the behavior Do NOT edit the default SublimeOnSaveBuild settings. Your changes will be lost when SublimeOnSaveBuild is updated. ALWAYS edit the user SublimeOnSaveBuild settings by selecting `Preferences->Package Settings->SublimeOnSaveBuild->Settings - User`. * **build_on_save** -Set to `1` to trigger a build on save. By default, this is set to `1`. I.e., SublimeOnSaveBuild attempts to build all projects. You can change this behavior and build only specific projects by configuring the user specific setting of `build_on_save` to `0` and project specific setting to `1`. +Set to `true` to trigger a build on save. By default, this is set to `true`. I.e., SublimeOnSaveBuild attempts to build all projects. You can change this behavior and build only specific projects by configuring the user specific setting of `build_on_save` to `false` and project specific setting to `true`. * **filename_filter** -SublimeOnSaveBuild matches the name of the file being saved against this regular expression to determine if a build should be triggered. By default, the setting has a value of `"\\.(css|js|sass|less|scss)$"`. +SublimeOnSaveBuild matches the name of the file being saved against this regular expression to determine if a build should be triggered. By default, the setting has a value of `"(?!.sublime-settings|.md)\\..*$",` which matches any file extensions excluding .sublime-settings or .md files. + +* **verbose** +Whether to print a message whenever a save-on-build is detected. Defaults to `false`. Usage ----- 1. Make sure you have a build operation set up in your Sublime Text 2 project and you are able to build using `Control+B` (Linux/Windows) or `Command+B` (OS X). 2. Hit your favorite shortcut to Saveit should trigger a build. -*Good luck!* \ No newline at end of file +*Good luck!* diff --git a/SublimeOnSaveBuild.py b/SublimeOnSaveBuild.py index 2f3c444..6b33e4d 100644 --- a/SublimeOnSaveBuild.py +++ b/SublimeOnSaveBuild.py @@ -6,19 +6,18 @@ class SublimeOnSaveBuild(sublime_plugin.EventListener): def on_post_save(self, view): global_settings = sublime.load_settings(self.__class__.__name__+'.sublime-settings') + view_settings = view.settings() + cur_window = view.window() # 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. - should_build = view.settings().get('build_on_save', global_settings.get('build_on_save', True)) + build_on_save = view_settings.get('build_on_save', global_settings.get('build_on_save', True)) + filename_filter = view_settings.get('filename_filter', global_settings.get('filename_filter', '.*')) + verbose = view_settings.get('verbose', global_settings.get('verbose', False)) - # Load filename filter. Again, a project level setting takes precedence. - filename_filter = view.settings().get('filename_filter', global_settings.get('filename_filter', '.*')) - - if not should_build: - return - - if not re.search(filename_filter, view.file_name()): - return - - view.window().run_command('build') + # check if it is a project and supports building... + if build_on_save and cur_window.project_data() and re.search(filename_filter, view.file_name()): + if verbose: + print('Save detected, running build.') + cur_window.run_command('build') \ No newline at end of file diff --git a/SublimeOnSaveBuild.sublime-settings b/SublimeOnSaveBuild.sublime-settings index 0370322..6b5cdde 100644 --- a/SublimeOnSaveBuild.sublime-settings +++ b/SublimeOnSaveBuild.sublime-settings @@ -1,4 +1,8 @@ { - "filename_filter": "\\.(css|js|sass|less|scss)$", - "build_on_save": 1 + // Match everything except .sublime-settings files. + "filename_filter": "(?!.sublime-settings|.md)\\..*$", + // Match only .css, .js, .sass, .less, .scss. + // "filename_filter": "\\.(css|js|sass|less|scss)$", + "build_on_save": true, + "verbose": false } \ No newline at end of file