I would like to do something like this Textmate tip, so that trailing whitespace are always highlighted in some way when I code something in Python - it makes it easier to correct it immediately and other editors such as Emacs can do it.
Unfortunately the discussion after that post seems to suggest it's difficult to do. For me the invalid.trailing-whitespace
scope selector is not even visible in the preferences after following this tip. Has anyone else had any success with this?
Python String strip() function will remove leading and trailing whitespaces. If you want to remove only leading or trailing spaces, use lstrip() or rstrip() function instead.
Hover the mouse on warning in VS Code or any IDE and use quick fix to remove white spaces. Press f1 then type trim trailing whitespace .
Trailing whitespace. Description: Used when there is whitespace between the end of a line and the newline.
Some editors automatically remove trailing whitespace, some don't. This creates diff noise and can cause merge conflicts. You should coordinate with the people you're working with (colleagues, open-source crowd) what strategy everybody is using and make sure you all use the same strategy.
This code works (but not with comment) :
{ scopeName = 'source.whitespace';
patterns = (
{ name = 'source.invalid.trailing-whitespace';
match = '(\s+)$';
captures = { 1 = { name = 'invalid.trailing-whitespace'; }; };
},
);
}
PS: I have changed "source" to "source.whitespace"
For comment change in Python grammar :
{ name = 'comment.line.number-sign.python';
match = '(#).*$\n?';
captures = { 1 = { name = 'punctuation.definition.comment.python'; }; };
},
In:
{ name = 'comment.line.number-sign.python';
match = '(#).*?(\s*)$\n?';
captures = {
1 = { name = 'punctuation.definition.comment.python'; };
2 = { name = 'invalid.trailing-whitespace'; };
};
},
You'll need to add an 'include' in Python language definition where:
:
patterns = (
{ name = 'comment.line.number-sign.python';
:
Turns to:
:
patterns = (
{ include = 'source.whitespace'; },
{ name = 'comment.line.number-sign.python';
:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With