Skip to content

Commit 6bf6b88

Browse files
smanolloffrchl
authored andcommitted
New config option: trailing_spaces_scope_ignore
Defaults to ignoring find-in-files, diff and build output views. Also, remove mentions of the inferior `trailing_spaces_syntax_ignore` option in the README (still considered in the code for backward compat)
1 parent 0c58ab2 commit 6bf6b88

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,22 @@ a binding for the toggling command. When "On-demand Matching" is on and some
276276
trailing spaces are highlighted, added ones will obviously not be. Toggling
277277
highlight off and on will refresh them.
278278

279-
### Ignore Syntax
279+
### Ignore Scope
280280

281-
*Default: []*
281+
*Default: ["text.find-in-files", "source.build_output", "source.diff"]*
282282

283-
With this option you can ignore specific files/views based on the syntax used.
284-
An item has to match a case-sensitive substring of the syntax used in the view:
283+
With this option you can ignore lines being highlighted based on the scope of
284+
their trailing region.
285+
286+
If at least one scope in the configured list matches a scope in the trailing
287+
region of the line, it won't be highlighted.
288+
289+
By default, the scope under the mouse cursor is shown by pressing
290+
`Option+Command+P` (OS X) or `Ctrl+Alt+Shift+P` (Windows, Linux)
285291

286292
``` js
287-
// Views with a syntax that contains "Diff" are ignored
288-
{ "trailing_spaces_syntax_ignore": ["Diff"]}
293+
// Trailing spaces for find results, build output and markdown are ignored
294+
{ "trailing_spaces_scope_ignore": ["text.find-in-files", "source.build_output", "text.html.markdown"] }
289295
```
290296

291297
### For power-users only!

trailing_spaces.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,6 @@ def persist_settings():
6767
sublime.save_settings(ts_settings_filename)
6868

6969

70-
# Private: Determine if the view is a "Find results" view.
71-
#
72-
# view - the view, you know
73-
#
74-
# Returns True or False.
75-
def is_find_results(view):
76-
return view.settings().get('syntax') and "Find Results" in view.settings().get('syntax')
77-
78-
7970
# Private: Get the regions matching trailing spaces.
8071
#
8172
# As the core regexp matches lines, the regions are, well, "per lines".
@@ -93,17 +84,23 @@ def find_trailing_spaces(view):
9384
no_empty_lines_regexp = "(?<=\\S)%s$" % regexp
9485

9586
offending_lines = view.find_all(regexp if include_empty_lines else no_empty_lines_regexp)
87+
ignored_scopes = ",".join(ts_settings.get("trailing_spaces_scope_ignore", []))
88+
filtered_lines = []
89+
for region in offending_lines:
90+
if ignored_scopes and view.match_selector(region.begin(), ignored_scopes):
91+
continue
92+
filtered_lines.append(region)
9693

9794
sel = view.sel()
9895
line = len(sel) and view.line(sel[0].b)
9996

10097
if include_current_line or not line:
101-
return [offending_lines, offending_lines]
98+
return [filtered_lines, filtered_lines]
10299
else:
103100
current_offender = view.find(regexp if include_empty_lines else no_empty_lines_regexp, line.a)
104101
removal = False if current_offender is None else line.intersects(current_offender)
105-
highlightable = [i for i in offending_lines if i != current_offender] if removal else offending_lines
106-
return [offending_lines, highlightable]
102+
highlightable = [i for i in filtered_lines if i != current_offender] if removal else filtered_lines
103+
return [filtered_lines, highlightable]
107104

108105

109106
# Private: Find the freaking trailing spaces in the view and flags them as such!
@@ -128,10 +125,9 @@ def match_trailing_spaces(view):
128125
if max_size_exceeded(view):
129126
return
130127

131-
if not is_find_results(view):
132-
(matched, highlightable) = find_trailing_spaces(view)
133-
add_trailing_spaces_regions(view, matched)
134-
highlight_trailing_spaces_regions(view, highlightable)
128+
(matched, highlightable) = find_trailing_spaces(view)
129+
add_trailing_spaces_regions(view, matched)
130+
highlight_trailing_spaces_regions(view, highlightable)
135131

136132

137133
# Private: Checks if the view should be ignored.

trailing_spaces.sublime-settings

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
// Set to false to ignore trailing spaces on the edited line.
2525
"trailing_spaces_include_current_line" : true,
2626

27+
// By default, any lines in the Find Results Build output and Diff views are ignored
28+
// Add scopes to this list if you need to ignore them.
29+
"trailing_spaces_scope_ignore": ["text.find-in-files", "source.build_output", "source.diff"],
30+
2731
// By default, trailing spaces are deleted within the whole document.
2832
// Set to true to affect only the lines you edited since last save.
2933
// Trailing spaces will still be searched for and highlighted in the whole

0 commit comments

Comments
 (0)