Skip to content

Commit

Permalink
Only read file from disk when trim_modified_lines_only is enabled
Browse files Browse the repository at this point in the history
Reading file from disk is an expensive and blocking operation so do it only
when option that needs it is enabled.
  • Loading branch information
rcopera authored and rchl committed Mar 22, 2020
1 parent 61ab790 commit e9a3b1d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions trailing_spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
def plugin_loaded():
global ts_settings_filename, ts_settings, trailing_spaces_live_matching
global current_highlighting_scope, trim_modified_lines_only, startup_queue
global DEFAULT_COLOR_SCOPE_NAME, on_disk, trailing_spaces_syntax_ignore
global DEFAULT_COLOR_SCOPE_NAME, trailing_spaces_syntax_ignore

ts_settings = sublime.load_settings(ts_settings_filename)
trailing_spaces_live_matching = bool(ts_settings.get("trailing_spaces_enabled",
Expand Down Expand Up @@ -414,12 +414,18 @@ def on_selection_modified(self, view):
match_trailing_spaces(view)

def on_activated(self, view):
self.freeze_last_version(view)
global trim_modified_lines_only
if trim_modified_lines_only:
self.freeze_last_version(view)

if trailing_spaces_live_matching:
match_trailing_spaces(view)

def on_pre_save(self, view):
self.freeze_last_version(view)
global trim_modified_lines_only
if trim_modified_lines_only:
self.freeze_last_version(view)

if ts_settings.get("trailing_spaces_trim_on_save"):
view.run_command("delete_trailing_spaces")

Expand Down

0 comments on commit e9a3b1d

Please sign in to comment.