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?

Giovanni Lovato
  • 2,183
  • 2
  • 29
  • 53

4 Answers4

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
Randell
  • 6,112
  • 6
  • 45
  • 70
3

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

Pigueiras
  • 18,778
  • 10
  • 64
  • 87
  • It doesn't work. It seems that the PHP formatter rules don't affect the live-typing indentation (at least for array initializers). – Giovanni Lovato Oct 28 '12 at 12:19
  • @Heruan Try then with Formatter -> Tab policy = Spaces and Indentation Size = 1 – Pigueiras Oct 28 '12 at 12:30
  • 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. – Giovanni Lovato Oct 28 '12 at 12:37
  • 1
    @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. – Pigueiras Oct 28 '12 at 12:49
2

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

Guillermo Luque
  • 1,376
  • 1
  • 10
  • 9
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.

reformed
  • 4,505
  • 11
  • 62
  • 88