7

So Eclipse can auto-format my css files under Source->Format, or by hitting Cntl-Shift-F.

When I group selectors for a single rule, eclipse formats it like this:

.planner th,.planner td {
    border: 1px solid black;
}

I would really like Eclipse to add a space between the selectors to aide readability, like this:

.planner th, .planner td {
    border: 1px solid black;
}

Is there any way I can configure Eclipse to do this? I'm running Eclipse Indigo.

Eliran Malka
  • 15,821
  • 6
  • 77
  • 100
Tom Tresansky
  • 19,364
  • 17
  • 93
  • 129
  • http://stackoverflow.com/questions/1392744/how-do-i-configure-autoformatting-in-eclipse I believe this should solve your problems... – will Jun 13 '12 at 23:26
  • @will, No, those options are specific to the Java formatter and don't affect CSS formatting. – Tom Tresansky Jun 14 '12 at 12:28
  • Does it not let you select the language you want to format though? – will Jun 14 '12 at 17:33

3 Answers3

1

The easiest way to solve your problem would be to run a find/replace command like so.

  1. Open up File/Replace ( Ctrl+F) on the CSS file.
  2. Find: ,\.
  3. Replace: , \.
  4. Check the regular expressions box.
  5. Click Replace All.

Alternatively If your want can't be configure through the CSS editor (which seems to be so), then you're going to have to make a plugin for it.

CSS Editor is located here:

Preferences > Web > CSS Files > Editor

If you're considering making a plugin, then check out the package org.eclipse.jdt.core.formatter for help.

More information here:

Larry Battle
  • 9,008
  • 4
  • 41
  • 55
  • 1
    It's admittedly a pretty easy problem to fix in various ways, but I want eclipse to do it for me. I hope writing a custom plugin isn't the only answer. – Tom Tresansky Jun 08 '12 at 17:41
1

The Aptana Studio plugin for eclipse has a formatter that's pre-configured according to your needs.

I recommend using it regardless as it ease up the development process a great deal for web developers (all sorts of nifty features like built-in Git integration, code assist for common JavaScript libraries, integrated FTP client, embedded AJAX server [Jaxer], nice themes included, etcetera, etcetera...).

References:

Eliran Malka
  • 15,821
  • 6
  • 77
  • 100
0

You could add a CSS class macro rule or even a macro, it works great in a text file but not so much the Java editor.

But your utlimate answer is add/change rules in ICSSStyleSheet, there is an explanation here: http://lab.benstucki.net/flashsac/doc/org/w3c/css/dom/ICSSStyleSheet.html#insertRule() <-- include those brackets.

rrrcode
  • 107
  • 3
  • 10