views:

42

answers:

2

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.

+1  A: 

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

(This works in Eclipse 3.5 at least).

SirDarius
That's a good but not perfect answer, because it marks spaces and newline characters. It would also be better if I could knock the grey to be a bit less visible.
rjmunro
A: 

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

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)

VonC
Checkstyle looks very good, but, AFAICS, it doesn't work on PHP code, only on Java. Am I missing an option to enable a rule for other language editors or something?
rjmunro
@rjmunro: I haven't seen the PHP aspect of your question;) I have added in my answer the relevant link for your case.
VonC