There are several commands, represented by toolbar items
Any of these commands can be mapped to different keys using the Eclipse General->Keys dialog. Search for "MXML" in the keys dialog to find the format/indent commands.
The FlexFormatter allows you to cause a Format or Indent operation to occur when an editor is saved. Operation for ActionScript and MXML files can be controlled separately. Check the appropriate box and decide whether you want Format or Indent to occur. Operations of either kind can be performed manually as needed.
You can exclude files from auto (or batch) formatting by adding a regular expression to match the workspace-relative path in the table on the preference page. For example, to exclude items in package com.mycompany.adobePatches, you could add .*/com/mycompany/adobePatches/.* to the table. Note that you are filtering based on a path (not a package), and that I canonicalize the paths to use forward slashes for convenience, regardless of Operation System.
The rules are:
You can also use the formatter as a helper for formatting xml-style files. In the extensions table, add other extension (ex. 'xml') that should be formatted/indented using the mxml pretty printer. CData sections are not formatted.
This page allows you to adjust some updating options.
These options are common to both MXML and ActionScript formatting. Right now, the only such option is whether to use tabs or spaces. You should set this option to match what is in the standard FlexBuilder options at Window->Preferences->Flex->Editors->Indent Using
This is the number of spaces inside parentheses, brackets, and braces (for arrays). If you uncheck the box beside the twistie, you can set the subitems separately.
If checked, nesting characters that appear next to each other will not have spaces between them, regardless of the Spaces inside setting. Ex. [(( x + 2 ) + 3 )].
This is the number of spaces before/after commas as they appear in parameter lists, method arguments, array declarations, etc.
This is the number of spaces on either side of an '=' or boolean/arithmetic operator. This applies to symbolic operators only. Text operators (like 'as' and 'instanceof') will always have only 1 space on either side.
This is the number of spaces on either side of a ':' character in variable declarations. You can uncheck the checkbox beside the twistie to set the number of spaces before and after the colon separately.
This is the number of spaces after the colon of a label. Labels never have any space before the colon.
This is the number of spaces before the open parenthesis after a control keyword. For instance, between for and the control block.
This is the number of spaces between the name of the function and the function's parameter list.
If checked, don't delete any lines in the document that only contain whitespace. This does not mean that line breaks won't be removed, only that empty lines (2 or more line breaks in a row) will be preserved. Additional blank lines may be added. If not checked, then blank lines will be removed depending on the blank lines settings. Typically you would leave this item checked so that extra blank lines used to group variable declarations or other code won't be lost.
If unchecked, then an additional setting is available to preserve some blank lines. The idea is that 'extra' blank lines will be removed, but you won't lose your existing code groupings.
This is the number of blank lines to insert before these items. The idea is to keep a consistent amount of whitespace. Note that if you have "Don't delete blank lines" turned on, then the number of blank lines will never shrink, regardless of this setting.
If checked, then generate the indent whitespace on blank lines. If not checked, then blank lines will be empty. Checking this option can be useful if you want the whitespace to exist so that you can go back later and navigate to the end of line to start typing.
If checked, don't indent line comments that start in column one. Some people keep TODO comments there.
These options control formatting of the wrappable code elements. The goal here was to provide some reasonable wrapping, but also to allow you to skip formatting code elements that are complicated and that it's likely you have your own style for. Allowing you to selectively turn off formatting allows you to select larger parts of the document without worrying that your custom formatting will get destroyed.
This items are wrapped in a similar way and have the same set of options. Indentation is always affected, regardless of which option is chosen.
This applies to expressions in general (arithmetic, boolean, assignment etc.). The options are the same as above, but line breaks are only added at operators. So if you don't allow wrapping of method parameters, setting the wrap option here won't wrap on commas.
This option applies to XML tags embedded directly in ActionScript code. These tags are not formatted using the options for MXML, both because the semantics are different and because it looked difficult. Instead, I added options to try to not screw up formatting that you have already supplied. There is an extra option that will put each tag on a separate line with a reasonable indent.
The max line length is a hint at where you want wrapping to occur for the wrappable elements. Wrapping occurs after the boundary has been passed, so this is not appropriate for ensuring print output. For better wrapping behavior, check the Advanced Wrapping checkbox.
Add carriage returns before commas/operators, or afterward.
If checked, indent 2nd and subsequent lines to the first parameter/argument/array item. This does not affect general expression wrapping. Method calls with method calls as arguments are wrapped in nested fashion. If not checked, all wrapping is indented one indent beyond the start of the first line of the wrapped item.
This is the amount of indent to use for the second and subsequent lines of a wrapped statement. One tab stop is the size of a tab, whether it's actually realized as tabs or spaces. This is overridden by the Indent to first item setting if checked, for items where indent to first item is applicable.
This option turns on newer wrapping code that gives you better control of where lines are split when wrapping. The advanced wrapping checkbox is only enabled if at least one of the statement types is set to an option that wraps based on length.
This table contains the different types of items where a line can be broken. Check the items where you prefer breaks to occur. Other settings will also be used as applicable.
This is the number of columns to allow as a buffer to allow line breaks to occur without slavish adherence to a column. The grace columns are only be used if the preferred line breaks (the ones checked in the Advanced wrapping table) all fail to break the line at an earlier point. At that point, the formatter searches forward based on the grace columns to see if using those extra columns does allow a preferred line break to occur. Of course, you can set the column size to 0 to prevent grace columns from being used.
This option is the most important aspect of the advanced wrapping. If checked, possible line breaks are checked in (reverse) precedence order. The precedence order is determined in the usual way by operators, parentheses, etc. For each precedence level, possible line-break items are tested. If no line breaks are found, then the grace columns are applied to see if a line-break is allowed. So the idea is to allow the longest possible line at the lowest precedence level, so that pieces of the statement that are related are kept together.
If this option is not checked, then only one pass through the source line is made, rather than searching each precedence level. Then, the grace columns are checked. This setting is similar to the old wrapping algorithm, except for the grace columns and the ability to choose which operators can cause a break.
Check this option to attempt to enforce the max line length if other wrapping strategies fail. The first attempt is to see if a line break is available if items that are not checked in the table are used. If that still doesn't find a break, then the line is searched in increasing columns (first using preferred break locations, then using any) until a break location is found. If none are found, then the line is not broken. So this is an aggressive breaking strategy.
If this option is not checked, then columns to the right are still searched, but only using the preferred line break locations. If none are found, then the line is not broken. This is a less aggressive breaking strategy.
Check the box if you generally want braces done in Sun style or Adobe Style. Uncheck the box if you want some hybrid of the two styles or have particular exceptions for some of the subitems. Adobe style has open braces on a new line. Sun style has braces on the end of the first line of the statement.
If checked, else will be placed on a new line after the if statement. Typically, you set "Open brace on new line" and this option to the same checked state.
If checked, keep the 'if' in an 'else if' on the same line with the else. Otherwise, move the if to a new line.
This is the same idea as 'Else on new line'
This is a special option for do...while loops. It is different from the other brace options in that it does not control whether the brace is at the start of a line, but whether the brace is on the same line with the keyword. This option is standard in neither Sun nor Adobe styles.
If checked, open braces will be placed on the line below their control statement. If not, they will be left on the line of the control statement. You can uncheck the main checkbox to tweak this setting for particular types of statements and code blocks.
If checked, a line break will be added after a [Bindable] metatag that occurs right before the associated element. If not, then the meta tag will appear on the same line as the associated item, with a space between them. Other metatags before the [Bindable] tag will never be on the same line with the associated item. If there is another metatag or comment after the [Bindable] tag, then the [Bindable] tag will not be put on the same line with the associated item.
Put any empty statement (a single semi-colon) on a new line to help prevent errors with accidental semi-colons.
These are items that didn't seem to fit anywhere else and are hopefully unusual.
This is a special setting to control the number of spaces around the '=' in optional parameters in function declarations. Otherwise, the normal spaces around '=' setting is used.
For some reason, the Adobe sample code doesn't indent package contents (braces, classes, imports) at all. This option mimics that behavior.
Checking this option leaves any extra whitespace around '='. The idea is that if you have lined up your '=' across several variable declarations, then this option will prevent that from being disturbed.
Rearranging allows you to modify the order of modifiers and elements of an ActionScript block/file. It works in both Actionscript files and in script blocks within mxml. However, rearranging cannot be done on an mxml file using the toolbar button, and rearranging is always performed on the entire file. Rearranging without formatting can be a little weird because it is difficult to know what to do with leading whitespace. For instance, if the first function in the file has 2 blank lines before it to separate it from the properties, rearranging may move it to later in the file. The rearranger will take the leading whitespace and comments with it, because that seems like the only sensible thing to do. However, in some cases this can lead to odd results. A subsequent 'format' often cleans up these oddities depending on the settings for adding and retaining blank lines.
This provides the ability to control what order element modifiers appear in. You can specify separately for functions/properties/classes or use the same for all three. The order of elements is unaffected; this only affects the order of modifiers for each element.
This page provides the ability to change the order of elements in a source file. For instance, if you want all of the static properties at the top of a class, you can set that here.
Use the up and down buttons to reorder the elements.
If you need more control over member order (that is, of functions and properties), you can use the New member selector... button. This feature allows you to create some new special sort elements that filter members based on a number of different factors.
The tab folders below the member ordering table DO NOT apply to custom member sets.
These tabs correspond to the basic element types (i.e. the predefined ones) listed in the element type table. They do not apply to custom property/function sets that you have added to the table.
Creating a new member set can be a little confusing, so here are a couple of examples. Note: each example lists the 'print string' of the settings that appears at the bottom of the custom member set dialog.
This set grabs all public functions that are not static or final or native or getter/setting/Constructor and have names starting with "put"
This set grabs all non-public functions that have no namespace specifier.
This set grabs all functions that have the namespace 'mx_internal' or 'private_ns'
This set grabs all properties that are static and have names starting with CONSTANT_
A header is a comment header placed before elements of a certain type to identify a section of code that contains the same type of elements. A span is a header that applies to more than one consecutive element type. For example, a standard header identifying functions might look like this:
//////////////////////////// // Functions (only functions are in this header group) //////////////////////////// public function a():int {}
A span might look like the following:
//////////////////////////// // Members (this is a span that occurs before any functions or properties) //////////////////////////// public function a():int {} public function b():int {} public var a_prop:int; public var b_prop:int;
FlexFormatter allows you to define headers for any or all element types, using either the Major or Minor format defined on this page.
Rather than have each header's style configured manually, you configure the size, width, comment style, and repeat character for the major and minor header styles. Then, when you configure a header, you pick which type of header you want and supply the text.
This page is intended to help you generated copyright headers for Actionscript files. The styles can be set just like those for headers/spans. Paste in the appropriate copyright text and check out the preview. Notice that in the sample code the copyright header doesn't use your text unless you check the Remove Existing Copyright headers checkbox. This is intended to prevent accidental erasures.
If you chose the Header button, then the content you typed will appear in the table beside the element type. If you chose the Span button, then the items that are part of the span will appear indented in the element table.
Any element type can have a header. An element can only belong to one span. To be clear, an element type can have both a header defined and be part of a span.
A span/header combination might be used to group members. Here's an example:
///////////////////////////////////////// // // Members (major header) // ///////////////////////////////////////// /////////////////////// // Functions (minor header) /////////////////////// public function a():int{} ////////////////////// // Properties (minor header) ////////////////////// public var i:int;
Set the number of spaces that should be placed on either side of an attribute '='.
Number of spaces before the end marker of an empty tag.
If checked, indent wrapped attributes to line up with the first attribute in the tag. If not checked, wrapped lines are indented one tab.
This button brings up a dialog lets you specify the proper ordering (reordering) of mxml attributes during a Format.
Determine how you want the attributes to be wrapped.
Sometimes, you always want tags with 3 or fewer attributes to be kept on the same line, regardless of line length or number of attributes per line. Also, if you configure the 'id' attribute to be the first attribute and appear on the line after the tag name, then this setting overrides that and compresses the tag.
This is an override to the Keep on one line below a certain number of attributes option. So basically, if you think max line length is the most important wrapping criterion, then turn this option on so that putting a number of attributes on the same line doesn't make it unreasonably long. This option does not apply if you are wrapping based on n attributes per line.
If checked, blank lines between tags and inside tag data are preserved during a format. Carriage returns within a start or end tag are ignored. This option should rarely be unchecked.
Blank lines around tag settings can be used together. If a tag matches multiple settings, only the maximum number of blank lines will be used.
There are two tables here. Tags listed in neither of these tables will be formatted with the default strategy. The default strategy is to not modify the text content of a tag if it contains any non-whitespace characters. This is the normal case of no text content.
This button repopulates the two list boxes. This is a convenience since you may get the tables out of whack and want to restore their default contents, which might change as I add more event tags to the default list.
This dialog lets you reorder mxml attributes during a Format.
If this box is checked, don't change the order of attributes or use any custom line wrapping configuration.
In this table, add the attribute names that you want to see in a particular order. Many people would want to add 'id', perhaps others. Each row in the table is a group of attributes. It could be a single attribute, or it could be a comma-separated list of attributes with a newline at the end. The second case would mean that all the attributes in the set (that exist) should appear in the given order in any tag, and a newline should be inserted after the last existing attribute, so that following attributes will start on a new line. No newline will be added if none of the attributes exist. Creating a group with only linebreaks (no attributes) means that the linebreaks will always be added (unless there are no attributes in the tag). It makes most sense to include a linebreak in each attribute group (if you want one). A linebreak can also be included in its own group (as the first group in the list) to insert a newline before the first attribute in any tag. Extra line breaks beyond the last attribute in a tag will be trimmed.
Remove the currently selected row from the table
Use these buttons to reorder rows in the table.
Adds a line break to the current row in the edit field
Add a reference to a group (a list of attributes) to the current row in the edit field. The available groups are listed in the combo box beside the button. Use the Edit groups... button to add/edit/delete groups of attributes.
Add the current row definition to the table. This will be disabled if any element in the row already exists in the table. Update Modify the currently selected row definition in the table with the contents of the edit field. This button will be disabled if there is no row selected or if the contents of the edit field intersect the contents of another table row.
If this box is checked, all left-over attributes (that are not referenced in the table above) will be sorted in ascending alphabetical order.
If this box is checked, the end symbol for the tag (> or />) will be moved to the next line. Otherwise, it will appear immediately after the last attribute in the tag. This option is the only way to have a line break after the last attribute in a tag.
There are 5 predefined groups (properties, styles, effects, xml namespaces, and events). You can modify these groups to contain items I have missed, or create your own groups. An attribute may be listed in more than one group.
This table lists the currently defined groups.
This button allows you to define a new group. Groups must have unique names.
This button allows you to delete a group. A group that is used in your custom attribute order cannot be deleted.
This button allow you to rename a group. A group that is already being used in your custom attribute order cannot be renamed.
This button adds attributes to the end of existing groups based on the default group definitions in the FlexFormatter plugin. The idea is that if more attributes are added to the default groups, this is a way to update them. No attributes or groups are deleted. The normal restore defaults behavior on the main preference page does not affect the group definitions.
To edit a group, select it in the group table. This will cause the attributes table to be populated with the list of attributes in the group.
Any legal attribute name may be typed here. Also, you can use Java regular expressions to define attributes. See this link A simple example is xmlns:.* to match all attributes starting with "xmlns:".
A group by definition can contain multiple members. So it makes sense to be able to control sorting and wrapping within items matched by the group. Each group has its own setting.