-Add settings file and load it from main script

-Change enable variable name so that it matches current naming convention
-Add Trailing Space commands to the command palette so that delete and toggle can be called even without shortcuts defined
This commit is contained in:
facelessuser 2011-10-19 19:30:30 -06:00
parent 710a69fd87
commit 0c7c1e4ca4
3 changed files with 35 additions and 13 deletions

10
Default.sublime-commands Normal file
View File

@ -0,0 +1,10 @@
[
{
"caption": "Trailing Spaces: Toggle Trailing Spaces",
"command": "toggle_trailing_spaces"
},
{
"caption": "Trailing Spaces: Delete Trailing Spaces",
"command": "delete_trailing_spaces"
}
]

View File

@ -25,7 +25,9 @@ DEFAULT_COLOR_SCOPE_NAME = "invalid"
DEFAULT_IS_ENABLED = True DEFAULT_IS_ENABLED = True
#Set whether the plugin is on or off #Set whether the plugin is on or off
TrailingSpacesEnabled = DEFAULT_IS_ENABLED ts_settings = sublime.load_settings('trailing_spaces.sublime-settings')
trailing_spaces_enabled = bool(ts_settings.get('trailing_spaces_enabled',
DEFAULT_IS_ENABLED))
# Return an array of regions matching trailing spaces. # Return an array of regions matching trailing spaces.
@ -35,9 +37,9 @@ def find_trailing_spaces(view):
# Highlight trailing spaces # Highlight trailing spaces
def highlight_trailing_spaces(view): def highlight_trailing_spaces(view):
max_size = view.settings().get('trailing_spaces_file_max_size', max_size = ts_settings.get('trailing_spaces_file_max_size',
DEFAULT_MAX_FILE_SIZE) DEFAULT_MAX_FILE_SIZE)
color_scope_name = view.settings().get('trailing_spaces_highlight_color', color_scope_name = ts_settings.get('trailing_spaces_highlight_color',
DEFAULT_COLOR_SCOPE_NAME) DEFAULT_COLOR_SCOPE_NAME)
if view.size() <= max_size: if view.size() <= max_size:
regions = find_trailing_spaces(view) regions = find_trailing_spaces(view)
@ -55,12 +57,12 @@ def clear_trailing_spaces_highlight(window):
# Toggle the event listner on or off # Toggle the event listner on or off
class ToggleTrailingSpacesCommand(sublime_plugin.WindowCommand): class ToggleTrailingSpacesCommand(sublime_plugin.WindowCommand):
def run(self): def run(self):
global TrailingSpacesEnabled global trailing_spaces_enabled
TrailingSpacesEnabled = False if TrailingSpacesEnabled else True trailing_spaces_enabled = False if trailing_spaces_enabled else True
# If toggling on go ahead and perform a pass, # If toggling on, go ahead and perform a pass,
# if not clear the highlighting in all views # else clear the highlighting in all views
if TrailingSpacesEnabled: if trailing_spaces_enabled:
highlight_trailing_spaces(self.window.active_view()) highlight_trailing_spaces(self.window.active_view())
else: else:
clear_trailing_spaces_highlight(self.window) clear_trailing_spaces_highlight(self.window)
@ -69,15 +71,15 @@ class ToggleTrailingSpacesCommand(sublime_plugin.WindowCommand):
# Highlight matching regions. # Highlight matching regions.
class TrailingSpacesHighlightListener(sublime_plugin.EventListener): class TrailingSpacesHighlightListener(sublime_plugin.EventListener):
def on_modified(self, view): def on_modified(self, view):
if TrailingSpacesEnabled: if trailing_spaces_enabled:
highlight_trailing_spaces(view) highlight_trailing_spaces(view)
def on_activated(self, view): def on_activated(self, view):
if TrailingSpacesEnabled: if trailing_spaces_enabled:
highlight_trailing_spaces(view) highlight_trailing_spaces(view)
def on_load(self, view): def on_load(self, view):
if TrailingSpacesEnabled: if trailing_spaces_enabled:
highlight_trailing_spaces(view) highlight_trailing_spaces(view)

View File

@ -0,0 +1,10 @@
{
// Color is determined by scope
"trailing_spaces_highlight_color" : "invalid",
// Max file size to search
"trailing_spaces_file_max_size" : 1048576,
// By default plugin is enabled or disabled (true|false)
"trailing_spaces_enabled" : true
}