Skip to content

Commit

Permalink
Merge pull request #19 from xaka/patch-1
Browse files Browse the repository at this point in the history
Enforce settings for newly created -> saved files
  • Loading branch information
sindresorhus committed Feb 15, 2014
2 parents c1dc140 + 40ae320 commit b9431c3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions EditorConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,24 @@
}

class EditorConfig(sublime_plugin.EventListener):
MARKER = 'editorconfig'

def on_activated(self, view):
if view.settings().has('editorconfig'):
return
self.init(view, False)
view.settings().set('editorconfig', True)
if not view.settings().has(self.MARKER):
self.init(view, False)

def on_pre_save(self, view):
self.init(view, True)

def on_post_save(self, view):
if not view.settings().has(self.MARKER):
self.init(view, False)

def init(self, view, pre_save):
path = view.file_name()
if not path:
return

try:
config = get_properties(path)
except EditorConfigError:
Expand Down Expand Up @@ -80,3 +85,5 @@ def apply_config(self, view, config):
settings.set('ensure_newline_at_eof_on_save', True)
elif insert_final_newline == 'false':
settings.set('ensure_newline_at_eof_on_save', False)

view.settings().set(self.MARKER, True)

0 comments on commit b9431c3

Please sign in to comment.