Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project check settings, new verbose option, default filename_filter... #25

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!*
*Good luck!*
21 changes: 10 additions & 11 deletions SublimeOnSaveBuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
8 changes: 6 additions & 2 deletions SublimeOnSaveBuild.sublime-settings
Original file line number Diff line number Diff line change
@@ -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
}