Search code examples
apache-flexcurly-braces

Cuddle braces in flex


How can I force flex to cuddle my curly-braces instead of putting them on a new line?


Solution

  • I'm going to make the assumption that you are talking about Flex Builder. I'm specifically using Flex Builder 4 beta (Flash Builder), but I think this applies for Flex Builder 3.

    When asking fb to create a new actionscript class, you can adjust the template and set it to cuddle the braces, but only for the class definition. The template settings can be found under Window -> Preferences -> Flash Builder -> File Templates.

    A better option is the Flex Formatter plug-in, which can be found at Source-Forge here. Note the installation instructions here which are different depending on which version of Eclipse you are running.

    Once you get the plugin installed, you'll see a number of new setting available under Window -> Preferences -> Flex Formatting. The one you are looking for is buried a bit. Look under Flex Formatting -> ActionScript -> Newlines/Wrapping -> Line Breaks -> Brace Style.

    Set as desired.

    Once that is all done, just go to your selected actionscript file, and press the Ctrl+Shift+F keyboard shortcut. And there you have it.

    Easy Peasy, Lemon Squeezy.