Skip to content

Commit

Permalink
Force indentation on save - fixes #24
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Mar 8, 2014
1 parent 59d8dfc commit 2e68c0c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion EditorConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# Python 2
from editorconfig import get_properties, EditorConfigError


LINE_ENDINGS = {
'lf': 'unix',
'crlf': 'windows',
Expand Down Expand Up @@ -57,10 +56,15 @@ def init(self, view, pre_save):
def apply_pre_save(self, view, config):
charset = config.get('charset')
end_of_line = config.get('end_of_line')
indent_style = config.get('indent_style')
if charset in CHARSETS:
view.set_encoding(CHARSETS[charset])
if end_of_line in LINE_ENDINGS:
view.set_line_endings(LINE_ENDINGS[end_of_line])
if indent_style == 'space':
view.run_command('expand_tabs', {'set_translate_tabs': True})
elif indent_style == 'tab':
view.run_command('unexpand_tabs', {'set_translate_tabs': True})

def apply_config(self, view, config):
settings = view.settings()
Expand Down

3 comments on commit 2e68c0c

@kevinSuttle
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't add or remove spaces though. It will only convert tabs to the default amount of spaces. So, if I had 2 set as a default, it won't add 2 more to match the format spec.

@sindresorhus
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but that's sadly a limitation of Sublime.

@kevinSuttle
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. Thanks, Sindre.

Please sign in to comment.