Skip to content
Merged
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
18 changes: 10 additions & 8 deletions trailing_spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,28 @@
INITIAL_HIGHLIGHT_COLOR = None
HIGHLIGHT_REGION_KEY = 'TrailingSpacesHighlightedRegions'
settings = None
named_settings = None


def plugin_loaded():
global settings, current_highlight_color, INITIAL_HIGHLIGHT_COLOR
global settings, named_settings, current_highlight_color, INITIAL_HIGHLIGHT_COLOR

# A settings layer that handled settings that included `trailing_spaces_` prefix (now deprecated).
# A settings layer that handles settings with the `trailing_spaces_` prefix (now deprecated).
class DeprecatedSettingsDict(NamedSettingsDict):
def __getitem__(self, key):
return super().__getitem__('trailing_spaces_%s' % key)

deprecated_settings = DeprecatedSettingsDict(SETTINGS_FILENAME)
settings = ChainMap(deprecated_settings, NamedSettingsDict(SETTINGS_FILENAME), DEFAULT_SETTINGS)
named_settings = NamedSettingsDict(SETTINGS_FILENAME)
settings = ChainMap(deprecated_settings, named_settings, DEFAULT_SETTINGS)

current_highlight_color = settings['highlight_color']
INITIAL_HIGHLIGHT_COLOR = current_highlight_color

if not settings['enabled']:
current_highlight_color = ""
if settings['highlight_color'] != current_highlight_color:
settings[0].save()
named_settings.save()


# Private: Makes sure all timers are stopped.
Expand Down Expand Up @@ -376,8 +378,8 @@ def run(self):
return

state = toggle_highlighting(view)
settings['highlight_color'] = current_highlight_color
settings[0].save()
named_settings['highlight_color'] = current_highlight_color
named_settings.save()
sublime.status_message('Highlighting of trailing spaces is %s' % state)

def is_checked(self):
Expand All @@ -388,8 +390,8 @@ def is_checked(self):
class ToggleTrailingSpacesModifiedLinesOnlyCommand(sublime_plugin.WindowCommand):
def run(self):
was_on = settings['modified_lines_only']
settings['modified_lines_only'] = not was_on
settings[0].save()
named_settings['modified_lines_only'] = not was_on
named_settings.save()

message = "Let's trim trailing spaces everywhere" if was_on \
else "Let's trim trailing spaces only on modified lines"
Expand Down