在 Eclipse 的文本编辑器中,制表符是否可能看起来与空格不同

发布于 2024-09-11 09:57:39 字数 362 浏览 4 评论 0原文

是否可以将选项卡设置为具有不同的背景颜色(例如略为灰色)或在 Eclipse 文本编辑器中放置一个小符号(如“↦”)?如果它是特定于语言的,我使用 PHP。

我们公司的编码标准是用于缩进的制表符,但源代码中经常有空格,因此很高兴看到这些空格在哪里,以便我在处理那段代码时可以更正它们。我不想运行脚本来全局修复它们,因为这会破坏我们版本控制中的合并,并且如果开发人员复制并粘贴了一些示例代码或其他内容,它们可能会在开发人员意识到的情况下回来。

如果它能够突出显示行首的空格或带有红色背景或其他内容的制表符后的空格,那就太好了。我可以通过对“^|\t +”进行正则表达式搜索来模拟这一点,但这也会突出显示选项卡本身,而且我希望它能够永久突出显示,即使当我使用搜索其他内容时也是如此。

Is it possible to set tabs to have a different background color (e.g. slightly grey) or put a little symbol (like "↦") in Eclipse text editors? If it's language specific, I'm using PHP.

Our company coding standard is Tabs for indenting, but often there are spaces in the source code, so it would be great to see where these spaces are so that I can correct them when working on that bit of the code. I don't want to run a script to just fix them globally because that would break merging in our version control, and they may come back without the developer realising if they copy and paste some sample code or something.

What would be really nice is if it could highlight spaces at the beginning of lines or spaces after tabs with a red background or something. I can sort-of simulate this by doing a regex search for "^|\t +", but that also highlights the tab itself, and I'd like this to be permanently highlighted, even when I am using the search for other things.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光倒影 2024-09-18 09:57:39

在首选项对话框中:常规 ->编辑->文本编辑器:显示空白字符。

(这至少适用于 Eclipse 3.5)。

In the preferences dialog: General -> Editors -> Text Editors : Show whitespace characters.

(This works in Eclipse 3.5 at least).

櫻之舞 2024-09-18 09:57:39

为此,您需要一个外部插件。

以下使用 Checkstyle(适用于 Java)进行说明。
但是您可以使用 phpcheckstyle (相同想法,但您需要修补该开放源以添加正则表达式检测,请参阅论坛获取补丁示例)

^[\t]*? [\t ]*?\S.*?$

alt text http://img825.imageshack.us /img825/390/eclipsecsspace.png

使用以下模块:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "configuration_1_3.dtd">

<!--
    This configuration file was written by the eclipse-cs plugin configuration editor
-->
<!--
    Checkstyle-Configuration: t
    Description: none
-->
<module name="Checker">
  <property name="severity" value="warning"/>
  <module name="TreeWalker">
    <module name="Regexp">
      <property name="format" value="^[\t]*? [\t ]*?\S.*?$"/>
      <property name="message" value="spaces are used instead of tab for indent"/>
      <property name="illegalPattern" value="true"/>
    </module>
  </module>
</module>

注意 configuration_1_3.dtd:如果您无法访问最初编写在模块 xml 文件中的 dtd( http://www.puppycrawl.com/dtds/configuration_1_2.dtd:参见< a href="http://checkstyle.sourceforge.net/config.html#XML%20Details" rel="nofollow noreferrer">模块 XML 配置)

You need an external plugin for that.

The following uses Checkstyle (for Java) for illustration.
But you can use phpcheckstyle (same idea, but you need to patch that oppen source to add the regex detection. See the forum for patch examples)

^[\t]*? [\t ]*?\S.*?$

alt text http://img825.imageshack.us/img825/390/eclipsecsspace.png

Use the following module:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "configuration_1_3.dtd">

<!--
    This configuration file was written by the eclipse-cs plugin configuration editor
-->
<!--
    Checkstyle-Configuration: t
    Description: none
-->
<module name="Checker">
  <property name="severity" value="warning"/>
  <module name="TreeWalker">
    <module name="Regexp">
      <property name="format" value="^[\t]*? [\t ]*?\S.*?$"/>
      <property name="message" value="spaces are used instead of tab for indent"/>
      <property name="illegalPattern" value="true"/>
    </module>
  </module>
</module>

Note the configuration_1_3.dtd: you need one dtd if you can't access the one originally written in the module xml file (http://www.puppycrawl.com/dtds/configuration_1_2.dtd: see Module XML configuration)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文