Adding support for mixed tab-and-space detection
This commit is contained in:
parent
6cfb029215
commit
bb0207c1e7
|
@ -46,7 +46,8 @@ as "invalid", "comment"... in "File Settings - User":
|
|||
{
|
||||
"highlight_whitespaces_space_highlight_scope_name": "invalid",
|
||||
"highlight_whitespaces_tab_highlight_scope_name": "invalid",
|
||||
"highlight_whitespaces_eol_highlight_scope_name": "invalid"
|
||||
"highlight_whitespaces_eol_highlight_scope_name": "invalid",
|
||||
"highlight_whitespaces_mixed_highlight_scope_name": "invalid"
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -11,11 +11,13 @@ 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
|
||||
}
|
||||
|
@ -37,6 +39,7 @@ 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
|
||||
|
@ -72,6 +75,10 @@ def find_whitespaces_tabs(view):
|
|||
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):
|
||||
hws_settings = get_settings()
|
||||
|
@ -84,6 +91,8 @@ def highlight_whitespaces(view):
|
|||
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)
|
||||
|
@ -100,6 +109,11 @@ def highlight_whitespaces(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
|
||||
|
@ -108,6 +122,7 @@ def clear_whitespaces_highlight(window):
|
|||
view.erase_regions('WhitespacesHighlightListener')
|
||||
view.erase_regions('WhitespacesHighlightListener2')
|
||||
view.erase_regions('WhitespacesHighlightListener3')
|
||||
view.erase_regions('WhitespacesHighlightListener4')
|
||||
|
||||
|
||||
# Toggle the event listner on or off
|
||||
|
@ -163,3 +178,16 @@ class WhitespacesHighlightListener3(sublime_plugin.EventListener):
|
|||
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)
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
// 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,
|
||||
|
||||
|
@ -23,6 +27,9 @@
|
|||
// 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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user