Sublime Forum

Problem with script that highlights trailing spaces

#1

At sublimetext.userecho.com/feedback/21171-search/ I found a tip how to highlight trailing spaces.

Problem is that I canā€™t figure out how to customize color (posted question there but not sure if commenter was notified and if I will ever get reply there).

Script source is here: bitbucket.org/theblacklion/subl ā€¦ _spaces.py

It does:

view.add_regions('HighlightTrailingSpacesListener', regions, color_name, sublime.DRAW_EMPTY_AS_OVERWRITE)
so Iā€™ve added custom scope to theme Iā€™m using (Twilight) like this:

<dict> <key>name</key> <string>Trailing whitespace</string> <key>scope</key> <string>trailingspace</string> <key>settings</key> <dict> <key>background</key> <string>#FF0E09</string> <key>foreground</key> <string>#F8F8F8</string> </dict> </dict>
and set DEFAULT_COLOR_NAME = ā€˜trailingspaceā€™ in script. Unfortunately, trailing spaces have white background with this change. When using default ā€œcommentā€ scope, they have no background color (or same as buffer background) so changing color seems to make some difference but not the one I expect.

0 Likes

#2

Sublime uses the foreground color to fill those regions. So set your foreground color to your reddish one. You also might have to close and reopen your file to see the changes.

P.S. Sorry - but it has been only 3 days since your post on userecho and I had the notification waiting in my inbox :wink:.

0 Likes

#3

That works! Thanks.

I also found another ā€œproblemā€. When highlight timeout is set to 500 for example, and Iā€™m typing a sentence fast, I would expect to not see trailing spaces being highlighted during typing when I donā€™t make such long breaks during typing. They are still highlighted briefly and I believe itā€™s because previous sublime.set_timeoutā€™s are triggering. Having sublime.clear_timeout would probably help here but it seems like itā€™s not implemented.

BTW. Sorry for being impatient, I wasnā€™t sure if there is notification system in place there. :smile:

0 Likes