Compare commits

..

2 Commits

3 changed files with 70 additions and 2 deletions

View File

@ -12,7 +12,7 @@ Go to your `Packages` subdirectory under ST2's data directory:
* Windows: `%APPDATA%\Sublime Text 2`
* OS X: `~/Library/Application Support/Sublime Text 2/Packages`
* Linux: `~/.config/sublime-text-2/Packages`
* Linux: `~/.config/sublime-text-2`
* Portable Installation: `Sublime Text 2/Data`
Then clone this repository:
@ -45,7 +45,9 @@ as "invalid", "comment"... in "File Settings - User":
```
{
"highlight_whitespaces_space_highlight_scope_name": "invalid",
"highlight_whitespaces_tab_highlight_scope_name": "invalid"
"highlight_whitespaces_tab_highlight_scope_name": "invalid",
"highlight_whitespaces_eol_highlight_scope_name": "invalid",
"highlight_whitespaces_mixed_highlight_scope_name": "invalid"
}
```

View File

@ -10,10 +10,14 @@ Config summary (see README.md for details):
{
"highlight_whitespaces_space_highlight_scope_name": "invalid",
"highlight_whitespaces_tab_highlight_scope_name": "invalid",
"highlight_whitespaces_eol_highlight_scope_name": "invalid",
"highlight_whitespaces_mixed_highlight_scope_name": "invalid",
"highlight_whitespaces_file_max_size": 1048576,
"highlight_whitespaces_enabled": true,
"highlight_whitespaces_check_spaces": true,
"highlight_whitespaces_check_tabs": true,
"highlight_whitespaces_check_eol": true,
"highlight_whitespaces_check_mixed": false,
"highlight_whitespaces_single_space": false,
"highlight_last_whitespace": true
}
@ -33,7 +37,9 @@ DEFAULT_COLOR_SCOPE_NAME = "invalid"
DEFAULT_IS_ENABLED = True
DEFAULT_CHECK_SPACES = True
DEFAULT_SINGLE_SPACE = False
DEFAULT_CHECK_EOL = True
DEFAULT_CHECK_TABS = True
DEFAULT_CHECK_MIXED = True
DEFAULT_LAST_WHITESPACE = False
#Set whether the plugin is on or off
@ -66,6 +72,12 @@ def find_whitespaces_spaces(view):
def find_whitespaces_tabs(view):
return view.find_all('\t+')
def find_whitespaces_eol(view):
return view.find_all('[\t ]+$')
def find_whitespaces_mixed(view):
return view.find_all('(\t )|( \t)')
# Highlight whitespaces
def highlight_whitespaces(view):
@ -77,6 +89,10 @@ def highlight_whitespaces(view):
DEFAULT_COLOR_SCOPE_NAME)
tab_scope_name = hws_settings.get('highlight_whitespaces_tab_highlight_scope_name',
DEFAULT_COLOR_SCOPE_NAME)
eol_scope_name = hws_settings.get('highlight_whitespaces_eol_highlight_scope_name',
DEFAULT_COLOR_SCOPE_NAME)
mixed_scope_name = hws_settings.get('highlight_whitespaces_mixed_highlight_scope_name',
DEFAULT_COLOR_SCOPE_NAME)
if view.size() <= max_size and not is_find_results(view):
if hws_settings.get('highlight_whitespaces_check_spaces', DEFAULT_CHECK_SPACES):
space_regions = find_whitespaces_spaces(view)
@ -88,6 +104,16 @@ def highlight_whitespaces(view):
view.add_regions('WhitespacesHighlightListener2',
tab_regions, tab_scope_name, '',
sublime.DRAW_EMPTY)
if hws_settings.get('highlight_whitespaces_check_eol', DEFAULT_CHECK_EOL):
eol_regions = find_whitespaces_eol(view)
view.add_regions('WhitespacesHighlightListener3',
eol_regions, eol_scope_name, '',
sublime.DRAW_EMPTY)
if hws_settings.get('highlight_whitespaces_check_mixed', DEFAULT_CHECK_MIXED):
mixed_regions = find_whitespaces_mixed(view)
view.add_regions('WhitespacesHighlightListener4',
mixed_regions, mixed_scope_name, '',
sublime.DRAW_EMPTY)
# Clear all white spaces
@ -95,6 +121,8 @@ def clear_whitespaces_highlight(window):
for view in window.views():
view.erase_regions('WhitespacesHighlightListener')
view.erase_regions('WhitespacesHighlightListener2')
view.erase_regions('WhitespacesHighlightListener3')
view.erase_regions('WhitespacesHighlightListener4')
# Toggle the event listner on or off
@ -138,3 +166,28 @@ class WhitespacesHighlightListener2(sublime_plugin.EventListener):
if hws_enabled:
highlight_whitespaces(view)
class WhitespacesHighlightListener3(sublime_plugin.EventListener):
def on_modified(self, view):
if hws_enabled:
highlight_whitespaces(view)
def on_activated(self, view):
if hws_enabled:
highlight_whitespaces(view)
def on_load(self, view):
if hws_enabled:
highlight_whitespaces(view)
class WhitespacesHighlightListener4(sublime_plugin.EventListener):
def on_modified(self, view):
if hws_enabled:
highlight_whitespaces(view)
def on_activated(self, view):
if hws_enabled:
highlight_whitespaces(view)
def on_load(self, view):
if hws_enabled:
highlight_whitespaces(view)

View File

@ -5,6 +5,13 @@
// Tabs color is determined by scope (default, "invalid")
// "highlight_whitespaces_tab_highlight_scope_name": "Whitespaces.tab.highlight",
// End-of-line color is determined by scope (default, "invalid")
// "highlight_whitespaces_eol_highlight_scope_name": "Whitespaces.eol.highlight",
// End-of-line color is determined by scope (default, "invalid")
// "highlight_whitespaces_mixed_highlight_scope_name": "Whitespaces.eol.highlight",
// Max file size to search
"highlight_whitespaces_file_max_size": 1048576,
@ -17,6 +24,12 @@
// Whether to check for tabs
"highlight_whitespaces_check_tabs": true,
// Whether to check for end-of-line whitespace
"highlight_whitespaces_check_eol": true,
// Whether to check for mixed tabs and spaces
"highlight_whitespaces_check_mixed": false,
// Allow the highlighting of the last whitespace, one or more time
"highlight_last_whitespace": true
}