Formatter Preferences

Zend Studio can auto-format scripts to organize them into an easily readable format. The Formatter Preferences page allows you to customize the way it is formatted.

The Formatter Preferences Preferences page is accessed from Window | Preferences | PHP | Code Style | Formatter.

Creating Your Own Set of Configuration Settings

The default formatting settings are based on the PHP Conventions settings.

Click Show to see these settings.

 

 

Instructions on how to complete a procedure

To create your own set of configuration settings:

  1. Click New.

  2. Enter a name for you profile.

  3. Select which profile to base your new profile on. (This will duplicate these settings and allow you to edit them).

  4. Ensure that the 'Open the edit dialog now' checkbox is marked and click OK.

  5. The Edit dialog will open with the following tabbed option screens:

  • Indentation

  • Braces

  • White Space

  • Blank Lines

  • New Lines

  • Control Statements

  • Line Wrapping

These are described in more detail below.

  1. Once you have set the required options, click OK.

 The new configuration will be added to the list.

 

The Options Available in the Formatter Tabs

These options are available by clicking Show in the Formatter Preferences page.

Indentation

The Indentation tab allows you to configure the indentation size and select which elements should be indented.

The Indentation tab contains the following options:

General Settings

  • Tab Policy - Select Tab or Spaces from the drop-down list to set the indentation size for a tab.

  • Indentation size - If you select spaces, enter the number of spaces to be created.

  • Tab size - Define the number of character spaces a tab contains.
  • Default indentation for array initializers - Enter the default indentation for array initializers (in characters).

Indent

Select the elements to be indented by marking the relevant checkbox from the following options:

  • Declarations within class body

  • Statements within method/function body

  • Statements within blocks

  • Statements within 'switch' body

  • Statements within 'case' body

  • 'break statements

  • Empty lines

Braces

The Braces tab allows you to configure brace positions.

Choose the brace positions (Same line, Next line or Next line indented) for the following:

  • Class or interface declaration

  • Method declaration

  • Blocks

  • 'switch' statement

White Space

The White Space tab allows you to configure where spaces should be entered for declarations, control statements, expressions and arrays.

Expand each category by clicking on the + sign to configure which items are applied

to each instruction.

 

Standing on an item will display a list of possible syntax conditions in which white

spaces will be inserted. Select the required conditions by marking the relevant checkboxes.

 

Choosing 'sort options by Syntax element' from the drop down list will sort the list

of by syntax conditions rather than by element.

 

Blank Lines

The Blank Lines tab allows you to set the number of blank lines to be created in various conditions.

Enter the number of blank lines (between 0-32) to be created in the following conditions:

Blank Lines

  • Before class declarations

  • Before constant declarations

  • Before field declarations

  • Before function/method declarations

  • At beginning of function / method / body

Existing Blank Lines

  • Number of empty lines to preserve

New Lines

The New Lines tab allows you to select when new lines will be created.

The Options in the New Lines tab

Insert New Line

Select whether to insert a new line in the following conditions:

  • In empty class body

  • In empty method body

  • In empty block

  • Insert new line after method invocation, when chaining at least - When chaining at least the number of methods you specify here, a new line will be inserted after the method invocation.

Array Initializers

Select whether to:

  • Insert new line after opening parenthesis of array initializer

  • Insert new line before closing parenthesis of array initializer

Empty statements

Select whether to put empty statements on a new line.

Control Statements

The Control Statements tab allows you to configure the line formatting for Control Statements.

The Control Statements tab contains the following options:

General

  • Insert new line before 'else' and 'elseif' in an 'if' statement

  • Insert new line before 'catch' in a 'try' statement

  • Insert new line before 'while' in a 'do' statement

'if else'

  • Keep 'then' statement on same line

  • Keep simple 'if' on one line

  • Keep 'else' statement on same line

  • Keep 'else if' on one line

  • Keep 'return' or 'throw' clause on one line

Line Wrapping

The Line Wrapping tab allows you to configure Line Wrapping properties.

The Line Wrapping tab contains the following options:

Line Width and Indentation Levels

  • Maximum Line Width - Enter the maximum line width (in characters).

  • Default indentation for wrapped lines - Enter the default indentation for wrapped lines (in characters).

Line Wrapping and Indentation Policies

To set line wrapping and indentation wrapping policies for a specific element, select an element from the collapsible list and select an option from the 'Line wrapping policy' and 'Indentation policy' drop-down lists.

The elements for which the line and indentation policies can be applied are :

  • Class Declarations

    • 'implements' clause'

  • Method Declarations

    • Parameters

  • Function Calls

    • Arguments

    • Object allocation arguments

  • Expressions

    • Binary expressions

    • Array Initializers

Comments

The Comments tab allows you to configure line comment formatting.

Off/On Tags

The Off/On Tags tab allows you to enable the Off/On tags. Off/On tags can be used in any comments to turn the formatter off and on in a source file.

Importing an Existing Formatting Configuration

 

 

Instructions on how to complete a procedure

To import an existing formatting configuration:

  1. Click Import.

  2. Select an XML file with the required configuration settings.

  3. Click OK.

The new configuration will be added to the list.

Exporting a Configuration File to an XML File

 

 

Instructions on how to complete a procedure

To export a configuration file to an XML file:

  1. Select the required configuration from the drop-down list.

  2. Enter a name and location for the file.

  3. Click OK.

  4. An XML file will be created with the required settings.

 

Formatter Preferences page

Applying Formatter Preferences Settings to a Specific Project

 

 

Instructions on how to complete a procedure

To apply Formatter Preferences settings to a specific project only:

  1. Select the link labelled "Configure Project Specific Settings".

  2. Select the required project from the list.
    A Formatter Preferences Properties dialog will appear.

  3. Select the required settings and click Apply.
    A prompt dialog will appear stating that a rebuild of the project must occur for the settings to take effect.

  4. Click Yes to rebuild the project.
    -Or- Click No for a rebuild to be performed only when Zend Studio is restarted.
    -Or- Click Cancel to cancel the operation.