Highlighting trailing whitespace in Textmate for Python?

前端 未结 2 1375
礼貌的吻别
礼貌的吻别 2021-02-14 06:47

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 corre

相关标签:
2条回答
  • 2021-02-14 06:54

    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';
    :
    
    0 讨论(0)
  • 2021-02-14 07:11

    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.

    0 讨论(0)
提交回复
热议问题