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.

3
  • stackoverflow.com/questions/1392744/… I believe this should solve your problems... Commented Jun 13, 2012 at 23:26
  • @will, No, those options are specific to the Java formatter and don't affect CSS formatting. Commented Jun 14, 2012 at 12:28
  • Does it not let you select the language you want to format though? Commented Jun 14, 2012 at 17:33

3 Answers 3

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:

Sign up to request clarification or add additional context in comments.

2 Comments

This looks promising. I'll download the plugin and try it out.
Does the trick by default, and offers a lot of other coolness for working with css in eclipse!
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:

1 Comment

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.
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.

1 Comment

I'm not sure what this is, could you please clarify?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.