Skip to content

Commit

Permalink
Merge pull request #30 from temoto/patch-1
Browse files Browse the repository at this point in the history
support per-project settings
  • Loading branch information
taylor committed May 28, 2016
2 parents 75a2efe + 96526b4 commit 8058bbf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,21 @@ Use
http://clang.llvm.org/docs/ClangFormatStyleOptions.html.
- Settings for the 'Custom' format and others are available through the Sublime
Text preferences.
- It is possible to enable the formatter on every
save to a C/C++ file. To change settings on a per-package basis, check out the
package "Project-Specific".
- It is possible to run the formatter on every save to a file, change settings
to `"format_on_save": true`.
- To change settings on a per-package basis, add them under `ClangFormat` key,
example project.sublime-settings:

```json
{
"folders": [],
"settings": {
"ClangFormat": {
"format_on_save": true
}
}
}
```


If You Liked This
Expand Down
12 changes: 7 additions & 5 deletions clang_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,14 @@ def load_settings():
global style
global format_on_save
global languages
settings = sublime.load_settings(settings_file)
settings_global = sublime.load_settings(settings_file)
settings_local = sublime.active_window().active_view().settings().get('ClangFormat', {})
load = lambda name, default: settings_local.get(name, settings_global.get(name, default))
# Load settings, with defaults.
binary = settings.get('binary', default_binary)
style = settings.get('style', styles[0] )
format_on_save = settings.get('format_on_save', False )
languages = settings.get('languages', ['C', 'C++', 'C++11', 'JavaScript'])
binary = load('binary', default_binary)
style = load('style', styles[0])
format_on_save = load('format_on_save', False)
languages = load('languages', ['C', 'C++', 'C++11', 'JavaScript'])

def is_supported(lang):
load_settings()
Expand Down

0 comments on commit 8058bbf

Please sign in to comment.