Highlighting trailing whitespace in Textmate for Python?

元气小坏坏 提交于 2019-12-03 11:24:49
ppierre

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';
:

I don't know how to highlight the trailing space but you can remove it by going to

Bundles -> Text -> Converting/Stripping -> Remove trailing spaces in document

Also, because textmate has emacs bindings, you may be able to do it the same way you would do it in emacs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!