6

I set my preferred array initializer indentation on Preferences > PHP > Code Style > Fromatter > Line Wrapping, but while typing array initializers indentation is wrong:

$arr = array([ENTER]
····[CURSOR])

while I'm expecting:

$arr = array([ENTER]
··[CURSOR]
)

like it happens editing Javascript code. Note that the wrong indentation happens only while typing, whereas an explicit CTRL+SHIFT+F indents array initializer correctly. (So not a duplicate of many other questions asking how to set indentation, since here indentation is set but not applied while typing.)

How can I get the correct indentation while typing array initializers?

4 Answers 4

4

My settings on Zend Eclipse for PHP Developers, under PHP > Code Style > Formatter:

  • Indentation > Tab policy > Spaces
  • Indentation > Indentation size > 2
  • Indentation > Tab size > 2
  • Indentation > Default indentation for array initializers > 2
  • Line Wrapping > Expressions > Array initializers > Indentation policy > Indent by one
Sign up to request clarification or add additional context in comments.

2 Comments

one of these helped to make it work. Probably the indentation policy flag. I needed to restart Eclipse. It didn't work without.
Great, it same with Drupal coding standard
3

Try to set Indentation Policy to Indent by one (instead of Default Indentation) for Method Declarations -> parameters

4 Comments

It doesn't work. It seems that the PHP formatter rules don't affect the live-typing indentation (at least for array initializers).
@Heruan Try then with Formatter -> Tab policy = Spaces and Indentation Size = 1
That will set indentation by 1 space and that's not what I want. I guess Eclipse PDT has somehow hardcoded a double-indentation for array initializers that can't be overloaded by a formatter plugin.
@Heruan In my Eclipse Indigo I have this settings: Tab policy = Spaces, Identation size = 1, Default Indentation for Wrapped Lines = 2, Default Indentation for array Initializer = 2. And it works exactly as you are describing.
2

In Eclipse Juno, try with PHP -> Code Style -> Formatter -> Default indentation for array intializers = 1. It works for me.

Comments

2

In my Windows instance, it is necessary to restart Eclipse to apply changes to this setting:

PHP > Code Style > Formatter > Default indentation for array intializers

On other instances it's not required. No idea why.

Comments

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.