views:

359

answers:

4

Does anyone know of a command (not a macro) for Textmate / E Text Editor / Redcar / etc. that will collapse a multi-line CSS rule down to one line OR, if the rule is already on one line, expand it out to multi-line? I already know about code folding and that's not what I require - I need to be able to toggle the rules between single and multi-line and have them be edited and saved like that.

For example, if I have this:

h1 {font-size:3em;line-height:1;margin-bottom:0.5em;}

I would like to be able to place my cursor anywhere within the rule, hit a keyboard shortcut and it would turn into this:

h1 {
  font-size:3em;
  line-height:1;
  margin-bottom:0.5em;
}

On hitting the shortcut again, it would convert back into single-line.

Does anything like this exist? Does anyone have any code that does something similar I could repurpose (ideally Ruby)? Does anyone know if this is even possible in Textmate?

Update: it seems that CSS rule collapsing and expanding is implemented as a pair of macros in Textmate. However, this isn't toggling and it also doesn't work in E Text Editor (which doesn't support macros). Not sure whether it works in Redcar. Is it possible to implement something similar as a command that can do toggling?

A: 

Try this online tool http://www.codebeautifier.com

antyrat
Thanks for your answer. Can you provide a little more info on how this addresses the question I posed? I'm can't see how this is related to Textmate.
Charles Roper
+1  A: 

Using the CSS bundle ctrl + opt + Q will collapse the currently selected rule into 1 line.

Mark Story
+1  A: 

Appending to Mark Story's answer, ctrl + Q does the opposite, turning a single line of CSS into nicely formatted CSS.

Chris Forrette
+2  A: 

I ended up creating my own command to do this. Grab it here.

There is a limitation in that for the command to work, the cursor has to be in whitespace within a rule declaration; i.e., not in a property/value pair scope. I've found placing the cursor just inside the opening brace to be a good place to trigger the command from.

If anyone knows how to select a parent scope that would be neat.

Charles Roper