在Textmate for Python中突出显示尾随空白吗? [英] Highlighting trailing whitespace in Textmate for Python?

查看:112
本文介绍了在Textmate for Python中突出显示尾随空白吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做类似 Textmate提示,以便在我用Python编写代码时始终以某种方式突出显示尾随空格-这样可以更轻松地立即对其进行更正,而其他编辑器(例如Emacs)也可以做到这一点.

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.

不幸的是,那篇文章之后的讨论似乎表明很难做到.对我而言,遵循此技巧后,invalid.trailing-whitespace范围选择器甚至在首选项中也不可见.其他人在这方面有成功吗?

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?

推荐答案

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

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:我已经将源"更改为"source.whitespace"

PS: I have changed "source" to "source.whitespace"

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

For comment change in Python grammar :

{  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语言定义中添加包含",其中:

You'll need to add an 'include' in Python language definition where:

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

转到:

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

这篇关于在Textmate for Python中突出显示尾随空白吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆