Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f030fe86ee | ||
|
|
42b9b62842 | ||
|
|
e363121abb | ||
|
|
0060617485 | ||
|
|
1df06d1ada | ||
|
|
1067d50461 | ||
|
|
7c8152b0d6 | ||
|
|
148ad95966 | ||
|
|
dc3c860a25 | ||
|
|
551cf1e378 | ||
|
|
e9d8a6dd6e | ||
|
|
87141119fa | ||
|
|
17ca7f2616 | ||
|
|
04b88f15bd | ||
|
|
36f90560f4 |
10
README.md
10
README.md
@@ -1,6 +1,6 @@
|
||||
## Synopsis
|
||||
|
||||
This is a [Sublime Text 2](http://www.sublimetext.com/2) plugin.
|
||||
This is a plugin for [Sublime Text 2](http://www.sublimetext.com/2) and [3](http://www.sublimetext.com/3).
|
||||
|
||||
**Highlight whitespaces in documents**
|
||||
|
||||
@@ -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`
|
||||
* Linux: `~/.config/sublime-text-2/Packages`
|
||||
* Portable Installation: `Sublime Text 2/Data`
|
||||
|
||||
Then clone this repository:
|
||||
@@ -21,6 +21,8 @@ Then clone this repository:
|
||||
|
||||
That's it!
|
||||
|
||||
Note for ST3 users: For Sublime Text 3, replace "2" with "3" in path names. (`%APPDATA%\Sublime Text 3` and so on)
|
||||
|
||||
## Options
|
||||
|
||||
Several options are available to customize the plugin look 'n feel. The
|
||||
@@ -31,6 +33,10 @@ menu.
|
||||
|
||||
The default toggle highlight shortcut is ```ctrl+alt+w``` (```cmd+alt+w``` for OS X)
|
||||
|
||||
### Disable highlighting when Sublime Text starts up
|
||||
|
||||
Change `highlight_whitespaces_enabled` from the default of `true` to `false`.
|
||||
|
||||
### Change the highlighting color
|
||||
|
||||
One may also change the highlighting color, providing a scope name such
|
||||
|
||||
@@ -11,7 +11,11 @@ Config summary (see README.md for details):
|
||||
"highlight_whitespaces_space_highlight_scope_name": "invalid",
|
||||
"highlight_whitespaces_tab_highlight_scope_name": "invalid",
|
||||
"highlight_whitespaces_file_max_size": 1048576,
|
||||
"highlight_whitespaces_enabled": true
|
||||
"highlight_whitespaces_enabled": true,
|
||||
"highlight_whitespaces_check_spaces": true,
|
||||
"highlight_whitespaces_check_tabs": true,
|
||||
"highlight_whitespaces_single_space": false,
|
||||
"highlight_last_whitespace": true
|
||||
}
|
||||
|
||||
Forked from https://github.com/SublimeText/TrailingSpaces/ by Jean-Denis Vauguet <jd@vauguet.fr>, Oktay Acikalin <ok@ryotic.de>
|
||||
@@ -27,19 +31,37 @@ import sublime_plugin
|
||||
DEFAULT_MAX_FILE_SIZE = 1048576
|
||||
DEFAULT_COLOR_SCOPE_NAME = "invalid"
|
||||
DEFAULT_IS_ENABLED = True
|
||||
DEFAULT_CHECK_SPACES = True
|
||||
DEFAULT_SINGLE_SPACE = False
|
||||
DEFAULT_CHECK_TABS = True
|
||||
DEFAULT_LAST_WHITESPACE = False
|
||||
|
||||
#Set whether the plugin is on or off
|
||||
hws_settings = sublime.load_settings('highlight_whitespaces.sublime-settings')
|
||||
hws_enabled = bool(hws_settings.get('highlight_whitespaces_enabled',
|
||||
DEFAULT_IS_ENABLED))
|
||||
|
||||
def get_settings():
|
||||
s = sublime.load_settings('highlight_whitespaces.sublime-settings')
|
||||
return s
|
||||
|
||||
# Determine if the view is a find results view
|
||||
def is_find_results(view):
|
||||
return view.settings().get('syntax') and "Find Results" in view.settings().get('syntax')
|
||||
|
||||
# Return an array of regions matching whitespaces.
|
||||
def find_whitespaces_spaces(view):
|
||||
return view.find_all(' {2,}')
|
||||
hws_settings = get_settings()
|
||||
last_whitespace = bool(hws_settings.get('highlight_last_whitespace',DEFAULT_LAST_WHITESPACE))
|
||||
single_space = bool(hws_settings.get('highlight_whitespaces_single_space',DEFAULT_SINGLE_SPACE))
|
||||
if single_space:
|
||||
regex = ' +'
|
||||
else:
|
||||
regex = ' {2,}|\t | \t'
|
||||
if last_whitespace:
|
||||
regex += '| {1,}$'
|
||||
|
||||
return view.find_all(regex)
|
||||
|
||||
def find_whitespaces_tabs(view):
|
||||
return view.find_all('\t+')
|
||||
@@ -47,6 +69,8 @@ def find_whitespaces_tabs(view):
|
||||
|
||||
# Highlight whitespaces
|
||||
def highlight_whitespaces(view):
|
||||
hws_settings = get_settings()
|
||||
|
||||
max_size = hws_settings.get('highlight_whitespaces_file_max_size',
|
||||
DEFAULT_MAX_FILE_SIZE)
|
||||
space_scope_name = hws_settings.get('highlight_whitespaces_space_highlight_scope_name',
|
||||
@@ -54,14 +78,16 @@ def highlight_whitespaces(view):
|
||||
tab_scope_name = hws_settings.get('highlight_whitespaces_tab_highlight_scope_name',
|
||||
DEFAULT_COLOR_SCOPE_NAME)
|
||||
if view.size() <= max_size and not is_find_results(view):
|
||||
space_regions = find_whitespaces_spaces(view)
|
||||
view.add_regions('WhitespacesHighlightListener',
|
||||
space_regions, space_scope_name,
|
||||
sublime.DRAW_EMPTY)
|
||||
tab_regions = find_whitespaces_tabs(view)
|
||||
view.add_regions('WhitespacesHighlightListener2',
|
||||
tab_regions, tab_scope_name,
|
||||
sublime.DRAW_EMPTY)
|
||||
if hws_settings.get('highlight_whitespaces_check_spaces', DEFAULT_CHECK_SPACES):
|
||||
space_regions = find_whitespaces_spaces(view)
|
||||
view.add_regions('WhitespacesHighlightListener',
|
||||
space_regions, space_scope_name, '',
|
||||
sublime.DRAW_EMPTY)
|
||||
if hws_settings.get('highlight_whitespaces_check_tabs', DEFAULT_CHECK_TABS):
|
||||
tab_regions = find_whitespaces_tabs(view)
|
||||
view.add_regions('WhitespacesHighlightListener2',
|
||||
tab_regions, tab_scope_name, '',
|
||||
sublime.DRAW_EMPTY)
|
||||
|
||||
|
||||
# Clear all white spaces
|
||||
|
||||
@@ -1,13 +1,22 @@
|
||||
{
|
||||
// Spaces color is determined by scope (default, "invalid")
|
||||
// Spaces color is determined by scope (default, "invalid")
|
||||
// "highlight_whitespaces_space_highlight_scope_name": "Whitespaces.space.highlight",
|
||||
|
||||
// Tabs color is determined by scope (default, "invalid")
|
||||
// Tabs color is determined by scope (default, "invalid")
|
||||
// "highlight_whitespaces_tab_highlight_scope_name": "Whitespaces.tab.highlight",
|
||||
|
||||
// Max file size to search
|
||||
// Max file size to search
|
||||
"highlight_whitespaces_file_max_size": 1048576,
|
||||
|
||||
// By default plugin is enabled or disabled (true|false)
|
||||
"highlight_whitespaces_enabled": true
|
||||
// By default plugin is enabled or disabled (true|false)
|
||||
"highlight_whitespaces_enabled": true,
|
||||
|
||||
// Whether to check for spaces
|
||||
"highlight_whitespaces_check_spaces": true,
|
||||
|
||||
// Whether to check for tabs
|
||||
"highlight_whitespaces_check_tabs": true,
|
||||
|
||||
// Allow the highlighting of the last whitespace, one or more time
|
||||
"highlight_last_whitespace": true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user