Compare commits

...

1 Commits

Author SHA1 Message Date
6cfb029215 Adding end-of-line highlighting as an option 2015-02-17 13:50:00 -07:00
3 changed files with 33 additions and 1 deletions

View File

@ -45,7 +45,8 @@ 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"
}
```

View File

@ -10,10 +10,12 @@ 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_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_single_space": false,
"highlight_last_whitespace": true
}
@ -33,6 +35,7 @@ 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_LAST_WHITESPACE = False
@ -66,6 +69,8 @@ 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 ]+$')
# Highlight whitespaces
def highlight_whitespaces(view):
@ -77,6 +82,8 @@ 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)
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 +95,11 @@ 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)
# Clear all white spaces
@ -95,6 +107,7 @@ def clear_whitespaces_highlight(window):
for view in window.views():
view.erase_regions('WhitespacesHighlightListener')
view.erase_regions('WhitespacesHighlightListener2')
view.erase_regions('WhitespacesHighlightListener3')
# Toggle the event listner on or off
@ -138,3 +151,15 @@ 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)

View File

@ -5,6 +5,9 @@
// 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",
// Max file size to search
"highlight_whitespaces_file_max_size": 1048576,
@ -17,6 +20,9 @@
// Whether to check for tabs
"highlight_whitespaces_check_tabs": true,
// Whether to check for end-of-line whitespace
"highlight_whitespaces_check_eol": true,
// Allow the highlighting of the last whitespace, one or more time
"highlight_last_whitespace": true
}