问题 在Textmate for Python中突出显示尾随空格?


我想做点什么 这个 Textmate提示,因此当我在Python中编写代码时,始终以某种方式突出显示尾随空格 - 这使得更容易立即纠正它,而其他编辑器(如Emacs)可以执行此操作。

不幸的是,那篇文章之后的讨论似乎表明它很难做到。对我来说 invalid.trailing-whitespace 遵循此提示后,范围选择器甚至在首选项中不可见。有没有人有这个成功?


7104
2018-03-13 08:02


起源



答案:


此代码有效(但没有注释):

{   scopeName = 'source.whitespace';
    patterns = (
        {  name = 'source.invalid.trailing-whitespace';
            match = '(\s+)$';
            captures = { 1 = { name = 'invalid.trailing-whitespace'; }; };
         },
    );
}

PS:我已将“source”更改为“source.whitespace”

对于Python语法中的注释更改:

{  name = 'comment.line.number-sign.python';
   match = '(#).*$\n?';
   captures = { 1 = { name = 'punctuation.definition.comment.python'; }; };
},

在:

{  name = 'comment.line.number-sign.python';
   match = '(#).*?(\s*)$\n?';
   captures = { 
     1 = { name = 'punctuation.definition.comment.python'; }; 
     2 = { name = 'invalid.trailing-whitespace';  }; 
   };
},

您需要在Python语言定义中添加“include”,其中:

:
patterns = (
 {    name = 'comment.line.number-sign.python';
:

转向:

:
patterns = (
 {  include = 'source.whitespace'; },
 {    name = 'comment.line.number-sign.python';
:

5
2018-03-14 01:45



谢谢!这很有效。 - pojo
您还可以使用: github.com/ppierre/python-pep8-tmbundle - ppierre


答案:


此代码有效(但没有注释):

{   scopeName = 'source.whitespace';
    patterns = (
        {  name = 'source.invalid.trailing-whitespace';
            match = '(\s+)$';
            captures = { 1 = { name = 'invalid.trailing-whitespace'; }; };
         },
    );
}

PS:我已将“source”更改为“source.whitespace”

对于Python语法中的注释更改:

{  name = 'comment.line.number-sign.python';
   match = '(#).*$\n?';
   captures = { 1 = { name = 'punctuation.definition.comment.python'; }; };
},

在:

{  name = 'comment.line.number-sign.python';
   match = '(#).*?(\s*)$\n?';
   captures = { 
     1 = { name = 'punctuation.definition.comment.python'; }; 
     2 = { name = 'invalid.trailing-whitespace';  }; 
   };
},

您需要在Python语言定义中添加“include”,其中:

:
patterns = (
 {    name = 'comment.line.number-sign.python';
:

转向:

:
patterns = (
 {  include = 'source.whitespace'; },
 {    name = 'comment.line.number-sign.python';
:

5
2018-03-14 01:45



谢谢!这很有效。 - pojo
您还可以使用: github.com/ppierre/python-pep8-tmbundle - ppierre


我不知道如何突出显示尾随空格,但你可以通过去除它来删除它

Bundles - > Text - > Converting / Stripping - >删除文档中的尾随空格

另外,因为textmate有emacs绑定,你可以像在emacs中那样做。


5



效果很好!我将该捆绑操作分配给^ S,并将保存操作从“Nothing”更改为“Current File”。所以现在如果我点击^ S,在将文件保存到磁盘之前会删除空格。 - pojo